Search in sources :

Example 1 with ZooCacheFactory

use of org.apache.accumulo.fate.zookeeper.ZooCacheFactory 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 2 with ZooCacheFactory

use of org.apache.accumulo.fate.zookeeper.ZooCacheFactory 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 3 with ZooCacheFactory

use of org.apache.accumulo.fate.zookeeper.ZooCacheFactory 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 4 with ZooCacheFactory

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

the class ZooKeeperInstanceTest method testAllZooKeepersAreUsed.

@Test
public void testAllZooKeepersAreUsed() {
    final String zookeepers = "zk1,zk2,zk3", instanceName = "accumulo";
    ZooCacheFactory factory = createMock(ZooCacheFactory.class);
    EasyMock.reset(zc);
    expect(factory.getZooCache(zookeepers, 30000)).andReturn(zc).anyTimes();
    expect(zc.get(Constants.ZROOT + Constants.ZINSTANCES + "/" + instanceName)).andReturn(IID_STRING.getBytes(UTF_8));
    expect(zc.get(Constants.ZROOT + "/" + IID_STRING)).andReturn("yup".getBytes());
    replay(zc, factory);
    ClientConfiguration cfg = ClientConfiguration.loadDefault().withInstance(instanceName).withZkHosts(zookeepers);
    ZooKeeperInstance zki = new ZooKeeperInstance(cfg, factory);
    assertEquals(zookeepers, zki.getZooKeepers());
    assertEquals(instanceName, zki.getInstanceName());
}
Also used : ZooCacheFactory(org.apache.accumulo.fate.zookeeper.ZooCacheFactory) Test(org.junit.Test)

Example 5 with ZooCacheFactory

use of org.apache.accumulo.fate.zookeeper.ZooCacheFactory 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)

Aggregations

ZooCacheFactory (org.apache.accumulo.fate.zookeeper.ZooCacheFactory)8 Instance (org.apache.accumulo.core.client.Instance)5 ZooCache (org.apache.accumulo.fate.zookeeper.ZooCache)5 ArrayList (java.util.ArrayList)3 ServerServices (org.apache.accumulo.core.util.ServerServices)2 TTransport (org.apache.thrift.transport.TTransport)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 ClientConfiguration (org.apache.accumulo.core.client.ClientConfiguration)1 Connector (org.apache.accumulo.core.client.Connector)1 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 TimedOutException (org.apache.accumulo.core.client.TimedOutException)1 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)1 ClientContext (org.apache.accumulo.core.client.impl.ClientContext)1 Credentials (org.apache.accumulo.core.client.impl.Credentials)1 MasterClient (org.apache.accumulo.core.client.impl.MasterClient)1