/** * 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; }
/** * 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()); }
public static void clearCache(ClientContext context) { getZooCache(context).clear(context.getZooKeeperRoot() + Constants.ZTABLES); getZooCache(context).clear(context.getZooKeeperRoot() + Constants.ZNAMESPACES); instanceToMapCache.invalidate(context.getInstanceID()); }
public static boolean exists(ClientContext context, Table.ID tableId) { ZooCache zc = getZooCache(context); List<String> tableIds = zc.getChildren(context.getZooKeeperRoot() + Constants.ZTABLES); return tableIds.contains(tableId.canonicalID()); }
/** * Returns the namespace id for a given table ID. * * @param context * The Accumulo client context * @param tableId * The tableId * @return The namespace id which this table resides in. * @throws IllegalArgumentException * if the table doesn't exist in ZooKeeper */ public static Namespace.ID getNamespaceId(ClientContext context, Table.ID tableId) throws TableNotFoundException { checkArgument(context != null, "instance is null"); checkArgument(tableId != null, "tableId is null"); ZooCache zc = getZooCache(context); byte[] n = zc.get(context.getZooKeeperRoot() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_NAMESPACE); // We might get null out of ZooCache if this tableID doesn't exist if (n == null) { throw new TableNotFoundException(tableId.canonicalID(), null, null); } return Namespace.ID.of(new String(n, UTF_8)); } }
/** * Get the current state of the table using the tableid. The boolean clearCache, if true will * clear the table state in zookeeper before fetching the state. Added with ACCUMULO-4574. * * @param context * the Accumulo client context * @param tableId * the table id * @param clearCachedState * if true clear the table state in zookeeper before checking status * @return the table state. */ public static TableState getTableState(ClientContext context, Table.ID tableId, boolean clearCachedState) { String statePath = context.getZooKeeperRoot() + Constants.ZTABLES + "/" + tableId.canonicalID() + Constants.ZTABLE_STATE; if (clearCachedState) { Tables.clearCacheByPath(context, statePath); } ZooCache zc = getZooCache(context); byte[] state = zc.get(statePath); if (state == null) return TableState.UNKNOWN; return TableState.valueOf(new String(state, UTF_8)); }