Search in sources :

Example 1 with ServerServices

use of org.apache.accumulo.core.util.ServerServices in project accumulo by apache.

the class ZombieTServer method main.

public static void main(String[] args) throws Exception {
    Random random = new Random(System.currentTimeMillis() % 1000);
    int port = random.nextInt(30000) + 2000;
    Instance instance = HdfsZooInstance.getInstance();
    AccumuloServerContext context = new AccumuloServerContext(instance, new ServerConfigurationFactory(instance));
    TransactionWatcher watcher = new TransactionWatcher();
    final ThriftClientHandler tch = new ThriftClientHandler(context, watcher);
    Processor<Iface> processor = new Processor<>(tch);
    ServerAddress serverPort = TServerUtils.startTServer(context.getConfiguration(), ThriftServerType.CUSTOM_HS_HA, processor, "ZombieTServer", "walking dead", 2, 1, 1000, 10 * 1024 * 1024, null, null, -1, HostAndPort.fromParts("0.0.0.0", port));
    String addressString = serverPort.address.toString();
    String zPath = ZooUtil.getRoot(context.getInstance()) + Constants.ZTSERVERS + "/" + addressString;
    ZooReaderWriter zoo = ZooReaderWriter.getInstance();
    zoo.putPersistentData(zPath, new byte[] {}, NodeExistsPolicy.SKIP);
    ZooLock zlock = new ZooLock(zPath);
    LockWatcher lw = new LockWatcher() {

        @Override
        public void lostLock(final LockLossReason reason) {
            try {
                tch.halt(Tracer.traceInfo(), null, null);
            } catch (Exception ex) {
                log.error("Exception", ex);
                System.exit(1);
            }
        }

        @Override
        public void unableToMonitorLockNode(Throwable e) {
            try {
                tch.halt(Tracer.traceInfo(), null, null);
            } catch (Exception ex) {
                log.error("Exception", ex);
                System.exit(1);
            }
        }
    };
    byte[] lockContent = new ServerServices(addressString, Service.TSERV_CLIENT).toString().getBytes(UTF_8);
    if (zlock.tryLock(lw, lockContent)) {
        log.debug("Obtained tablet server lock {}", zlock.getLockPath());
    }
    // modify metadata
    synchronized (tch) {
        while (!tch.halted) {
            tch.wait();
        }
    }
    System.exit(0);
}
Also used : AccumuloServerContext(org.apache.accumulo.server.AccumuloServerContext) Processor(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Processor) ServerServices(org.apache.accumulo.core.util.ServerServices) Instance(org.apache.accumulo.core.client.Instance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) ServerConfigurationFactory(org.apache.accumulo.server.conf.ServerConfigurationFactory) TException(org.apache.thrift.TException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) Iface(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Iface) TransactionWatcher(org.apache.accumulo.server.zookeeper.TransactionWatcher) Random(java.util.Random) LockWatcher(org.apache.accumulo.fate.zookeeper.ZooLock.LockWatcher) LockLossReason(org.apache.accumulo.fate.zookeeper.ZooLock.LockLossReason) ZooLock(org.apache.accumulo.server.zookeeper.ZooLock)

Example 2 with ServerServices

use of org.apache.accumulo.core.util.ServerServices in project accumulo by apache.

the class LiveTServerSet method checkServer.

private synchronized void checkServer(final Set<TServerInstance> updates, final Set<TServerInstance> doomed, final String path, final String zPath) throws TException, InterruptedException, KeeperException {
    TServerInfo info = current.get(zPath);
    final String lockPath = path + "/" + zPath;
    ZcStat stat = new ZcStat();
    byte[] lockData = ZooLock.getLockData(getZooCache(), lockPath, stat);
    if (lockData == null) {
        if (info != null) {
            doomed.add(info.instance);
            current.remove(zPath);
            currentInstances.remove(info.instance);
        }
        Long firstSeen = locklessServers.get(zPath);
        if (firstSeen == null) {
            locklessServers.put(zPath, System.currentTimeMillis());
        } else if (System.currentTimeMillis() - firstSeen > 10 * 60 * 1000) {
            deleteServerNode(path + "/" + zPath);
            locklessServers.remove(zPath);
        }
    } else {
        locklessServers.remove(zPath);
        ServerServices services = new ServerServices(new String(lockData, UTF_8));
        HostAndPort client = services.getAddress(ServerServices.Service.TSERV_CLIENT);
        TServerInstance instance = new TServerInstance(client, stat.getEphemeralOwner());
        if (info == null) {
            updates.add(instance);
            TServerInfo tServerInfo = new TServerInfo(instance, new TServerConnection(client));
            current.put(zPath, tServerInfo);
            currentInstances.put(instance, tServerInfo);
        } else if (!info.instance.equals(instance)) {
            doomed.add(info.instance);
            updates.add(instance);
            TServerInfo tServerInfo = new TServerInfo(instance, new TServerConnection(client));
            current.put(zPath, tServerInfo);
            currentInstances.remove(info.instance);
            currentInstances.put(instance, tServerInfo);
        }
    }
}
Also used : HostAndPort(org.apache.accumulo.core.util.HostAndPort) ZcStat(org.apache.accumulo.fate.zookeeper.ZooCache.ZcStat) ServerServices(org.apache.accumulo.core.util.ServerServices) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance)

