Skip to content

Commit

Permalink
INTERNAL: Refactor logic and add comments in addKeyToChunk.
Browse files Browse the repository at this point in the history
  • Loading branch information
brido4125 committed Jan 10, 2024
1 parent eb5c939 commit cb27795
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/main/java/net/spy/memcached/MemcachedClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ public <T> BulkFuture<Map<String, T>> asyncGetBulk(Collection<String> keys,
Transcoder<T> 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);
Expand Down Expand Up @@ -1232,7 +1232,7 @@ public <T> BulkFuture<Map<String, CASValue<T>>> asyncGetsBulk(Collection<String>

tc_map.put(key, tc);
validateKey(key);
addKeyToChunk(chunks, key, conn.findNodeByKey(key));
addKeyToChunk(chunks, key);
}

int wholeChunkSize = getWholeChunkSize(chunks);
Expand Down Expand Up @@ -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<MemcachedNode, List<Collection<String>>> chunks,
String key, MemcachedNode node) {
List<Collection<String>> lks = chunks.get(node);
if (lks == null) {
lks = new ArrayList<Collection<String>>();
Collection<String> ts = new ArrayList<String>();
lks.add(ts);
chunks.put(node, lks);
*/
private void addKeyToChunk(Map<MemcachedNode, List<Collection<String>>> chunkMap, String key) {
MemcachedNode node = conn.findNodeByKey(key);
List<Collection<String>> keyListByNode = chunkMap.get(node);

if (keyListByNode == null) {
keyListByNode = new ArrayList<Collection<String>>();
keyListByNode.add(new ArrayList<String>());
chunkMap.put(node, keyListByNode);
}
if (lks.get(lks.size() - 1).size() >= GET_BULK_CHUNK_SIZE) {
lks.add(new ArrayList<String>());
if (keyListByNode.get(keyListByNode.size() - 1).size() >= GET_BULK_CHUNK_SIZE) {
keyListByNode.add(new ArrayList<String>());
}
lks.get(lks.size() - 1).add(key);
keyListByNode.get(keyListByNode.size() - 1).add(key);
}

/**
Expand Down

0 comments on commit cb27795

Please sign in to comment.