Search in sources :

Example 6 with ZooCache

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;
}
Also used : PropCacheKey(org.apache.accumulo.server.conf.ZooCachePropertyAccessor.PropCacheKey) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache)

Example 7 with ZooCache

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;
}
Also used : PropCacheKey(org.apache.accumulo.server.conf.ZooCachePropertyAccessor.PropCacheKey) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache)

Example 8 with ZooCache

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;
}
Also used : Path(org.apache.hadoop.fs.Path) WatchedEvent(org.apache.zookeeper.WatchedEvent) VolumeManager(org.apache.accumulo.server.fs.VolumeManager) Watcher(org.apache.zookeeper.Watcher) IOException(java.io.IOException) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache)

Example 9 with ZooCache

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());
}
Also used : ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache)

Example 10 with ZooCache

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));
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache)

Aggregations

ZooCache (org.apache.accumulo.fate.zookeeper.ZooCache)25 Instance (org.apache.accumulo.core.client.Instance)7 Test (org.junit.Test)6 ZooCacheFactory (org.apache.accumulo.fate.zookeeper.ZooCacheFactory)5 ClientConfiguration (org.apache.accumulo.core.client.ClientConfiguration)4 Connector (org.apache.accumulo.core.client.Connector)4 ZooReader (org.apache.accumulo.fate.zookeeper.ZooReader)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ClusterControl (org.apache.accumulo.cluster.ClusterControl)3 File (java.io.File)2 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)2 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)2 ServerServices (org.apache.accumulo.core.util.ServerServices)2 PropCacheKey (org.apache.accumulo.server.conf.ZooCachePropertyAccessor.PropCacheKey)2 Path (org.apache.hadoop.fs.Path)2 TTransport (org.apache.thrift.transport.TTransport)2 FileOutputStream (java.io.FileOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 URL (java.net.URL)1