@Override public String getInstanceID() { return context.getInstanceID(); }
/** * Get the TableMap from the cache. A new one will be populated when needed. Cache is cleared * manually by calling {@link #clearCache(ClientContext)} or automatically cleared by ZooCache * watcher created in {@link #getZooCache(ClientContext)}. See ACCUMULO-4778. */ private static TableMap getTableMap(final ClientContext context) { TableMap map; try { map = instanceToMapCache.get(context.getInstanceID(), () -> new TableMap(context, getZooCache(context))); } catch (ExecutionException e) { throw new RuntimeException(e); } return map; }
public String getZooKeeperRoot() { ensureOpen(); return ZooUtil.getRoot(getInstanceID()); }
/** * Clears the zoo cache from instance/root/{PATH} * * @param context * The Accumulo client context * @param zooPath * A zookeeper path */ public static void clearCacheByPath(ClientContext context, final String zooPath) { String thePath = zooPath.startsWith("/") ? zooPath : "/" + zooPath; getZooCache(context).clear(context.getZooKeeperRoot() + thePath); instanceToMapCache.invalidate(context.getInstanceID()); }
/** * 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); } }
@Override public boolean authenticateUser(final String principal, final AuthenticationToken token) throws AccumuloException, AccumuloSecurityException { checkArgument(principal != null, "principal is null"); checkArgument(token != null, "token is null"); final Credentials toAuth = new Credentials(principal, token); return execute(client -> client.authenticateUser(Tracer.traceInfo(), context.rpcCreds(), toAuth.toThrift(context.getInstanceID()))); }
public static void clearCache(ClientContext context) { getZooCache(context).clear(context.getZooKeeperRoot() + Constants.ZTABLES); getZooCache(context).clear(context.getZooKeeperRoot() + Constants.ZNAMESPACES); instanceToMapCache.invalidate(context.getInstanceID()); }
/** * Serialize the credentials just before initiating the RPC call */ public synchronized TCredentials rpcCreds() { ensureOpen(); if (getCredentials().getToken().isDestroyed()) { rpcCreds = null; } if (rpcCreds == null) { rpcCreds = getCredentials().toThrift(getInstanceID()); } return rpcCreds; }
public static synchronized TabletLocator getLocator(ClientContext context, Table.ID tableId) { Preconditions.checkState(enabled, "The Accumulo singleton that that tracks tablet locations is " + "disabled. This is likely caused by all AccumuloClients being closed or garbage collected" + "."); LocatorKey key = new LocatorKey(context.getInstanceID(), tableId); TabletLocator tl = locators.get(key); if (tl == null) { MetadataLocationObtainer mlo = new MetadataLocationObtainer(); if (RootTable.ID.equals(tableId)) { tl = new RootTabletLocator(new ZookeeperLockChecker(context)); } else if (MetadataTable.ID.equals(tableId)) { tl = new TabletLocatorImpl(MetadataTable.ID, getLocator(context, RootTable.ID), mlo, new ZookeeperLockChecker(context)); } else { tl = new TabletLocatorImpl(tableId, getLocator(context, MetadataTable.ID), mlo, new ZookeeperLockChecker(context)); } locators.put(key, tl); } return tl; }