use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class NamespaceConfiguration method getPropCacheAccessor.
private synchronized ZooCachePropertyAccessor getPropCacheAccessor() {
if (propCacheAccessor == null) {
synchronized (propCaches) {
PropCacheKey key = new PropCacheKey(inst.getInstanceID(), namespaceId.canonicalID());
ZooCache propCache = propCaches.get(key);
if (propCache == null) {
propCache = zcf.getZooCache(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut(), new NamespaceConfWatcher(inst));
propCaches.put(key, propCache);
}
propCacheAccessor = new ZooCachePropertyAccessor(propCache);
}
}
return propCacheAccessor;
}
use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class TableConfiguration method getPropCacheAccessor.
private synchronized ZooCachePropertyAccessor getPropCacheAccessor() {
if (propCacheAccessor == null) {
synchronized (propCaches) {
PropCacheKey key = new PropCacheKey(instance.getInstanceID(), tableId.canonicalID());
ZooCache propCache = propCaches.get(key);
if (propCache == null) {
propCache = zcf.getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut(), new TableConfWatcher(instance));
propCaches.put(key, propCache);
}
propCacheAccessor = new ZooCachePropertyAccessor(propCache);
}
}
return propCacheAccessor;
}
use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class ZooConfigurationFactory method getInstance.
/**
* Gets a configuration object for the given instance with the given parent. Repeated calls will return the same object.
*
* @param inst
* instance; if null, instance is determined from HDFS
* @param zcf
* {@link ZooCacheFactory} for building {@link ZooCache} to contact ZooKeeper (required)
* @param parent
* parent configuration (required)
* @return configuration
*/
ZooConfiguration getInstance(Instance inst, ZooCacheFactory zcf, AccumuloConfiguration parent) {
String instanceId;
if (inst == null) {
// InstanceID should be the same across all volumes, so just choose one
VolumeManager fs;
try {
fs = VolumeManagerImpl.get();
} catch (IOException e) {
throw new RuntimeException(e);
}
Path instanceIdPath = Accumulo.getAccumuloInstanceIdPath(fs);
instanceId = ZooUtil.getInstanceIDFromHdfs(instanceIdPath, parent);
} else {
instanceId = inst.getInstanceID();
}
ZooConfiguration config;
synchronized (instances) {
config = instances.get(instanceId);
if (config == null) {
ZooCache propCache;
// The purpose of this watcher is a hack. It forces the creation on a new zoocache instead of using a shared one. This was done so that the zoocache
// would update less, causing the configuration update count to changes less.
Watcher watcher = new Watcher() {
@Override
public void process(WatchedEvent arg0) {
}
};
if (inst == null) {
propCache = zcf.getZooCache(parent.get(Property.INSTANCE_ZK_HOST), (int) parent.getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT), watcher);
} else {
propCache = zcf.getZooCache(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut(), watcher);
}
config = new ZooConfiguration(instanceId, propCache, parent);
instances.put(instanceId, config);
}
}
return config;
}
use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class Tables method exists.
public static boolean exists(Instance instance, Table.ID tableId) {
ZooCache zc = getZooCache(instance);
List<String> tableIds = zc.getChildren(ZooUtil.getRoot(instance) + Constants.ZTABLES);
return tableIds.contains(tableId.canonicalID());
}
use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.
the class Tables method getNamespaceId.
/**
* Returns the namespace id for a given table ID.
*
* @param instance
* The Accumulo Instance
* @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(Instance instance, Table.ID tableId) throws TableNotFoundException {
checkArgument(instance != null, "instance is null");
checkArgument(tableId != null, "tableId is null");
ZooCache zc = getZooCache(instance);
byte[] n = zc.get(ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_NAMESPACE);
// We might get null out of ZooCache if this tableID doesn't exist
if (null == n) {
throw new TableNotFoundException(tableId.canonicalID(), null, null);
}
return Namespace.ID.of(new String(n, UTF_8));
}
Aggregations