Search in sources :

Example 6 with ZooLock

use of org.apache.accumulo.server.zookeeper.ZooLock in project accumulo by apache.

the class TabletServer method announceExistence.

private void announceExistence() {
    IZooReaderWriter zoo = ZooReaderWriter.getInstance();
    try {
        String zPath = ZooUtil.getRoot(getInstance()) + Constants.ZTSERVERS + "/" + getClientAddressString();
        try {
            zoo.putPersistentData(zPath, new byte[] {}, NodeExistsPolicy.SKIP);
        } catch (KeeperException e) {
            if (KeeperException.Code.NOAUTH == e.code()) {
                log.error("Failed to write to ZooKeeper. Ensure that accumulo-site.xml, specifically instance.secret, is consistent.");
            }
            throw e;
        }
        tabletServerLock = new ZooLock(zPath);
        LockWatcher lw = new LockWatcher() {

            @Override
            public void lostLock(final LockLossReason reason) {
                Halt.halt(serverStopRequested ? 0 : 1, new Runnable() {

                    @Override
                    public void run() {
                        if (!serverStopRequested)
                            log.error("Lost tablet server lock (reason = {}), exiting.", reason);
                        gcLogger.logGCInfo(getConfiguration());
                    }
                });
            }

            @Override
            public void unableToMonitorLockNode(final Throwable e) {
                Halt.halt(1, new Runnable() {

                    @Override
                    public void run() {
                        log.error("Lost ability to monitor tablet server lock, exiting.", e);
                    }
                });
            }
        };
        byte[] lockContent = new ServerServices(getClientAddressString(), Service.TSERV_CLIENT).toString().getBytes(UTF_8);
        for (int i = 0; i < 120 / 5; i++) {
            zoo.putPersistentData(zPath, new byte[0], NodeExistsPolicy.SKIP);
            if (tabletServerLock.tryLock(lw, lockContent)) {
                log.debug("Obtained tablet server lock {}", tabletServerLock.getLockPath());
                lockID = tabletServerLock.getLockID().serialize(ZooUtil.getRoot(getInstance()) + Constants.ZTSERVERS + "/");
                return;
            }
            log.info("Waiting for tablet server lock");
            sleepUninterruptibly(5, TimeUnit.SECONDS);
        }
        String msg = "Too many retries, exiting.";
        log.info(msg);
        throw new RuntimeException(msg);
    } catch (Exception e) {
        log.info("Could not obtain tablet server lock, exiting.", e);
        throw new RuntimeException(e);
    }
}
Also used : ServerServices(org.apache.accumulo.core.util.ServerServices) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) IterationInterruptedException(org.apache.accumulo.core.iterators.IterationInterruptedException) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) WalMarkerException(org.apache.accumulo.server.log.WalStateManager.WalMarkerException) ConstraintViolationException(org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) KeeperException(org.apache.zookeeper.KeeperException) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) CancellationException(java.util.concurrent.CancellationException) DistributedStoreException(org.apache.accumulo.server.master.state.DistributedStoreException) TException(org.apache.thrift.TException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) BadLocationStateException(org.apache.accumulo.server.master.state.TabletLocationState.BadLocationStateException) TimeoutException(java.util.concurrent.TimeoutException) TabletClosedException(org.apache.accumulo.tserver.tablet.TabletClosedException) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) LockWatcher(org.apache.accumulo.fate.zookeeper.ZooLock.LockWatcher) LoggingRunnable(org.apache.accumulo.fate.util.LoggingRunnable) LockLossReason(org.apache.accumulo.fate.zookeeper.ZooLock.LockLossReason) KeeperException(org.apache.zookeeper.KeeperException) ZooLock(org.apache.accumulo.server.zookeeper.ZooLock)

Aggregations

ZooLock (org.apache.accumulo.server.zookeeper.ZooLock)6 LockLossReason (org.apache.accumulo.fate.zookeeper.ZooLock.LockLossReason)4 LockWatcher (org.apache.accumulo.fate.zookeeper.ZooLock.LockWatcher)4 ServerServices (org.apache.accumulo.core.util.ServerServices)3 Instance (org.apache.accumulo.core.client.Instance)2 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)2 IZooReaderWriter (org.apache.accumulo.fate.zookeeper.IZooReaderWriter)2 AccumuloServerContext (org.apache.accumulo.server.AccumuloServerContext)2 HdfsZooInstance (org.apache.accumulo.server.client.HdfsZooInstance)2 ServerConfigurationFactory (org.apache.accumulo.server.conf.ServerConfigurationFactory)2 ZooReaderWriter (org.apache.accumulo.server.zookeeper.ZooReaderWriter)2 TException (org.apache.thrift.TException)2 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 Random (java.util.Random)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1