Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 17 additions & 31 deletions src/main/java/net/spy/memcached/v2/AsyncArcusCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ public class AsyncArcusCommands<T> implements AsyncArcusCommandsIF<T> {

@SuppressWarnings("unchecked")
public AsyncArcusCommands(Supplier<ArcusClient> arcusClientSupplier) {
this.tc = (Transcoder<T>) arcusClientSupplier.get().getTranscoder();
this.tcForCollection = (Transcoder<T>) arcusClientSupplier.get().getCollectionTranscoder();
this.keyValidator = arcusClientSupplier.get().getKeyValidator();
ArcusClient client = arcusClientSupplier.get();
this.tc = (Transcoder<T>) client.getTranscoder();
this.tcForCollection = (Transcoder<T>) client.getCollectionTranscoder();
this.keyValidator = client.getKeyValidator();
this.arcusClientSupplier = arcusClientSupplier;
}

Expand Down Expand Up @@ -401,7 +402,8 @@ public ArcusFuture<Map<String, T>> multiGet(List<String> keys) {
for (Map.Entry<MemcachedNode, List<String>> entry : arrangedKeys) {
MemcachedNode node = entry.getKey();
List<String> keyList = entry.getValue();
CompletableFuture<Map<String, T>> future = get(client, node, keyList).toCompletableFuture();
CompletableFuture<Map<String, T>> future = getPerNode(client, node, keyList)
.toCompletableFuture();
futureToKeys.put(future, keyList);
futures.add(future);
}
Expand All @@ -423,14 +425,8 @@ public ArcusFuture<Map<String, T>> multiGet(List<String> keys) {
});
}

/**
* Use only in multiGet method.
*
* @param keyList key list to get from single node
* @return ArcusFuture with results
*/
private ArcusFuture<Map<String, T>> get(ArcusClient client, MemcachedNode node,
List<String> keyList) {
private ArcusFuture<Map<String, T>> getPerNode(ArcusClient client, MemcachedNode node,
List<String> keyList) {
AbstractArcusResult<Map<String, CachedData>> result
= new AbstractArcusResult<>((new AtomicReference<>(new HashMap<>())));
@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -482,7 +478,6 @@ public void complete() {
return future;
}


public ArcusFuture<Long> incr(String key, int delta) {
return mutate(Mutator.incr, key, delta, -1L, 0);
}
Expand Down Expand Up @@ -562,7 +557,7 @@ public ArcusFuture<Map<String, CASValue<T>>> multiGets(List<String> keys) {
MemcachedNode node = entry.getKey();
List<String> keyList = entry.getValue();
CompletableFuture<Map<String, CASValue<T>>> future
= gets(client, node, keyList).toCompletableFuture();
= getsPerNode(client, node, keyList).toCompletableFuture();
futureToKeys.put(future, keyList);
futures.add(future);
}
Expand All @@ -583,14 +578,8 @@ public ArcusFuture<Map<String, CASValue<T>>> multiGets(List<String> keys) {
});
}

