Examples of AvatarZooKeeperClient


Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

    long ssid = -1;
    int maxTries = conf.getInt("dfs.avatarnode.sync.ssidtxid.retries", 3);
    // Whether or not to verify the sessionid after writing it to ZK.
    int tries = 0;
    while (tries < maxTries) {
      AvatarZooKeeperClient zk = new AvatarZooKeeperClient(conf, null);
      try {
        ssid = now();
        zk.registerPrimarySsId(getClusterAddress(conf), ssid);
        // Be extra careful and verify the data was synced to zk.
        Long ssIdInZk = zk.getPrimarySsId(getClusterAddress(conf));
        if (ssid != ssIdInZk) {
          throw new IOException("Session Id in the NameNode : " + ssid +
              " does not match the session Id in Zookeeper : " + ssIdInZk);
        }
        break;
      } catch(Exception e) {
        if (tries == maxTries - 1 ) {
          throw new IOException(e);
        }
      } finally {
        try {
          zk.shutdown();
        } catch (InterruptedException ie) {
          if (tries == maxTries - 1) {
            throw new IOException(ie);
          }
        }
View Full Code Here

Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

    ZookeeperTxId zkTxid = new ZookeeperTxId(this.sessionId, lastTxid,
        totalBlocks);
    int maxTries = startupConf.getInt("dfs.avatarnode.sync.ssidtxid.retries", 3);
    int tries = 0;
    while (true) {
      AvatarZooKeeperClient zk = new AvatarZooKeeperClient(confg, null);
      try {
        zk.registerLastTxId(getClusterAddress(this.startupConf), zkTxid);
        return;
      } catch (Exception e) {
        if (tries > maxTries) {
          throw new IOException(e);
        } else {
          tries++;
          LOG.warn("Error syncing last txid to zk, retrying ....", e);
          try {
            Thread.sleep(5000);
          } catch (InterruptedException ie) {
            throw new IOException("writeLastTxidToZookeeper() interrupted", ie);
          }
        }
      } finally {
        try {
          zk.shutdown();
        } catch (InterruptedException ie) {
          throw new IOException(ie);
        }
      }
    }
View Full Code Here

Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

    }
  }

  private ZookeeperTxId getLastTransactionId() throws IOException {
    try {
      AvatarZooKeeperClient zk = new AvatarZooKeeperClient(confg, null);
      try {
        // Gather session id and transaction id data.
        String address = getClusterAddress(this.startupConf);
        long sessionId = zk.getPrimarySsId(address);
        ZookeeperTxId zkTxId = zk.getPrimaryLastTxId(address);
        if (sessionId != zkTxId.getSessionId()) {
          throw new IOException("Session Id in the ssid node : " + sessionId
              + " does not match the session Id in the txid node : "
              + zkTxId.getSessionId());
        }
        return zkTxId;
      } finally {
        zk.shutdown();
      }
    } catch (Exception e) {
      throw new IOException(e);
    }
  }
View Full Code Here

Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

  private void registerAsPrimaryToZK() throws IOException {
    // Register client port address.
    String address = getClusterAddress(startupConf);
    String realAddress = getClusterAddress(confg);
    AvatarZooKeeperClient zk = new AvatarZooKeeperClient(confg, null);
    try {
      zk.registerPrimary(address, realAddress, true);

      // Register dn protocol address
      registerAddressToZK(zk, "dfs.namenode.dn-address");

      // Register http address
      registerAddressToZK(zk, "dfs.http.address");

      // Register rpc address
      registerAddressToZK(zk, AvatarNode.DFS_NAMENODE_RPC_ADDRESS_KEY);
    } finally {
      try {
        zk.shutdown();
      } catch (InterruptedException e) {
        throw new IOException("Could not shutdown zk client", e);
      }
    }
  }
