@@ -205,36 +205,34 @@ public Iterator<MemcachedNode> getSequence(String k, ReplicaPick pick) {
205205 }
206206
207207 public NodeLocator getReadonlyCopy () {
208- TreeMap <Long , SortedSet <MemcachedReplicaGroup >> smg =
209- new TreeMap <>(ketamaGroups );
210- HashMap <String , MemcachedReplicaGroup > ag =
211- new HashMap <>(allGroups .size ());
212- Collection <MemcachedNode > an = new ArrayList <>(allNodes .size ());
213-
214208 lock .lock ();
215209 try {
210+ TreeMap <Long , SortedSet <MemcachedReplicaGroup >> ketamaCopy = new TreeMap <>();
211+ HashMap <String , MemcachedReplicaGroup > groupsCopy = new HashMap <>(allGroups .size ());
212+ Collection <MemcachedNode > nodesCopy = new ArrayList <>(allNodes .size ());
213+
216214 // Rewrite the values a copy of the map
217- for (Map .Entry <Long , SortedSet <MemcachedReplicaGroup >> mge : smg .entrySet ()) {
215+ for (Map .Entry <Long , SortedSet <MemcachedReplicaGroup >> hashPoint : ketamaGroups .entrySet ()) {
218216 SortedSet <MemcachedReplicaGroup > groupROSet = new TreeSet <>(
219217 new ArcusReplKetamaNodeLocatorConfiguration .MemcachedReplicaGroupComparator ());
220- for (MemcachedReplicaGroup mrg : mge .getValue ()) {
221- groupROSet .add (new MemcachedReplicaGroupROImpl (mrg ));
218+ for (MemcachedReplicaGroup group : hashPoint .getValue ()) {
219+ groupROSet .add (new MemcachedReplicaGroupROImpl (group ));
222220 }
223- mge . setValue ( groupROSet );
221+ ketamaCopy . put ( hashPoint . getKey (), groupROSet );
224222 }
225223 // copy the allGroups collection.
226- for (Map .Entry <String , MemcachedReplicaGroup > me : allGroups .entrySet ()) {
227- ag .put (me .getKey (), new MemcachedReplicaGroupROImpl (me .getValue ()));
224+ for (Map .Entry <String , MemcachedReplicaGroup > group : allGroups .entrySet ()) {
225+ groupsCopy .put (group .getKey (), new MemcachedReplicaGroupROImpl (group .getValue ()));
228226 }
229227 // copy the allNodes collection.
230- for (MemcachedNode n : allNodes ) {
231- an .add (new MemcachedNodeROImpl (n ));
228+ for (MemcachedNode node : allNodes ) {
229+ nodesCopy .add (new MemcachedNodeROImpl (node ));
232230 }
231+
232+ return new ArcusReplKetamaNodeLocator (ketamaCopy , groupsCopy , nodesCopy );
233233 } finally {
234234 lock .unlock ();
235235 }
236-
237- return new ArcusReplKetamaNodeLocator (smg , ag , an );
238236 }
239237
240238 public void update (Collection <MemcachedNode > toAttach , Collection <MemcachedNode > toDelete ) {
0 commit comments