/**
* Use only in multiGets method.
*
* @param keyList key list to get from single node
* @return ArcusFuture with results.
*/
private ArcusFuture<Map<String, CASValue<T>>> gets(ArcusClient client, MemcachedNode node,
List<String> keyList) {
private ArcusFuture<Map<String, CASValue<T>>> getsPerNode(ArcusClient client, MemcachedNode node,
List<String> keyList) {
AbstractArcusResult<Map<String, GetsResultImpl<T>>> result
= new AbstractArcusResult<>(new AtomicReference<>(new HashMap<>()));

Expand Down Expand Up @@ -640,7 +629,6 @@ public void complete() {
return future;
}


public ArcusFuture<Boolean> delete(String key) {
AbstractArcusResult<Boolean> result = new AbstractArcusResult<>(new AtomicReference<>());
ArcusFutureImpl<Boolean> future = new ArcusFutureImpl<>(result);
Expand Down Expand Up @@ -1030,7 +1018,7 @@ private static BTreeGet createBTreeGet(BKey bKey, BopGetArgs args) {
}

public ArcusFuture<BTreeElements<T>> bopGet(String key, BKey from, BKey to, BopGetArgs args) {
verifyBKeyRange(from, to);
verifyBKeyTypesMatch(from, to);

AbstractArcusResult<BTreeElements<T>> result =
new AbstractArcusResult<>(new AtomicReference<>(new BTreeElements<>(new ArrayList<>())));
Expand Down Expand Up @@ -1098,7 +1086,7 @@ public ArcusFuture<Map<String, BTreeElements<T>>> bopMultiGet(List<String> keys,
BopGetArgs args) {
keyValidator.validateKey(keys);
keyValidator.checkDupKey(keys);
verifyBKeyRange(from, to);
verifyBKeyTypesMatch(from, to);
verifyPositiveCountArg(args, ArcusClient.MAX_GETBULK_ELEMENT_COUNT);

ArcusClient client = arcusClientSupplier.get();
Expand Down Expand Up @@ -1226,7 +1214,7 @@ public void gotElement(String key, int flags, Object bKey, byte[] eFlag, byte[]
return future;
}

private static void verifyBKeyRange(BKey from, BKey to) {
private static void verifyBKeyTypesMatch(BKey from, BKey to) {
if (from.getType() != to.getType()) {
throw new IllegalArgumentException("Two BKey types(from, to) must be the same.");
}
Expand Down Expand Up @@ -1445,7 +1433,7 @@ public ArcusFuture<SMGetElements<T>> bopSortMergeGet(List<String> keys, BKey fro
boolean unique, BopGetArgs args) {
keyValidator.validateKey(keys);
keyValidator.checkDupKey(keys);
verifyBKeyRange(from, to);
verifyBKeyTypesMatch(from, to);
verifyPositiveCountArg(args, ArcusClient.MAX_SMGET_COUNT);

ArcusClient client = arcusClientSupplier.get();
Expand Down Expand Up @@ -1633,7 +1621,7 @@ public ArcusFuture<Boolean> bopDelete(String key, BKey bKey, BopDeleteArgs args)
}

public ArcusFuture<Boolean> bopDelete(String key, BKey from, BKey to, BopDeleteArgs args) {
verifyBKeyRange(from, to);
verifyBKeyTypesMatch(from, to);
BTreeDelete delete = new BTreeDelete(from.toString(), to.toString(),
args.getCount(), args.getEFlagFilter(), args.isDropIfEmpty(), false);
return collectionDelete(key, delete);
Expand Down Expand Up @@ -1681,7 +1669,7 @@ public void complete() {
}

public ArcusFuture<Long> bopCount(String key, BKey from, BKey to, ElementFlagFilter eFlagFilter) {
verifyBKeyRange(from, to);
verifyBKeyTypesMatch(from, to);

AbstractArcusResult<Long> result = new AbstractArcusResult<>(new AtomicReference<>());
ArcusFutureImpl<Long> future = new ArcusFutureImpl<>(result);
Expand Down Expand Up @@ -2152,7 +2140,6 @@ public ArcusFuture<Boolean> flush(int delay) {
public void receivedStatus(OperationStatus status) {
switch (status.getStatusCode()) {
case SUCCESS:
result.set(true);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด๊ฑฐ ๋น ์กŒ๋Š” ๋ฐ, ๊ดœ์ฐฎ์€๊ฐ€์š”?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flush()๋Š” ์‘๋‹ต์ด ์™”๋‹ค๋Š” ๊ฒƒ ์ž์ฒด๊ฐ€ ์„ฑ๊ณต์„ ์˜๋ฏธํ•˜๋ฏ€๋กœ ํ•ญ์ƒ true๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ธฐ๋กœ ํ•ฉ์˜ํ•˜์˜€๊ณ , ์ด์— ๋”ฐ๋ผ combiner๋ฅผ () -> true๋กœ ์„ค์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ๊ฐœ๋ณ„ ๋…ธ๋“œ์˜ result์— ๊ฐ’์„ ์„ธํŒ…ํ•˜๋”๋ผ๋„ ์ตœ์ข… ๊ฒฐ๊ณผ์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
์˜คํžˆ๋ ค result.set(true)๊ฐ€ ๋‚จ์•„์žˆ์œผ๋ฉด ํ•ด๋‹น ๊ฐ’์ด ๊ฒฐ๊ณผ์— ๋ฐ˜์˜๋˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์˜คํ•ดํ•  ์ˆ˜ ์žˆ์–ด ์ œ๊ฑฐํ•˜์˜€์Šต๋‹ˆ๋‹ค.

break;
case CANCELLED:
future.internalCancel();
Expand Down Expand Up @@ -2231,7 +2218,6 @@ public void complete() {
futures.add(future);
}


return new ArcusMultiFuture<>(futures, () -> {
for (CompletableFuture<?> future : futures) {
if (!future.isCompletedExceptionally() && Boolean.TRUE.equals(future.join())) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/spy/memcached/v2/AsyncArcusCommandsIF.java
Original file line number Diff line number Diff line change
Expand Up @@ -821,15 +821,15 @@ ArcusFuture<Boolean> mopCreate(String key, ElementValueType type,
/**
* Flush all items from all servers immediately.
*
* @return {@code true} if all servers flushed successfully, {@code false} otherwise
* @return always {@code true}
*/
ArcusFuture<Boolean> flush();

/**
* Flush all items from all servers after a given delay.
*
* @param delay delay in seconds before flushing. (&ge; -1)
* @return {@code true} if all servers flushed successfully, {@code false} otherwise
* @return always {@code true}
*/
ArcusFuture<Boolean> flush(int delay);

Expand Down
Loading