Search in sources :

Example 16 with ZooCache

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

the class CacheTestReader method main.

public static void main(String[] args) throws Exception {
    String rootDir = args[0];
    String reportDir = args[1];
    String keepers = args[2];
    int numData = CacheTestWriter.NUM_DATA;
    File myfile = new File(reportDir + "/" + UUID.randomUUID());
    myfile.deleteOnExit();
    ZooCache zc = new ZooCache(keepers, 30000);
    while (true) {
        if (myfile.exists() && !myfile.delete()) {
            LoggerFactory.getLogger(CacheTestReader.class).warn("Unable to delete {}", myfile);
        }
        if (zc.get(rootDir + "/die") != null) {
            return;
        }
        Map<String, String> readData = new TreeMap<>();
        for (int i = 0; i < numData; i++) {
            byte[] v = zc.get(rootDir + "/data" + i);
            if (v != null)
                readData.put(rootDir + "/data" + i, new String(v, UTF_8));
        }
        byte[] v = zc.get(rootDir + "/dataS");
        if (v != null)
            readData.put(rootDir + "/dataS", new String(v, UTF_8));
        List<String> children = zc.getChildren(rootDir + "/dir");
        if (children != null)
            for (String child : children) {
                readData.put(rootDir + "/dir/" + child, "");
            }
        FileOutputStream fos = new FileOutputStream(myfile);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(readData);
        fos.close();
        oos.close();
        sleepUninterruptibly(20, TimeUnit.MILLISECONDS);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) TreeMap(java.util.TreeMap) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache)

Example 17 with ZooCache

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

the class TransportCachingIT method testCachedTransport.

@Test
public void testCachedTransport() {
    Connector conn = getConnector();
    Instance instance = conn.getInstance();
    ClientConfiguration clientConf = cluster.getClientConfig();
    ClientContext context = new ClientContext(instance, new Credentials(getAdminPrincipal(), getAdminToken()), clientConf);
    long rpcTimeout = ConfigurationTypeHelper.getTimeInMillis(Property.GENERAL_RPC_TIMEOUT.getDefaultValue());
    // create list of servers
    ArrayList<ThriftTransportKey> servers = new ArrayList<>();
    // add tservers
    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));
        }
    }
    ThriftTransportPool pool = ThriftTransportPool.getInstance();
    TTransport first = null;
    while (null == first) {
        try {
            // Get a transport (cached or not)
            first = pool.getAnyTransport(servers, true).getSecond();
        } catch (TTransportException e) {
            log.warn("Failed to obtain transport to {}", servers);
        }
    }
    assertNotNull(first);
    // Return it to unreserve it
    pool.returnTransport(first);
    TTransport second = null;
    while (null == second) {
        try {
            // Get a cached transport (should be the first)
            second = pool.getAnyTransport(servers, true).getSecond();
        } catch (TTransportException e) {
            log.warn("Failed obtain 2nd transport to {}", servers);
        }
    }
    // We should get the same transport
    assertTrue("Expected the first and second to be the same instance", first == second);
    // Return the 2nd
    pool.returnTransport(second);
    TTransport third = null;
    while (null == third) {
        try {
            // Get a non-cached transport
            third = pool.getAnyTransport(servers, false).getSecond();
        } catch (TTransportException e) {
            log.warn("Failed obtain 2nd transport to {}", servers);
        }
    }
    assertFalse("Expected second and third transport to be different instances", second == third);
    pool.returnTransport(third);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) ServerServices(org.apache.accumulo.core.util.ServerServices) Instance(org.apache.accumulo.core.client.Instance) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) ArrayList(java.util.ArrayList) TTransportException(org.apache.thrift.transport.TTransportException) ThriftTransportPool(org.apache.accumulo.core.client.impl.ThriftTransportPool) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache) ZooCacheFactory(org.apache.accumulo.fate.zookeeper.ZooCacheFactory) ThriftTransportKey(org.apache.accumulo.core.client.impl.ThriftTransportKey) TTransport(org.apache.thrift.transport.TTransport) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) Credentials(org.apache.accumulo.core.client.impl.Credentials) Test(org.junit.Test)

