use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class Tables method getTableState.
/**
* 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 instance
* the Accumulo instance.
* @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(Instance instance, Table.ID tableId, boolean clearCachedState) {
String statePath = ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + tableId.canonicalID() + Constants.ZTABLE_STATE;
if (clearCachedState) {
Tables.clearCacheByPath(instance, statePath);
}
ZooCache zc = getZooCache(instance);
byte[] state = zc.get(statePath);
if (state == null)
return TableState.UNKNOWN;
return TableState.valueOf(new String(state, UTF_8));
}
use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class ServerClient method getConnection.
public static <CT extends TServiceClient> Pair<String, CT> getConnection(ClientContext context, TServiceClientFactory<CT> factory, boolean preferCachedConnections, long rpcTimeout) throws TTransportException {
checkArgument(context != null, "context is null");
// create list of servers
ArrayList<ThriftTransportKey> servers = new ArrayList<>();
// add tservers
Instance instance = context.getInstance();
ZooCache zc = new ZooCacheFactory().getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
for (String tserver : zc.getChildren(ZooUtil.getRoot(instance) + Constants.ZTSERVERS)) {
String path = ZooUtil.getRoot(instance) + Constants.ZTSERVERS + "/" + tserver;
byte[] data = ZooUtil.getLockData(zc, path);
if (data != null) {
String strData = new String(data, UTF_8);
if (!strData.equals("master"))
servers.add(new ThriftTransportKey(new ServerServices(strData).getAddress(Service.TSERV_CLIENT), rpcTimeout, context));
}
}
boolean opened = false;
try {
Pair<String, TTransport> pair = ThriftTransportPool.getInstance().getAnyTransport(servers, preferCachedConnections);
CT client = ThriftUtil.createClient(factory, pair.getSecond());
opened = true;
warnedAboutTServersBeingDown = false;
return new Pair<>(pair.getFirst(), client);
} finally {
if (!opened) {
if (!warnedAboutTServersBeingDown) {
if (servers.isEmpty()) {
log.warn("There are no tablet servers: check that zookeeper and accumulo are running.");
} else {
log.warn("Failed to find an available server in the list of servers: {}", servers);
}
warnedAboutTServersBeingDown = true;
}
}
}
}
use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class Namespaces method exists.
public static boolean exists(Instance instance, Namespace.ID namespaceId) {
ZooCache zc = getZooCache(instance);
List<String> namespaceIds = zc.getChildren(ZooUtil.getRoot(instance) + Constants.ZNAMESPACES);
return namespaceIds.contains(namespaceId.canonicalID());
}
use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class Namespaces method getNamespaceName.
/**
* Look for namespace name in ZK. Throw NamespaceNotFoundException if not found.
*/
public static String getNamespaceName(Instance instance, Namespace.ID namespaceId) throws NamespaceNotFoundException {
String name;
ZooCache zc = getZooCache(instance);
byte[] path = zc.get(ZooUtil.getRoot(instance) + Constants.ZNAMESPACES + "/" + namespaceId.canonicalID() + Constants.ZNAMESPACE_NAME);
if (path != null)
name = new String(path, UTF_8);
else
throw new NamespaceNotFoundException(namespaceId.canonicalID(), null, "getNamespaceName() failed to find namespace");
return name;
}
use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class Namespaces method getAllNamespaces.
/**
* Gets all the namespaces from ZK. The first arg (t) the BiConsumer accepts is the ID and the second (u) is the namespaceName.
*/
private static void getAllNamespaces(Instance instance, BiConsumer<String, String> biConsumer) {
final ZooCache zc = getZooCache(instance);
List<String> namespaceIds = zc.getChildren(ZooUtil.getRoot(instance) + Constants.ZNAMESPACES);
for (String id : namespaceIds) {
byte[] path = zc.get(ZooUtil.getRoot(instance) + Constants.ZNAMESPACES + "/" + id + Constants.ZNAMESPACE_NAME);
if (path != null) {
biConsumer.accept(id, new String(path, UTF_8));
}
}
}
Aggregations