Search in sources :

Example 11 with ZooCache

use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.

the class RootTabletLocator method getRootTabletLocation.

protected TabletLocation getRootTabletLocation(ClientContext context) {
    Instance instance = context.getInstance();
    String zRootLocPath = ZooUtil.getRoot(instance) + RootTable.ZROOT_TABLET_LOCATION;
    ZooCache zooCache = zcf.getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
    Logger log = LoggerFactory.getLogger(this.getClass());
    OpTimer timer = null;
    if (log.isTraceEnabled()) {
        log.trace("tid={} Looking up root tablet location in zookeeper.", Thread.currentThread().getId());
        timer = new OpTimer().start();
    }
    byte[] loc = zooCache.get(zRootLocPath);
    if (timer != null) {
        timer.stop();
        log.trace("tid={} Found root tablet at {} in {}", Thread.currentThread().getId(), (loc == null ? "null" : new String(loc)), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS)));
    }
    if (loc == null) {
        return null;
    }
    String[] tokens = new String(loc).split("\\|");
    if (lockChecker.isLockHeld(tokens[0], tokens[1]))
        return new TabletLocation(RootTable.EXTENT, tokens[0], tokens[1]);
    else
        return null;
}
Also used : Instance(org.apache.accumulo.core.client.Instance) OpTimer(org.apache.accumulo.core.util.OpTimer) Logger(org.slf4j.Logger) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache)

Example 12 with ZooCache

use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.

the class RootTabletLocator method invalidateCache.

@Override
public void invalidateCache(Instance instance, String server) {
    ZooCache zooCache = zcf.getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
    String root = ZooUtil.getRoot(instance) + Constants.ZTSERVERS;
    zooCache.clear(root + "/" + server);
}
Also used : ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache)

Example 13 with ZooCache

use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.

the class InstanceOperationsImpl method getTabletServers.

@Override
public List<String> getTabletServers() {
    Instance instance = context.getInstance();
    ZooCache cache = new ZooCacheFactory().getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
    String path = ZooUtil.getRoot(instance) + Constants.ZTSERVERS;
    List<String> results = new ArrayList<>();
    for (String candidate : cache.getChildren(path)) {
        List<String> children = cache.getChildren(path + "/" + candidate);
        if (children != null && children.size() > 0) {
            List<String> copy = new ArrayList<>(children);
            Collections.sort(copy);
            byte[] data = cache.get(path + "/" + candidate + "/" + copy.get(0));
            if (data != null && !"master".equals(new String(data, UTF_8))) {
                results.add(candidate);
            }
        }
    }
    return results;
}
Also used : ZooCacheFactory(org.apache.accumulo.fate.zookeeper.ZooCacheFactory) Instance(org.apache.accumulo.core.client.Instance) ArrayList(java.util.ArrayList) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache)

Example 14 with ZooCache

use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.

the class TabletServerLocks method main.

public static void main(String[] args) throws Exception {
    Instance instance = HdfsZooInstance.getInstance();
    String tserverPath = ZooUtil.getRoot(instance) + Constants.ZTSERVERS;
    Opts opts = new Opts();
    opts.parseArgs(TabletServerLocks.class.getName(), args);
    ZooCache cache = new ZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
    if (opts.list) {
        IZooReaderWriter zoo = ZooReaderWriter.getInstance();
        List<String> tabletServers = zoo.getChildren(tserverPath);
        for (String tabletServer : tabletServers) {
            byte[] lockData = ZooLock.getLockData(cache, tserverPath + "/" + tabletServer, null);
            String holder = null;
            if (lockData != null) {
                holder = new String(lockData, UTF_8);
            }
            System.out.printf("%32s %16s%n", tabletServer, holder);
        }
    } else if (opts.delete != null) {
        ZooLock.deleteLock(tserverPath + "/" + args[1]);
    } else {
        System.out.println("Usage : " + TabletServerLocks.class.getName() + " -list|-delete <tserver lock>");
    }
}
Also used : Instance(org.apache.accumulo.core.client.Instance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache)

Example 15 with ZooCache

use of org.apache.accumulo.fate.zookeeper.ZooCache in project accumulo by apache.

the class BadDeleteMarkersCreatedIT method alterConfig.

@Before
public void alterConfig() throws Exception {
    InstanceOperations iops = getConnector().instanceOperations();
    Map<String, String> config = iops.getSystemConfiguration();
    gcCycleDelay = config.get(Property.GC_CYCLE_DELAY.getKey());
    gcCycleStart = config.get(Property.GC_CYCLE_START.getKey());
    iops.setProperty(Property.GC_CYCLE_DELAY.getKey(), "1s");
    iops.setProperty(Property.GC_CYCLE_START.getKey(), "0s");
    log.info("Restarting garbage collector");
    getCluster().getClusterControl().stopAllServers(ServerType.GARBAGE_COLLECTOR);
    Instance instance = getConnector().getInstance();
    ZooCache zcache = new ZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
    zcache.clear();
    String path = ZooUtil.getRoot(instance) + Constants.ZGC_LOCK;
    byte[] gcLockData;
    do {
        gcLockData = ZooLock.getLockData(zcache, path, null);
        if (null != gcLockData) {
            log.info("Waiting for GC ZooKeeper lock to expire");
            Thread.sleep(2000);
        }
    } while (null != gcLockData);
    log.info("GC lock was lost");
    getCluster().getClusterControl().startAllServers(ServerType.GARBAGE_COLLECTOR);
    log.info("Garbage collector was restarted");
    gcLockData = null;
    do {
        gcLockData = ZooLock.getLockData(zcache, path, null);
        if (null == gcLockData) {
            log.info("Waiting for GC ZooKeeper lock to be acquired");
            Thread.sleep(2000);
        }
    } while (null == gcLockData);
    log.info("GC lock was acquired");
}
Also used : Instance(org.apache.accumulo.core.client.Instance) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache) InstanceOperations(org.apache.accumulo.core.client.admin.InstanceOperations) Before(org.junit.Before)

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