From cb277951fcee140de680c966d34cbe1e4b83b7b2 Mon Sep 17 00:00:00 2001 From: brido4125 Date: Wed, 10 Jan 2024 16:20:46 +0900 Subject: [PATCH] INTERNAL: Refactor logic and add comments in addKeyToChunk. --- .../net/spy/memcached/MemcachedClient.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/spy/memcached/MemcachedClient.java b/src/main/java/net/spy/memcached/MemcachedClient.java index 638c3d4a4..14e78f527 100644 --- a/src/main/java/net/spy/memcached/MemcachedClient.java +++ b/src/main/java/net/spy/memcached/MemcachedClient.java @@ -1097,7 +1097,7 @@ public BulkFuture> asyncGetBulk(Collection keys, Transcoder tc = tc_iter.next(); tc_map.put(key, tc); validateKey(key); - addKeyToChunk(chunks, key, conn.findNodeByKey(key)); + addKeyToChunk(chunks, key); } int wholeChunkSize = getWholeChunkSize(chunks); final CountDownLatch latch = new CountDownLatch(wholeChunkSize); @@ -1232,7 +1232,7 @@ public BulkFuture>> asyncGetsBulk(Collection tc_map.put(key, tc); validateKey(key); - addKeyToChunk(chunks, key, conn.findNodeByKey(key)); + addKeyToChunk(chunks, key); } int wholeChunkSize = getWholeChunkSize(chunks); @@ -1281,24 +1281,24 @@ public void complete() { } /** - * add key to chunks - * @param chunks collection list that sorted by node + * Split the keys into 200 sizes by node. + * The max size of each chunk is 200. + * @param chunkMap key list that sorted by node * @param key the key to request - * @param node primary node to request - */ - private void addKeyToChunk(Map>> chunks, - String key, MemcachedNode node) { - List> lks = chunks.get(node); - if (lks == null) { - lks = new ArrayList>(); - Collection ts = new ArrayList(); - lks.add(ts); - chunks.put(node, lks); + */ + private void addKeyToChunk(Map>> chunkMap, String key) { + MemcachedNode node = conn.findNodeByKey(key); + List> keyListByNode = chunkMap.get(node); + + if (keyListByNode == null) { + keyListByNode = new ArrayList>(); + keyListByNode.add(new ArrayList()); + chunkMap.put(node, keyListByNode); } - if (lks.get(lks.size() - 1).size() >= GET_BULK_CHUNK_SIZE) { - lks.add(new ArrayList()); + if (keyListByNode.get(keyListByNode.size() - 1).size() >= GET_BULK_CHUNK_SIZE) { + keyListByNode.add(new ArrayList()); } - lks.get(lks.size() - 1).add(key); + keyListByNode.get(keyListByNode.size() - 1).add(key); } /**