Skip to content

Commit f9a6230

Browse files
author
Shih-Hao Yeh
committed
fixup as fail
1 parent c3d4639 commit f9a6230

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public class EVCacheImpl implements EVCache, EVCacheImplMBean {
116116

117117
private final Property<Boolean> bypassAddOpt;
118118
private final Property<Boolean> bypassFixup;
119+
private final Property<Boolean> fixupAsFail;
119120

120121
EVCacheImpl(String appName, String cacheName, int timeToLive, Transcoder<?> transcoder, boolean enableZoneFallback,
121122
boolean throwException, EVCacheClientPoolManager poolManager) {
@@ -176,6 +177,7 @@ public class EVCacheImpl implements EVCache, EVCacheImplMBean {
176177
// bypass short-circuit optimization
177178
this.bypassAddOpt = propertyRepository.get(_appName + ".bypass.add.opt", Boolean.class).orElse(false);
178179
this.bypassFixup = propertyRepository.get(_appName + ".bypass.fixup", Boolean.class).orElse(false);
180+
this.fixupAsFail = propertyRepository.get(_appName + ".fixup.as.fail", Boolean.class).orElse(false);
179181

180182
// if alias changes, refresh my pool to point to the correct alias app
181183
this.alias = propertyRepository.get("EVCacheClientPoolManager." + appName + ".alias", String.class);
@@ -3329,7 +3331,7 @@ protected <T> EVCacheLatch add(String key, T value, Transcoder<T> tc, int timeTo
33293331
cd = _pool.getEVCacheClientForRead().getTranscoder().encode(value);
33303332
}
33313333
if (clientUtil == null) clientUtil = new EVCacheClientUtil(_appName, _pool.getOperationTimeout().get());
3332-
latch = clientUtil.add(evcKey, cd, evcacheValueTranscoder, timeToLive, policy, clients, latchCount, fixup, bypassAddOpt.get());
3334+
latch = clientUtil.add(evcKey, cd, evcacheValueTranscoder, timeToLive, policy, clients, latchCount, fixup, bypassAddOpt.get(), fixupAsFail.get());
33333335
if (event != null) {
33343336
event.setTTL(timeToLive);
33353337
event.setCachedData(cd);

evcache-core/src/main/java/com/netflix/evcache/pool/EVCacheClientUtil.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public EVCacheClientUtil(String appName, long operationTimeout) {
4949
/**
5050
* TODO : once metaget is available we need to get the remaining ttl from an existing entry and use it
5151
*/
52-
public EVCacheLatch add(EVCacheKey evcKey, final CachedData cd, Transcoder evcacheValueTranscoder, int timeToLive, Policy policy, final EVCacheClient[] clients, int latchCount, boolean fixMissing, boolean bypassAddOpt) throws Exception {
52+
public EVCacheLatch add(EVCacheKey evcKey, final CachedData cd, Transcoder evcacheValueTranscoder, int timeToLive, Policy policy, final EVCacheClient[] clients, int latchCount, boolean fixMissing, boolean bypassAddOpt, boolean fixupAsFail) throws Exception {
5353
if (cd == null) return null;
5454

5555
final EVCacheLatchImpl latch = new EVCacheLatchImpl(policy, latchCount, _appName);
@@ -83,11 +83,11 @@ public EVCacheLatch add(EVCacheKey evcKey, final CachedData cd, Transcoder evcac
8383
return latch;
8484
}
8585
else {
86-
return fixup(client, clients, evcKey, timeToLive, policy);
86+
return fixup(client, clients, evcKey, timeToLive, policy, latch, fixupAsFail);
8787
}
8888
} else {
8989
if (log.isDebugEnabled()) log.debug("Add failed after first client. key: " + key + ", client : " + client);
90-
return fixup(client, clients, evcKey, timeToLive, policy);
90+
return fixup(client, clients, evcKey, timeToLive, policy, latch, fixupAsFail);
9191
}
9292
}
9393
if(firstStatus == null) firstStatus = Boolean.valueOf(status);
@@ -96,7 +96,7 @@ public EVCacheLatch add(EVCacheKey evcKey, final CachedData cd, Transcoder evcac
9696
return latch;
9797
}
9898

99-
private EVCacheLatch fixup(EVCacheClient sourceClient, EVCacheClient[] destClients, EVCacheKey evcKey, int timeToLive, Policy policy) {
99+
private EVCacheLatch fixup(EVCacheClient sourceClient, EVCacheClient[] destClients, EVCacheKey evcKey, int timeToLive, Policy policy, EVCacheLatchImpl prevLatch, boolean fixupAsFail) {
100100
if (log.isDebugEnabled()) log.debug("Trying to fix up!! destClient count = " + destClients.length);
101101
final EVCacheLatchImpl latch = new EVCacheLatchImpl(policy, destClients.length, _appName);
102102
try {
@@ -110,7 +110,16 @@ private EVCacheLatch fixup(EVCacheClient sourceClient, EVCacheClient[] destClien
110110
}
111111
latch.await(_operationTimeout, TimeUnit.MILLISECONDS);
112112
} catch (Exception e) {
113-
log.error("Error reading the data", e);
113+
log.error("Error fixing up the data.", e);
114+
}
115+
116+
// We still do our best to fixup, but client should know the key exist before the Add
117+
if (fixupAsFail) {
118+
for (int i = 0; i < destClients.length; i++) {
119+
prevLatch.countDown();
120+
}
121+
if (log.isDebugEnabled()) log.debug("Fixup treated as fail. latchSuccess = " + prevLatch.getSuccessCount() + ", latchExpected = " + prevLatch.getExpectedSuccessCount());
122+
return prevLatch;
114123
}
115124
return latch;
116125
}

0 commit comments

Comments
 (0)