Skip to content

Commit

Permalink
Fix race condition in Tables. Closes apache#768
Browse files Browse the repository at this point in the history
  • Loading branch information
milleruntime committed Feb 19, 2019
1 parent 6ab7569 commit 45ef1da
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions core/src/main/java/org/apache/accumulo/core/clientImpl/Tables.java
Expand Up @@ -51,8 +51,6 @@ public class Tables {
// frequently
private static Cache<String,TableMap> instanceToMapCache = CacheBuilder.newBuilder()
.expireAfterAccess(10, TimeUnit.MINUTES).build();
private static Cache<String,ZooCache> instanceToZooCache = CacheBuilder.newBuilder()
.expireAfterAccess(10, TimeUnit.MINUTES).build();

static {
SingletonManager.register(new SingletonService() {
Expand All @@ -73,7 +71,6 @@ public synchronized void enable() {
public synchronized void disable() {
try {
instanceToMapCache.invalidateAll();
instanceToZooCache.invalidateAll();
} finally {
enabled = false;
}
Expand All @@ -95,28 +92,14 @@ public static TableId getTableId(ClientContext context, String tableName)
}
}

/**
* Return the cached ZooCache for provided context. ZooCache is initially created with a watcher
* that will clear the TableMap cache for that instance when WatchedEvent occurs.
*/
private static ZooCache getZooCache(final ClientContext context) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(TABLES_PERMISSION);
}

final String uuid = context.getInstanceID();

try {
return instanceToZooCache.get(uuid, () -> {
final String zks = context.getZooKeepers();
final int timeOut = context.getZooKeepersSessionTimeOut();
return new ZooCacheFactory().getZooCache(zks, timeOut,
watchedEvent -> instanceToMapCache.invalidate(uuid));
});
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
return new ZooCacheFactory().getZooCache(context.getZooKeepers(),
context.getZooKeepersSessionTimeOut());
}

/**
Expand Down

0 comments on commit 45ef1da

Please sign in to comment.