Skip to content

Commit

Permalink
INTERNAL: Add warning log when OperationStatus.isSuccess() is false.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhm0311 committed Jun 12, 2024
1 parent 9c8437b commit 8e40b3c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 34 deletions.
64 changes: 30 additions & 34 deletions src/main/java/com/navercorp/arcus/spring/cache/ArcusCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
import com.navercorp.arcus.spring.concurrent.KeyLockProvider;

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

import javax.annotation.Nullable;

import net.spy.memcached.ArcusClientPool;
import net.spy.memcached.internal.GetFuture;
import net.spy.memcached.internal.OperationFuture;
import net.spy.memcached.ops.OperationStatus;
import net.spy.memcached.transcoders.Transcoder;

import org.slf4j.Logger;
Expand Down Expand Up @@ -219,24 +221,23 @@ public ValueWrapper putIfAbsent(Object key, Object value) {
}

try {
Future<Boolean> future;

OperationFuture<Boolean> future;
if (operationTranscoder != null) {
future = arcusClient.add(arcusKey, expireSeconds, value,
operationTranscoder);
future = arcusClient.add(arcusKey, expireSeconds, value, operationTranscoder);
} else {
future = arcusClient.add(arcusKey, expireSeconds, value);
}

boolean added = future.get(timeoutMilliSeconds,
TimeUnit.MILLISECONDS);

if (added && arcusFrontCache != null) {
boolean success = future.get(timeoutMilliSeconds, TimeUnit.MILLISECONDS);
if (!success) {
OperationStatus status = future.getStatus();
logger.info("failed to putIfAbsent a key: {}, status: {}", arcusKey, status.getMessage());
} else if (arcusFrontCache != null) {
arcusFrontCache.set(arcusKey, value, frontExpireSeconds);
}

// FIXME: maybe returned with a different value.
return added ? null : new SimpleValueWrapper(getValue(arcusKey));
return success ? null : new SimpleValueWrapper(getValue(arcusKey));
} catch (Exception e) {
if (wantToGetException) {
throw toRuntimeException(e);
Expand All @@ -254,13 +255,11 @@ public void evict(final Object key) {
boolean success = false;

try {
Future<Boolean> future = arcusClient.delete(arcusKey);

success = future.get(timeoutMilliSeconds,
TimeUnit.MILLISECONDS);

OperationFuture<Boolean> future = arcusClient.delete(arcusKey);
success = future.get(timeoutMilliSeconds, TimeUnit.MILLISECONDS);
if (!success) {
logger.info("failed to evict a key: {}", arcusKey);
OperationStatus status = future.getStatus();
logger.info("failed to evict a key: {}, status: {}", arcusKey, status.getMessage());
}
} catch (Exception e) {
if (wantToGetException) {
Expand All @@ -283,15 +282,11 @@ public void clear() {
boolean success = false;

try {
Future<Boolean> future = arcusClient.flush(arcusPrefix);

success = future.get(timeoutMilliSeconds,
TimeUnit.MILLISECONDS);

OperationFuture<Boolean> future = arcusClient.flush(arcusPrefix);
success = future.get(timeoutMilliSeconds, TimeUnit.MILLISECONDS);
if (!success) {
logger.info(
"failed to evicting every key that uses the prefix: {}",
arcusPrefix);
OperationStatus status = future.getStatus();
logger.info("failed to clear a prefix: {}, status: {}", arcusPrefix, status.getMessage());
}
} catch (Exception e) {
if (wantToGetException) {
Expand Down Expand Up @@ -480,22 +475,25 @@ private Object getValue(String arcusKey) throws Exception {
return value;
}

Future<Object> future;

// operation transcoder can't be null.
GetFuture<Object> future;
if (operationTranscoder != null) {
future = arcusClient.asyncGet(arcusKey, operationTranscoder);
} else {
future = arcusClient.asyncGet(arcusKey);
}

value = future.get(timeoutMilliSeconds, TimeUnit.MILLISECONDS);

if (value != null) {
logger.debug("arcus cache hit for {}", arcusKey);
if (arcusFrontCache != null) {
arcusFrontCache.set(arcusKey, value, frontExpireSeconds);
}
} else {
logger.debug("arcus cache miss for {}", arcusKey);
OperationStatus status = future.getStatus();
if (!status.isSuccess()) {
logger.info("failed to get a key: {}, status: {}", arcusKey, status.getMessage());
}
}

return value;
Expand All @@ -512,19 +510,17 @@ private void putValue(String arcusKey, Object value) throws Exception {
boolean success = false;

try {
Future<Boolean> future;

OperationFuture<Boolean> future;
if (operationTranscoder != null) {
future = arcusClient.set(arcusKey, expireSeconds, value,
operationTranscoder);
future = arcusClient.set(arcusKey, expireSeconds, value, operationTranscoder);
} else {
future = arcusClient.set(arcusKey, expireSeconds, value);
}

success = future.get(timeoutMilliSeconds, TimeUnit.MILLISECONDS);

if (!success) {
logger.info("failed to put a key: {}", arcusKey);
OperationStatus status = future.getStatus();
logger.info("failed to put a key: {}, status: {}", arcusKey, status.getMessage());
}
} finally {
if (arcusFrontCache != null &&
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/com/navercorp/arcus/spring/cache/ArcusCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import net.spy.memcached.ArcusClientPool;
import net.spy.memcached.internal.GetFuture;
import net.spy.memcached.internal.OperationFuture;
import net.spy.memcached.ops.OperationStatus;
import net.spy.memcached.ops.StatusCode;
import net.spy.memcached.transcoders.SerializingTranscoder;
import net.spy.memcached.transcoders.Transcoder;

Expand Down Expand Up @@ -1359,6 +1361,11 @@ public Object get() {
public Object get(long timeout, TimeUnit unit) {
return value;
}

@Override
public OperationStatus getStatus() {
return new OperationStatus(true, "END", StatusCode.SUCCESS);
}
};
}

Expand Down Expand Up @@ -1388,6 +1395,11 @@ public Object get() {
public Object get(long timeout, TimeUnit unit) {
throw new TestException();
}

@Override
public OperationStatus getStatus() {
return new OperationStatus(false, "UNDEFINED", StatusCode.UNDEFINED);
}
};
}

Expand Down Expand Up @@ -1418,6 +1430,14 @@ public Boolean get() {
public Boolean get(long timeout, TimeUnit unit) {
return value;
}

@Override
public OperationStatus getStatus() {
if (value) {
return new OperationStatus(true, "OK", StatusCode.SUCCESS);
}
return new OperationStatus(false, "UNDEFINED", StatusCode.UNDEFINED);
}
};
}

Expand Down Expand Up @@ -1447,6 +1467,11 @@ public Boolean get() {
public Boolean get(long timeout, TimeUnit unit) {
throw new TestException();
}

@Override
public OperationStatus getStatus() {
return new OperationStatus(false, "UNDEFINED", StatusCode.UNDEFINED);
}
};
}

Expand Down

0 comments on commit 8e40b3c

Please sign in to comment.