Skip to content

Commit 3d08034

Browse files
committed
Support for cloning writes across multiple evcache apps
1 parent 899eb14 commit 3d08034

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

evcache-client/src/main/java/com/netflix/evcache/pool/EVCacheClientPool.java

+40-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public class EVCacheClientPool implements Runnable, EVCacheClientPoolMBean {
6262

6363
private final DynamicIntProperty logOperations;
6464
private final DynamicStringSetProperty logOperationCalls;
65+
private final DynamicStringSetProperty cloneWrite;
6566

6667
private final DynamicIntProperty _opQueueMaxBlockTime; // Timeout for adding an operation
6768
private final DynamicIntProperty _operationTimeout;// Timeout for write operation
@@ -157,6 +158,12 @@ public void run() {
157158
this.logOperations = config.getDynamicIntProperty(appName + ".log.operation", 0);
158159
this.logOperationCalls = new DynamicStringSetProperty(appName + ".log.operation.calls", "SET,DELETE,GMISS,TMISS,BMISS_ALL,TOUCH,REPLACE");
159160
this.reconcileInterval = config.getDynamicIntProperty(appName + ".reconcile.interval", 600000);
161+
this.cloneWrite = new DynamicStringSetProperty(appName + ".clone.writes.to", "");
162+
this.cloneWrite.addCallback(new Runnable() {
163+
public void run() {
164+
setupClones();
165+
}
166+
});
160167

161168
final Map<String, String> map = new HashMap<String, String>();
162169
map.put("APP", _appName);
@@ -167,6 +174,12 @@ public void run() {
167174
if (log.isInfoEnabled()) log.info(toString());
168175
}
169176

177+
private void setupClones() {
178+
for(String cloneApp : cloneWrite.get()) {
179+
manager.initEVCache(cloneApp);
180+
}
181+
}
182+
170183
private void clearState() {
171184
cleanupMemcachedInstances(true);
172185
memcachedInstancesByServerGroup.clear();
@@ -295,7 +308,7 @@ public List<EVCacheClient> getEVCacheClientsForReadExcluding(ServerGroup serverG
295308
}
296309
return Collections.<EVCacheClient> emptyList();
297310
}
298-
311+
299312
public boolean isInWriteOnly(ServerGroup serverGroup) {
300313
if (memcachedReadInstancesByServerGroup.containsKey(serverGroup)) {
301314
return false;
@@ -330,7 +343,7 @@ public EVCacheClient[] getWriteOnlyEVCacheClients() {
330343
}
331344
}
332345

333-
public EVCacheClient[] getEVCacheClientForWrite() {
346+
EVCacheClient[] getAllWriteClients() {
334347
try {
335348
final EVCacheClient[] clientArr = new EVCacheClient[memcachedWriteInstancesByServerGroup.size()];
336349
int i = 0;
@@ -351,6 +364,31 @@ public EVCacheClient[] getEVCacheClientForWrite() {
351364
}
352365
}
353366

367+
368+
public EVCacheClient[] getEVCacheClientForWrite() {
369+
try {
370+
if((cloneWrite.get().size() == 0)) {
371+
return getAllWriteClients();
372+
} else {
373+
final List<EVCacheClient> evcacheClientList = new ArrayList<EVCacheClient>();
374+
final EVCacheClient[] clientArr = getAllWriteClients();
375+
for(EVCacheClient client : clientArr) {
376+
evcacheClientList.add(client);
377+
}
378+
for(String cloneApp : cloneWrite.get()) {
379+
final EVCacheClient[] cloneWriteArray = manager.getEVCacheClientPool(cloneApp).getAllWriteClients();
380+
for(int j = 0; j < cloneWriteArray.length; j++) {
381+
evcacheClientList.add(cloneWriteArray[j]);
382+
}
383+
}
384+
return evcacheClientList.toArray(new EVCacheClient[0]);
385+
}
386+
} catch (Throwable t) {
387+
log.error("Exception trying to get an array of writable EVCache Instances", t);
388+
return new EVCacheClient[0];
389+
}
390+
}
391+
354392
private void refresh() throws IOException {
355393
refresh(false);
356394
}

0 commit comments

Comments
 (0)