@@ -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