Skip to content

Commit

Permalink
INTERNAL: return partial result if error or cancel occurred in getSom…
Browse files Browse the repository at this point in the history
…e method of BulkGetFuture
  • Loading branch information
oliviarla committed Sep 19, 2024
1 parent 0551f61 commit 3176cb6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
10 changes: 4 additions & 6 deletions src/main/java/net/spy/memcached/internal/BulkFuture.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.spy.memcached.internal;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -29,17 +28,16 @@ public interface BulkFuture<V> extends Future<V> {
/**
* Wait for the operation to complete and return results.
*
* If operation could not complete within specified
* timeout, partial result is returned. Otherwise, the
* behavior is identical to {@link #get(long, TimeUnit)}
* If operation could not complete within specified timeout, error, cancellation occurred,
* partial result is returned.
* Otherwise, the behavior is identical to {@link #get(long, TimeUnit)}
*
* @param timeout the maximum time to wait
* @param unit the time unit of the timeout argument
* @return the computed result
* @throws InterruptedException if the current thread was interrupted while waiting
* @throws ExecutionException if the computation threw an exception
*/
V getSome(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException;
V getSome(long timeout, TimeUnit unit) throws InterruptedException;


int getOpCount();
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/net/spy/memcached/internal/BulkGetFuture.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,10 @@ public Map<String, T> get() throws InterruptedException, ExecutionException {
}

@Override
public Map<String, T> getSome(long duration, TimeUnit unit)
throws InterruptedException, ExecutionException {

public Map<String, T> getSome(long duration, TimeUnit unit) throws InterruptedException {
try {
return internalGet(duration, unit, false);
} catch (TimeoutException e) {
} catch (TimeoutException | ExecutionException e) {
throw new AssertionError("Something went wrong...", e);
}
}
Expand Down Expand Up @@ -131,8 +129,8 @@ public int getOpCount() {
* refactored code common to both get(long, TimeUnit) and getSome(long,
* TimeUnit)
*/
private Map<String, T> internalGet(long to, TimeUnit unit, boolean throwOnTimeout)
throws InterruptedException, ExecutionException, TimeoutException {
private Map<String, T> internalGet(long to, TimeUnit unit, boolean throwException)
throws InterruptedException, ExecutionException, TimeoutException {

long beforeAwait = System.currentTimeMillis();
if (!latch.await(to, unit)) {
Expand All @@ -150,7 +148,7 @@ private Map<String, T> internalGet(long to, TimeUnit unit, boolean throwOnTimeou

long elapsed = System.currentTimeMillis() - beforeAwait;
TimeoutException e = new CheckedOperationTimeoutException(to, unit, elapsed, timedOutOps);
if (throwOnTimeout) {
if (throwException) {
throw e;
}
LoggerFactory.getLogger(getClass()).warn(e.getMessage());
Expand All @@ -177,6 +175,7 @@ private Map<String, T> internalGet(long to, TimeUnit unit, boolean throwOnTimeou
}
return resultMap;
}

/*
* set to true if timeout was reached.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public Map<String, T> get(long duration, TimeUnit unit)
}

@Override
public Map<String, T> getSome(long duration, TimeUnit unit)
throws InterruptedException, ExecutionException {
public Map<String, T> getSome(long duration, TimeUnit unit) throws InterruptedException {
if (result != null) {
return result;
}
Expand Down

0 comments on commit 3176cb6

Please sign in to comment.