Skip to content

Commit 04285ea

Browse files
daschlMichael Nitschinger
authored andcommitted
SPY-163: Count down bulk get latch even when empty key list is provided.
Motivation ---------- When a empty iterator (or empty key list) is passed in to a get bulk operation, a result is never returned and the thread is blocked because it waits on a latch that will never be counted down (because no response will ever arrive). Modifications ------------- If no chunks with keys are sent out to the servers, the latch is initialized to 0 right away so that the code doesn't need to wait at all. Result ------ The code now returns properly with an empty map instead of blocking the thread forever. Change-Id: I0711c399d9f15010bc808e0f651ce6ad605c06f0 Reviewed-on: http://review.couchbase.org/36208 Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com> Reviewed-by: Matt Ingenthron <matt@couchbase.com>
1 parent f2c370f commit 04285ea

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/main/java/net/spy/memcached/MemcachedClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,8 @@ public <T> BulkFuture<Map<String, T>> asyncGetBulk(Iterator<String> keyIter,
13171317
}
13181318

13191319
final AtomicInteger pendingChunks = new AtomicInteger(chunks.size());
1320-
final CountDownLatch latch = new CountDownLatch(1);
1320+
int initialLatchCount = chunks.isEmpty() ? 0 : 1;
1321+
final CountDownLatch latch = new CountDownLatch(initialLatchCount);
13211322
final Collection<Operation> ops = new ArrayList<Operation>(chunks.size());
13221323
final BulkGetFuture<T> rv = new BulkGetFuture<T>(m, ops, latch, executorService);
13231324

src/test/java/net/spy/memcached/ProtocolBaseCase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,11 @@ public void onComplete(BulkGetFuture<?> f) throws Exception {
10061006
assertTrue(latch.await(2, TimeUnit.SECONDS));
10071007
}
10081008

1009+
public void testEmptyGetBulk() throws Exception {
1010+
Map<String, Object> bulk = client.getBulk(Collections.<String>emptyList());
1011+
assertTrue(bulk.isEmpty());
1012+
}
1013+
10091014
private static class TestTranscoder implements Transcoder<String> {
10101015
private static final int FLAGS = 238885206;
10111016

0 commit comments

Comments
 (0)