Package org.apache.accumulo.core.zookeeper

Examples of org.apache.accumulo.core.zookeeper.ZooLock$AsyncLockWatcher


        Halt.halt("GC lock in zookeeper lost (reason = " + reason + "), exiting!");
      }
    };
   
    while (true) {
      lock = new ZooLock(path);
      if (lock.tryLock(lockWatcher, new ServerServices(address, Service.GC_CLIENT).toString().getBytes())) {
        break;
      }
      UtilWaitThread.sleep(1000);
    }
View Full Code Here


      final String path = ZooUtil.getRoot(instance) + Constants.ZTSERVERS;
      for (String server : getZooCache().getChildren(path)) {
        // See if we have an async lock in place?
        TServerInfo info = current.get(server);
        TServerLockWatcher watcher;
        ZooLock lock;
        final String lockPath = path + "/" + server;
        if (info != null) {
          // yep: get out the lock/watcher so we can check on it
          watcher = info.watcher;
          lock = info.lock;
        } else {
          // nope: create a new lock and watcher
          lock = new ZooLock(lockPath);
          watcher = new TServerLockWatcher();
          lock.lockAsync(watcher, "master".getBytes());
        }
        TServerInstance instance = null;
        // Did we win the lock yet?
        if (!lock.isLocked() && !watcher.gotLock && watcher.failureException == null) {
          // Nope... there's a server out there: is this is a new server?
          if (info == null) {
            // Yep: hold onto the information about this server
            byte[] lockData = ZooLock.getLockData(lockPath);
            String lockString = new String(lockData == null ? new byte[] {} : lockData);
            if (lockString.length() > 0 && !lockString.equals("master")) {
              ServerServices services = new ServerServices(new String(lockData));
              InetSocketAddress client = services.getAddress(ServerServices.Service.TSERV_CLIENT);
              InetSocketAddress addr = AddressUtil.parseAddress(server, Property.TSERV_CLIENTPORT);
              TServerConnection conn = new TServerConnection(addr);
              instance = new TServerInstance(client, lock.getSessionId());
              info = new TServerInfo(lock, instance, conn, watcher);
              current.put(server, info);
              updates.add(instance);
            } else {
              lock.tryToCancelAsyncLockOrUnlock();
            }
          }
        } else {
          // Yes... there is no server here any more
          lock.tryToCancelAsyncLockOrUnlock();
          if (info != null) {
            doomed.add(info.instance);
            current.remove(server);
            info.cleanup();
          }
View Full Code Here

    try {
      String zPath = ZooUtil.getRoot(HdfsZooInstance.getInstance()) + Constants.ZTSERVERS + "/" + getClientAddressString();
     
      ZooUtil.putPersistentData(zPath, new byte[] {}, NodeExistsPolicy.SKIP);
     
      tabletServerLock = new ZooLock(zPath);
     
      LockWatcher lw = new LockWatcher() {
       
        @Override
        public void lostLock(final LockLossReason reason) {
View Full Code Here

    final long waitTime = AccumuloConfiguration.getSystemConfiguration().getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT);
    final String masterClientAddress = hostname + ":" + AccumuloConfiguration.getSystemConfiguration().getPort(Property.MASTER_CLIENTPORT);
   
    boolean locked = false;
    while (System.currentTimeMillis() - current < waitTime) {
      masterLock = new ZooLock(zMasterLoc);
      if (masterLock.tryLock(masterLockWatcher, masterClientAddress.getBytes())) {
        locked = true;
        break;
      }
      UtilWaitThread.sleep(1000);
    }
    if (!locked) {
      log.info("Failed to get master lock, even after waiting for session timeout, becoming back-up server");
      while (true) {
        masterLock = new ZooLock(zMasterLoc);
        if (masterLock.tryLock(masterLockWatcher, masterClientAddress.getBytes())) {
          break;
        }
        UtilWaitThread.sleep(1000);
      }
View Full Code Here

    try {
      String zPath = ZooUtil.getRoot(HdfsZooInstance.getInstance()) + Constants.ZTSERVERS + "/" + getClientAddressString();
     
      ZooUtil.putPersistentData(zPath, new byte[] {}, NodeExistsPolicy.SKIP);
     
      tabletServerLock = new ZooLock(zPath);
     
      LockWatcher lw = new LockWatcher() {
       
        @Override
        public void lostLock(final LockLossReason reason) {
View Full Code Here

 
  @Override
  public void run() throws Exception {
    String zPath = ZooUtil.getRoot(HdfsZooInstance.getInstance()) + "/testLock";
    ZooSession.getSession().create(zPath, "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    ZooLock zl = new ZooLock(zPath);
    boolean gotLock = zl.tryLock(new LockWatcher() {
     
      @Override
      public void lostLock(LockLossReason reason) {
        System.exit(-1);
       
View Full Code Here

        Halt.halt("GC lock in zookeeper lost (reason = " + reason + "), exiting!");
      }
    };
   
    while (true) {
      lock = new ZooLock(path);
      if (lock.tryLock(lockWatcher, new ServerServices(address, Service.GC_CLIENT).toString().getBytes())) {
        break;
      }
      UtilWaitThread.sleep(1000);
    }
View Full Code Here

      final String path = ZooUtil.getRoot(instance) + Constants.ZTSERVERS;
      for (String server : getZooCache().getChildren(path)) {
        // See if we have an async lock in place?
        TServerInfo info = current.get(server);
        TServerLockWatcher watcher;
        ZooLock lock;
        final String lockPath = path + "/" + server;
        if (info != null) {
          // yep: get out the lock/watcher so we can check on it
          watcher = info.watcher;
          lock = info.lock;
        } else {
          // nope: create a new lock and watcher
          lock = new ZooLock(lockPath);
          watcher = new TServerLockWatcher();
          lock.lockAsync(watcher, "master".getBytes());
        }
        TServerInstance instance = null;
        // Did we win the lock yet?
        if (!lock.isLocked() && !watcher.gotLock && watcher.failureException == null) {
          // Nope... there's a server out there: is this is a new server?
          if (info == null) {
            // Yep: hold onto the information about this server
            byte[] lockData = ZooLock.getLockData(lockPath);
            String lockString = new String(lockData == null ? new byte[] {} : lockData);
            if (lockString.length() > 0 && !lockString.equals("master")) {
              ServerServices services = new ServerServices(new String(lockData));
              InetSocketAddress client = services.getAddress(ServerServices.Service.TSERV_CLIENT);
              InetSocketAddress addr = AddressUtil.parseAddress(server, Property.TSERV_CLIENTPORT);
              TServerConnection conn = new TServerConnection(addr);
              instance = new TServerInstance(client, lock.getSessionId());
              info = new TServerInfo(lock, instance, conn, watcher);
              current.put(server, info);
              updates.add(instance);
            } else {
              lock.tryToCancelAsyncLockOrUnlock();
            }
          }
        } else {
          // Yes... there is no server here any more
          lock.tryToCancelAsyncLockOrUnlock();
          if (info != null) {
            doomed.add(info.instance);
            current.remove(server);
            info.cleanup();
          }
View Full Code Here

    final long waitTime = AccumuloConfiguration.getSystemConfiguration().getTimeInMillis(Property.INSTANCE_ZK_TIMEOUT);
    final String masterClientAddress = hostname + ":" + AccumuloConfiguration.getSystemConfiguration().getPort(Property.MASTER_CLIENTPORT);
   
    boolean locked = false;
    while (System.currentTimeMillis() - current < waitTime) {
      masterLock = new ZooLock(zMasterLoc);
      if (masterLock.tryLock(masterLockWatcher, masterClientAddress.getBytes())) {
        locked = true;
        break;
      }
      UtilWaitThread.sleep(1000);
    }
    if (!locked) {
      log.info("Failed to get master lock, even after waiting for session timeout, becoming back-up server");
      while (true) {
        masterLock = new ZooLock(zMasterLoc);
        if (masterLock.tryLock(masterLockWatcher, masterClientAddress.getBytes())) {
          break;
        }
        UtilWaitThread.sleep(1000);
      }
View Full Code Here

TOP

Related Classes of org.apache.accumulo.core.zookeeper.ZooLock$AsyncLockWatcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.