View Full Code Here

Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

    String fsname = defaultAddr.getHostName() + ":" + defaultAddr.getPort();
    InetSocketAddress actualAddr = NameNode.getClientProtocolAddress(conf);
    String actualName = actualAddr.getHostName() + ":" + actualAddr.getPort();


    AvatarZooKeeperClient zk = new AvatarZooKeeperClient(conf, null);
    boolean zkRegistryMatch = true;
    boolean primaryPresent = false;
    String errorMsg = null;
    try {
      Stat stat = new Stat();
      String zkRegistry = zk.getPrimaryAvatarAddress(fsname, stat, false);
      if (zkRegistry == null) {
        // The registry is empty. Usually this means failover is in progress
        // we need to manually fix it before starting primary
        errorMsg = "A zNode that indicates the primary is empty. "
            + "AvatarNode can only be started as primary if it "
            + "is registered as primary with ZooKeeper";
        zkRegistryMatch = false;
      } else {
        primaryPresent = true;
        if (!zkRegistry.equalsIgnoreCase(actualName)) {
          zkRegistryMatch = false;
          errorMsg = "Registration information in ZooKeeper doesn't "
              + "match the address of this node. AvatarNode can "
              + "only be started as primary if it is registered as "
              + "primary with ZooKeeper. zkRegistry = " + zkRegistry
              + ", actual name = " + actualName;
        }
      }
      if (!startInfo.isStandby) {
        isPrimaryAlive(zkRegistry);
      }
    } catch (Exception e) {
      LOG.error("Got Exception reading primary node registration "
          + "from ZooKeeper. Aborting the start", e);
      zkRegistryMatch = false;

    } finally {
      try {
        zk.shutdown();
      } catch (InterruptedException e) {
        LOG.error("Error shutting down ZooKeeper client", e);
      }
    }
    if (!zkRegistryMatch && !startInfo.isStandby) {
View Full Code Here

Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

 
  private boolean zkIsEmpty() throws Exception {
      InetSocketAddress defaultAddr = NameNode.getClientProtocolAddress(startupConf);
      String fsname = defaultAddr.getHostName() + ":" + defaultAddr.getPort();

      AvatarZooKeeperClient zk =
        new AvatarZooKeeperClient(this.confg, null);
      try {
        Stat stat = new Stat();
        String zkRegistry = zk.getPrimaryAvatarAddress(fsname, stat, false);
        return zkRegistry == null;
      } catch (Exception e) {
        LOG.error("Got Exception reading primary node registration " +
            "from ZooKeeper.", e);
        throw e;
      } finally {
        try {
          zk.shutdown();
        } catch (InterruptedException e) {
          LOG.error("Error shutting down ZooKeeper client", e);
        }
      }
  }
View Full Code Here

Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

      this.nameAddr2 = nameAddr2;
      this.avatarAddr1 = avatarAddr1;
      this.avatarAddr2 = avatarAddr2;
      this.defaultAddr = defaultAddr.getHostName() + ":" + defaultAddr.getPort();
      this.nameserviceId = nameserviceId;
      zkClient = new AvatarZooKeeperClient(getConf(), null);
      this.nsRegistration = new DatanodeRegistration(getMachineName());
    }
View Full Code Here

Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

   * Sets the backing configuration source
   */
  public void setConfSource(Configurable src) {
    validateConfigFile(src.getConf());
    confSrc = src;
    zkClient = new AvatarZooKeeperClient(confSrc.getConf(), null, true);
  }
View Full Code Here

Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

      this.nameAddr2 = nameAddr2;
      this.avatarAddr1 = avatarAddr1;
      this.avatarAddr2 = avatarAddr2;
      this.defaultAddr = defaultAddr;
      this.nameserviceId = nameserviceId;
      zkClient = new AvatarZooKeeperClient(getConf(), null);
      this.nsRegistration = new DatanodeRegistration(getMachineName());
    }
View Full Code Here

Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

   * @return the session id and last transaction id information from zookeeper
   * @throws IOException
   */
  static ZookeeperTxId checkZooKeeperBeforeFailover(Configuration startupConf,
      Configuration confg, boolean noverification) throws IOException {
    AvatarZooKeeperClient zk = null;
    String fsname = startupConf.get(NameNode.DFS_NAMENODE_RPC_ADDRESS_KEY);
   
    int maxTries = startupConf.getInt("dfs.avatarnode.zk.retries", 3);
    Exception lastException = null;
    for (int i = 0; i < maxTries; i++) {
      try {
        zk = new AvatarZooKeeperClient(confg, null, false);
        LOG.info("Failover: Checking if the primary is empty");
        String zkRegistry = zk.getPrimaryAvatarAddress(fsname, new Stat(),
            false, i > 0);
        if (zkRegistry != null) {
          throw new IOException(
              "Can't switch the AvatarNode to primary since "
                  + "zookeeper record is not clean. Either use shutdownAvatar to kill "
                  + "the current primary and clean the ZooKeeper entry, "
                  + "or clear out the ZooKeeper entry if the primary is dead");
        }

        if (noverification) {
          return null;
        }

        LOG.info("Failover: Obtaining last transaction id from ZK");
        String address = startupConf.get(NameNode.DFS_NAMENODE_RPC_ADDRESS_KEY);
        long sessionId = zk.getPrimarySsId(address, i > 0);
        ZookeeperTxId zkTxId = zk.getPrimaryLastTxId(address, i > 0);
        if (sessionId != zkTxId.getSessionId()) {
          throw new IOException("Session Id in the ssid node : " + sessionId
              + " does not match the session Id in the txid node : "
              + zkTxId.getSessionId());
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.