Example 3 with ServerServices

use of org.apache.accumulo.core.util.ServerServices in project accumulo by apache.

the class Monitor method fetchGcStatus.

private static GCStatus fetchGcStatus() {
    GCStatus result = null;
    HostAndPort address = null;
    try {
        // Read the gc location from its lock
        ZooReaderWriter zk = ZooReaderWriter.getInstance();
        String path = ZooUtil.getRoot(instance) + Constants.ZGC_LOCK;
        List<String> locks = zk.getChildren(path, null);
        if (locks != null && locks.size() > 0) {
            Collections.sort(locks);
            address = new ServerServices(new String(zk.getData(path + "/" + locks.get(0), null), UTF_8)).getAddress(Service.GC_CLIENT);
            GCMonitorService.Client client = ThriftUtil.getClient(new GCMonitorService.Client.Factory(), address, new AccumuloServerContext(instance, config));
            try {
                result = client.getStatus(Tracer.traceInfo(), getContext().rpcCreds());
            } finally {
                ThriftUtil.returnClient(client);
            }
        }
    } catch (Exception ex) {
        log.warn("Unable to contact the garbage collector at " + address, ex);
    }
    return result;
}
Also used : HostAndPort(org.apache.accumulo.core.util.HostAndPort) ServerServices(org.apache.accumulo.core.util.ServerServices) AccumuloServerContext(org.apache.accumulo.server.AccumuloServerContext) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) GCStatus(org.apache.accumulo.core.gc.thrift.GCStatus) GCMonitorService(org.apache.accumulo.core.gc.thrift.GCMonitorService) MasterClient(org.apache.accumulo.core.client.impl.MasterClient) Client(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client) KeeperException(org.apache.zookeeper.KeeperException) UnknownHostException(java.net.UnknownHostException)

Example 4 with ServerServices

use of org.apache.accumulo.core.util.ServerServices in project accumulo by apache.

the class SimpleGarbageCollector method getZooLock.

private void getZooLock(HostAndPort addr) throws KeeperException, InterruptedException {
    String path = ZooUtil.getRoot(getInstance()) + Constants.ZGC_LOCK;
    LockWatcher lockWatcher = new LockWatcher() {

        @Override
        public void lostLock(LockLossReason reason) {
            Halt.halt("GC lock in zookeeper lost (reason = " + reason + "), exiting!", 1);
        }

        @Override
        public void unableToMonitorLockNode(final Throwable e) {
            // ACCUMULO-3651 Level changed to error and FATAL added to message for slf4j compatibility
            Halt.halt(-1, new Runnable() {

                @Override
                public void run() {
                    log.error("FATAL: No longer able to monitor lock node ", e);
                }
            });
        }
    };
    while (true) {
        lock = new ZooLock(path);
        if (lock.tryLock(lockWatcher, new ServerServices(addr.toString(), Service.GC_CLIENT).toString().getBytes())) {
            log.debug("Got GC ZooKeeper lock");
            return;
        }
        log.debug("Failed to get GC ZooKeeper lock, will retry");
        sleepUninterruptibly(1, TimeUnit.SECONDS);
    }
}
Also used : ServerServices(org.apache.accumulo.core.util.ServerServices) LockWatcher(org.apache.accumulo.fate.zookeeper.ZooLock.LockWatcher) LockLossReason(org.apache.accumulo.fate.zookeeper.ZooLock.LockLossReason) ZooLock(org.apache.accumulo.server.zookeeper.ZooLock)

Example 5 with ServerServices

use of org.apache.accumulo.core.util.ServerServices 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)

Aggregations

ServerServices (org.apache.accumulo.core.util.ServerServices)7 Instance (org.apache.accumulo.core.client.Instance)3 LockLossReason (org.apache.accumulo.fate.zookeeper.ZooLock.LockLossReason)3 LockWatcher (org.apache.accumulo.fate.zookeeper.ZooLock.LockWatcher)3 ZooLock (org.apache.accumulo.server.zookeeper.ZooLock)3 UnknownHostException (java.net.UnknownHostException)2 ArrayList (java.util.ArrayList)2 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)2 HostAndPort (org.apache.accumulo.core.util.HostAndPort)2 ZooCache (org.apache.accumulo.fate.zookeeper.ZooCache)2 ZooCacheFactory (org.apache.accumulo.fate.zookeeper.ZooCacheFactory)2 AccumuloServerContext (org.apache.accumulo.server.AccumuloServerContext)2 ZooReaderWriter (org.apache.accumulo.server.zookeeper.ZooReaderWriter)2 TException (org.apache.thrift.TException)2 TTransport (org.apache.thrift.transport.TTransport)2 IOException (java.io.IOException)1 Random (java.util.Random)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1