Skip to content

Commit 35ba1d0

Browse files
author
Shih-Hao Yeh
committed
Add FT to bypass add optimization
1 parent 03a6804 commit 35ba1d0

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ public class EVCacheImpl implements EVCache, EVCacheImplMBean {
114114
private final Property<String> alias;
115115
private final Property<String> encoderBase;
116116

117+
private final Property<Boolean> bypassAddOpt;
118+
117119
EVCacheImpl(String appName, String cacheName, int timeToLive, Transcoder<?> transcoder, boolean enableZoneFallback,
118120
boolean throwException, EVCacheClientPoolManager poolManager) {
119121
this._appName = appName;
@@ -170,6 +172,9 @@ public class EVCacheImpl implements EVCache, EVCacheImplMBean {
170172
// auto key prepend with appname for duet feature.
171173
this.maxKeyLength = propertyRepository.get(_appName + ".max.key.length", Integer.class).orElseGet("evcache.max.key.length").orElse(200);
172174

175+
// bypass short-circuit optimization
176+
this.bypassAddOpt = propertyRepository.get(_appName + ".bypass.add.opt", Boolean.class).orElse(false);
177+
173178
// if alias changes, refresh my pool to point to the correct alias app
174179
this.alias = propertyRepository.get("EVCacheClientPoolManager." + appName + ".alias", String.class);
175180
this.alias.subscribe(i -> {
@@ -3322,7 +3327,7 @@ protected <T> EVCacheLatch add(String key, T value, Transcoder<T> tc, int timeTo
33223327
cd = _pool.getEVCacheClientForRead().getTranscoder().encode(value);
33233328
}
33243329
if (clientUtil == null) clientUtil = new EVCacheClientUtil(_appName, _pool.getOperationTimeout().get());
3325-
latch = clientUtil.add(evcKey, cd, evcacheValueTranscoder, timeToLive, policy, clients, latchCount, fixup);
3330+
latch = clientUtil.add(evcKey, cd, evcacheValueTranscoder, timeToLive, policy, clients, latchCount, fixup, bypassAddOpt.get());
33263331
if (event != null) {
33273332
event.setTTL(timeToLive);
33283333
event.setCachedData(cd);

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

Lines changed: 2 additions & 2 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) 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) throws Exception {
5353
if (cd == null) return null;
5454

5555
final EVCacheLatchImpl latch = new EVCacheLatchImpl(policy, latchCount, _appName);
@@ -73,7 +73,7 @@ public EVCacheLatch add(EVCacheKey evcKey, final CachedData cd, Transcoder evcac
7373
if(fixMissing) {
7474
boolean status = f.get().booleanValue();
7575
if(!status) { // most common case
76-
if(firstStatus == null) {
76+
if(firstStatus == null && !bypassAddOpt) {
7777
for(int i = 0; i < clients.length; i++) {
7878
latch.countDown();
7979
}

0 commit comments

Comments
 (0)