Examples of AvatarZooKeeperClient


Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

   * @return the session id for the new node after failover
   * @throws IOException
   */
  static long writeToZooKeeperAfterFailover(Configuration startupConf,
      Configuration confg) throws IOException {
    AvatarZooKeeperClient zk = null;
    // Register client port address.
    String address = startupConf.get(NameNode.DFS_NAMENODE_RPC_ADDRESS_KEY);
    String realAddress = confg.get(NameNode.DFS_NAMENODE_RPC_ADDRESS_KEY);

    int maxTries = startupConf.getInt("dfs.avatarnode.zk.retries", 3);
    for (int i = 0; i < maxTries; i++) {
      try {
        zk = new AvatarZooKeeperClient(confg, null, false);
        LOG.info("Failover: Registering to ZK as primary");
        final boolean toOverwrite = true;
        zk.registerPrimary(address, realAddress, toOverwrite);
        registerClientProtocolAddress(zk, startupConf, confg, toOverwrite);
        registerDnProtocolAddress(zk, startupConf, confg, toOverwrite);
        registerHttpAddress(zk, startupConf, confg, toOverwrite);
        LOG.info("Failover: Writting session id to ZK");
        return writeSessionIdToZK(startupConf, zk);
View Full Code Here

Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

   * Writes the last transaction id of the primary avatarnode to zookeeper.
   */
  static void writeLastTxidToZookeeper(long lastTxid, long totalBlocks,
      long totalInodes, long ssid, Configuration startupConf,
      Configuration confg) throws IOException {
    AvatarZooKeeperClient zk = null;
    LOG.info("Writing lastTxId: " + lastTxid + ", total blocks: " + totalBlocks
        + ", total inodes: " + totalInodes);
    if (lastTxid < 0) {
      LOG.warn("Invalid last transaction id : " + lastTxid
          + " skipping write to zookeeper.");
      return;
    }
    ZookeeperTxId zkTxid = new ZookeeperTxId(ssid, lastTxid, totalBlocks,
        totalInodes);
    int maxTries = startupConf.getInt("dfs.avatarnode.zk.retries", 3);
    for (int i = 0; i < maxTries; i++) {
      try {
        zk = new AvatarZooKeeperClient(confg, null, false);
        zk.registerLastTxId(startupConf.get(NameNode.DFS_NAMENODE_RPC_ADDRESS_KEY), zkTxid);
        return;
      } catch (Exception e) {
        LOG.error("Got Exception when syncing last txid to zk. Will retry...",
            e);
      } finally {
View Full Code Here

Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

   *
   * @return the session id that it wrote to ZooKeeper
   * @throws IOException
   */
  static long writeSessionIdToZK(Configuration conf) throws IOException {
    AvatarZooKeeperClient zk = null;
    long ssid = -1;
    int maxTries = conf.getInt("dfs.avatarnode.zk.retries", 3);
    boolean mismatch = false;
    Long ssIdInZk = -1L;

    for (int i = 0; i < maxTries; i++) {
      try {
        zk = new AvatarZooKeeperClient(conf, null, false);
        ssid = writeSessionIdToZK(conf, zk);
        return ssid;
      } catch (Exception e) {
        LOG.error("Got Exception when writing session id to zk. Will retry...",
            e);
View Full Code Here

Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

  /**
   * Obtain the registration of the primary from zk.
   */
  static String getPrimaryRegistration(Configuration startupConf,
      Configuration conf, String fsname) throws IOException {
    AvatarZooKeeperClient zk = null;
    int maxTries = startupConf.getInt("dfs.avatarnode.zk.retries", 3);
    for (int i = 0; i < maxTries; i++) {
      try {
        zk = new AvatarZooKeeperClient(conf, null, false);
        String zkRegistry = zk.getPrimaryAvatarAddress(fsname, new Stat(),
            false);
        return zkRegistry;
      } catch (Exception e) {
        LOG.error(
            "Got Exception when reading primary registration. Will retry...", e);
View Full Code Here

Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

  public static void updateZooKeeper(Configuration originalConf, Configuration conf,
      boolean toOverwrite, String serviceName, String primaryInstance) throws IOException {
    String connection = conf.get(FSConstants.FS_HA_ZOOKEEPER_QUORUM);
    if (connection == null)
      return;
    AvatarZooKeeperClient zk = new AvatarZooKeeperClient(conf, null);
    if (registerClientProtocolAddress(zk, originalConf, conf, toOverwrite)) {
      return;
    }
    registerDnProtocolAddress(zk, originalConf, conf, toOverwrite);
    registerHttpAddress(zk, originalConf, conf, toOverwrite);
    for (ZookeeperKey key : ZookeeperKey.values()) {
      zk.registerPrimary(getZnodeName(conf, serviceName, Avatar.ACTIVE, key),
          key.getIpPortString(conf), true);
    }
    if(primaryInstance.equalsIgnoreCase(StartupOption.NODEZERO.getName())){
      primaryInstance = StartupOption.NODEONE.getName();
    } else {
      primaryInstance = StartupOption.NODEZERO.getName();
    }
    Configuration tempConf = AvatarZKShell.updateConf(primaryInstance, originalConf);
    for (ZookeeperKey key : ZookeeperKey.values()) {
      zk.registerPrimary(getZnodeName(tempConf, serviceName, Avatar.STANDBY, key),
          key.getIpPortString(tempConf), true);
    }
  }
View Full Code Here

Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

      String serviceName) throws IOException {
    String connection = conf.get(FSConstants.FS_HA_ZOOKEEPER_QUORUM);
    if (connection == null) {
      return;
    }
    AvatarZooKeeperClient zk = new AvatarZooKeeperClient(conf, null);

    // Clear NameNode address in ZK
    InetSocketAddress defaultAddr;
    String[] aliases;

    defaultAddr = NameNode.getClientProtocolAddress(originalConf);
    String defaultName = defaultAddr.getHostName() + ":"
        + defaultAddr.getPort();
    LOG.info("Clear Client Address information in ZooKeeper: " + defaultName);
    zk.clearPrimary(defaultName);

    aliases = conf.getStrings(FSConstants.FS_NAMENODE_ALIASES);
    if (aliases != null) {
      for (String alias : aliases) {
        zk.clearPrimary(alias);
      }
    }
   
   
    LOG.info("Clear Service Address information in ZooKeeper");
    defaultAddr = NameNode.getDNProtocolAddress(originalConf);
    if (defaultAddr != null) {
      String defaultServiceName = defaultAddr.getHostName() + ":"
          + defaultAddr.getPort();
      zk.clearPrimary(defaultServiceName);
    }
   
    aliases = conf.getStrings(FSConstants.DFS_NAMENODE_DN_ALIASES);
    if (aliases != null) {
      for (String alias : aliases) {
        zk.clearPrimary(alias);
      }
    }
   
   
    LOG.info("Clear Http Address information in ZooKeeper");
    // Clear http address in ZK
    // Stolen from NameNode so we have the same code in both places
    defaultAddr = NetUtils.createSocketAddr(originalConf
        .get(FSConstants.DFS_NAMENODE_HTTP_ADDRESS_KEY));
    String defaultHttpAddress = defaultAddr.getHostName() + ":"
        + defaultAddr.getPort();
    zk.clearPrimary(defaultHttpAddress);
   
    aliases = conf.getStrings(FSConstants.DFS_HTTP_ALIASES);
    if (aliases != null) {
      for (String alias : aliases) {
        zk.clearPrimary(alias);
      }
    }

    for(Avatar avatar : Avatar.avatars) {
      for (ZookeeperKey key : ZookeeperKey.values()) {
        zk.clearPrimary(getZnodeName(conf, serviceName, avatar, key));
      }
    }
  }
View Full Code Here

Examples of org.apache.hadoop.hdfs.AvatarZooKeeperClient

      String serviceName, PrintStream outputStream) throws IOException, KeeperException,
      InterruptedException {
    String connection = conf.get(FSConstants.FS_HA_ZOOKEEPER_QUORUM);
    if (connection == null)
      return;
    AvatarZooKeeperClient zk = new AvatarZooKeeperClient(conf, null);
    outputStream.println("ZooKeeper entries:");

    // client protocol
    InetSocketAddress defaultAddr = NameNode.getClientProtocolAddress(originalConf);
    String defaultName = defaultAddr.getHostName() + ":" + defaultAddr.getPort();
    outputStream.println("Default name is " + defaultName);
    String registration = zk.getPrimaryAvatarAddress(defaultName, new Stat(), false);
    outputStream.println("Primary node according to ZooKeeper: " + registration);

    // datanode protocol
    defaultAddr = NameNode.getDNProtocolAddress(originalConf);
    defaultName = defaultAddr.getHostName() + ":" + defaultAddr.getPort();
    registration = zk.getPrimaryAvatarAddress(defaultName, new Stat(), false);
    outputStream.println("Primary node DN protocol     : " + registration);

    // http address
    defaultAddr = NetUtils.createSocketAddr(originalConf.get("dfs.http.address"));
    defaultName = defaultAddr.getHostName() + ":" + defaultAddr.getPort();
    registration = zk.getPrimaryAvatarAddress(defaultName, new Stat(), false);
    outputStream.println("Primary node http address    : " + registration);

    for (Avatar anAvatar : Avatar.avatars) {
      outputStream.println(anAvatar + " entries: ");
      for (ZookeeperKey key : ZookeeperKey.values()) {
        String keyInZookeeper = getZnodeName(conf, serviceName, anAvatar, key);
        outputStream.println(keyInZookeeper + " : "
            + zk.getPrimaryAvatarAddress(keyInZookeeper, new Stat(), false));
      }
    }
  }
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.