Example 18 with ZooCache

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

the class ReplicationIT method waitForGCLock.

private void waitForGCLock(Connector conn) throws InterruptedException {
    // Check if the GC process has the lock before wasting our retry attempts
    ZooKeeperInstance zki = (ZooKeeperInstance) conn.getInstance();
    ZooCacheFactory zcf = new ZooCacheFactory();
    ZooCache zcache = zcf.getZooCache(zki.getZooKeepers(), zki.getZooKeepersSessionTimeOut());
    String zkPath = ZooUtil.getRoot(conn.getInstance()) + Constants.ZGC_LOCK;
    log.info("Looking for GC lock at {}", zkPath);
    byte[] data = ZooLock.getLockData(zcache, zkPath, null);
    while (null == data) {
        log.info("Waiting for GC ZooKeeper lock to be acquired");
        Thread.sleep(1000);
        data = ZooLock.getLockData(zcache, zkPath, null);
    }
}
Also used : ZooCacheFactory(org.apache.accumulo.fate.zookeeper.ZooCacheFactory) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance)

Example 19 with ZooCache

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

the class Admin method stopTabletServer.

private static void stopTabletServer(final ClientContext context, List<String> servers, final boolean force) throws AccumuloException, AccumuloSecurityException {
    if (context.getInstance().getMasterLocations().size() == 0) {
        log.info("No masters running. Not attempting safe unload of tserver.");
        return;
    }
    final Instance instance = context.getInstance();
    final String zTServerRoot = getTServersZkPath(instance);
    final ZooCache zc = new ZooCacheFactory().getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
    for (String server : servers) {
        for (int port : context.getConfiguration().getPort(Property.TSERV_CLIENTPORT)) {
            HostAndPort address = AddressUtil.parseAddress(server, port);
            final String finalServer = qualifyWithZooKeeperSessionId(zTServerRoot, zc, address.toString());
            log.info("Stopping server {}", finalServer);
            MasterClient.executeVoid(context, new ClientExec<MasterClientService.Client>() {

                @Override
                public void execute(MasterClientService.Client client) throws Exception {
                    client.shutdownTabletServer(Tracer.traceInfo(), context.rpcCreds(), finalServer, force);
                }
            });
        }
    }
}
Also used : HostAndPort(org.apache.accumulo.core.util.HostAndPort) ZooCacheFactory(org.apache.accumulo.fate.zookeeper.ZooCacheFactory) Instance(org.apache.accumulo.core.client.Instance) MasterClientService(org.apache.accumulo.core.master.thrift.MasterClientService) MasterClient(org.apache.accumulo.core.client.impl.MasterClient) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Example 20 with ZooCache

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

the class ListInstances method listInstances.

static synchronized void listInstances(String keepers, boolean printAll, boolean printErrors) {
    errors = 0;
    System.out.println("INFO : Using ZooKeepers " + keepers);
    ZooReader rdr = new ZooReader(keepers, ZOOKEEPER_TIMER_MILLIS);
    ZooCache cache = new ZooCache(keepers, ZOOKEEPER_TIMER_MILLIS);
    TreeMap<String, UUID> instanceNames = getInstanceNames(rdr, printErrors);
    System.out.println();
    printHeader();
    for (Entry<String, UUID> entry : instanceNames.entrySet()) {
        printInstanceInfo(cache, entry.getKey(), entry.getValue(), printErrors);
    }
    TreeSet<UUID> instancedIds = getInstanceIDs(rdr, printErrors);
    instancedIds.removeAll(instanceNames.values());
    if (printAll) {
        for (UUID uuid : instancedIds) {
            printInstanceInfo(cache, null, uuid, printErrors);
        }
    } else if (instancedIds.size() > 0) {
        System.out.println();
        System.out.println("INFO : " + instancedIds.size() + " unamed instances were not printed, run with --print-all to see all instances");
    } else {
        System.out.println();
    }
    if (!printErrors && errors > 0) {
        System.err.println("WARN : There were " + errors + " errors, run with --print-errors to see more info");
    }
}
Also used : ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) UUID(java.util.UUID) 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