Package com.alibaba.wasp

Examples of com.alibaba.wasp.EntityGroupTransaction


  public static void createNodeOffline(ZooKeeperWatcher zkw,
      EntityGroupInfo entityGroup, ServerName serverName, final EventType event)
      throws KeeperException, KeeperException.NodeExistsException {
    LOG.debug(zkw.prefix("Creating unassigned node for "
        + entityGroup.getEncodedName() + " in OFFLINE state"));
    EntityGroupTransaction rt = EntityGroupTransaction.createEntityGroupTransition(event,
        entityGroup.getEntityGroupName(), serverName);
    String node = getNodeName(zkw, entityGroup.getEncodedName());
    ZKUtil.createAndWatch(zkw, node, rt.toByteArray());
  }
View Full Code Here


      EntityGroupInfo entityGroup, ServerName serverName,
      final AsyncCallback.StringCallback cb, final Object ctx)
      throws KeeperException {
    LOG.debug(zkw.prefix("Async create of unassigned node for "
        + entityGroup.getEncodedName() + " with OFFLINE state"));
    EntityGroupTransaction rt = EntityGroupTransaction.createEntityGroupTransition(
        EventType.M_ZK_ENTITYGROUP_OFFLINE, entityGroup.getEntityGroupName(), serverName);
    String node = getNodeName(zkw, entityGroup.getEncodedName());
    ZKUtil.asyncCreate(zkw, node, rt.toByteArray(), cb, ctx);
  }
View Full Code Here

   */
  public static int createOrForceNodeOffline(ZooKeeperWatcher zkw,
      EntityGroupInfo entityGroup, ServerName serverName) throws KeeperException {
    LOG.debug(zkw.prefix("Creating (or updating) unassigned node for "
        + entityGroup.getEncodedName() + " with OFFLINE state"));
    EntityGroupTransaction rt = EntityGroupTransaction.createEntityGroupTransition(
        EventType.M_ZK_ENTITYGROUP_OFFLINE, entityGroup.getEntityGroupName(), serverName,
        HConstants.EMPTY_BYTE_ARRAY);
    byte[] data = rt.toByteArray();
    String node = getNodeName(zkw, entityGroup.getEncodedName());
    zkw.sync(node);
    int version = ZKUtil.checkExists(zkw, node);
    if (version == -1) {
      return ZKUtil.createAndWatch(zkw, node, data);
    } else {
      boolean setData = false;
      try {
        setData = ZKUtil.setData(zkw, node, data, version);
        // Setdata throws KeeperException which aborts the Master. So we are
        // catching it here.
        // If just before setting the znode to OFFLINE if the RS has made any
        // change to the
        // znode state then we need to return -1.
      } catch (KeeperException kpe) {
        LOG.info("Version mismatch while setting the node to OFFLINE state.");
        return -1;
      }
      if (!setData) {
        return -1;
      } else {
        // We successfully forced to OFFLINE, reset watch and handle if
        // the state changed in between our set and the watch
        byte[] bytes = ZKAssign.getData(zkw, entityGroup.getEncodedName());
        rt = getEntityGroupTransition(bytes);
        if (rt.getEventType() != EventType.M_ZK_ENTITYGROUP_OFFLINE) {
          // state changed, need to process
          return -1;
        }
      }
    }
View Full Code Here

    byte[] bytes = ZKUtil.getDataNoWatch(zkw, node, stat);
    if (bytes == null) {
      // If it came back null, node does not exist.
      throw KeeperException.create(Code.NONODE);
    }
    EntityGroupTransaction rt = getEntityGroupTransition(bytes);
    EventType et = rt.getEventType();
    if (!et.equals(expectedState)) {
      LOG.warn(zkw.prefix("Attempting to delete unassigned node "
          + entityGroupName
          + " in " + expectedState + " state but node is in " + et + " state"));
      return false;
View Full Code Here

      EntityGroupInfo entityGroup,
      ServerName serverName) throws KeeperException,
      KeeperException.NodeExistsException {
    LOG.debug(zkw.prefix("Creating unassigned node for "
        + entityGroup.getEncodedName() + " in a CLOSING state"));
    EntityGroupTransaction rt = EntityGroupTransaction.createEntityGroupTransition(
        EventType.M_ZK_ENTITYGROUP_CLOSING, entityGroup.getEntityGroupName(), serverName,
        HConstants.EMPTY_BYTE_ARRAY);
    String node = getNodeName(zkw, entityGroup.getEncodedName());
    return ZKUtil.createAndWatch(zkw, node, rt.toByteArray());
  }
View Full Code Here

    byte[] existingBytes = ZKUtil.getDataNoWatch(zkw, node, stat);
    if (existingBytes == null) {
      // Node no longer exists. Return -1. It means unsuccessful transition.
      return -1;
    }
    EntityGroupTransaction rt = getEntityGroupTransition(existingBytes);

    // Verify it is the expected version
    if (expectedVersion != -1 && stat.getVersion() != expectedVersion) {
      LOG.warn(zkw.prefix("Attempt to transition the " + "unassigned node for "
          + encoded + " from " + beginState + " to " + endState + " failed, "
          + "the node existed but was version " + stat.getVersion()
          + " not the expected version " + expectedVersion));
      return -1;
    } else if (beginState.equals(EventType.M_ZK_ENTITYGROUP_OFFLINE)
        && endState.equals(EventType.FSERVER_ZK_ENTITYGROUP_OPENING)
        && expectedVersion == -1 && stat.getVersion() != 0) {
      // the below check ensures that double assignment doesnot happen.
      // When the node is created for the first time then the expected version
      // that is passed will be -1 and the version in znode will be 0.
      // In all other cases the version in znode will be > 0.
      LOG.warn(zkw.prefix("Attempt to transition the " + "unassigned node for "
          + encoded + " from " + beginState + " to " + endState + " failed, "
          + "the node existed but was version " + stat.getVersion()
          + " not the expected version " + expectedVersion));
      return -1;
    }

    // Verify it is in expected state
    EventType et = rt.getEventType();
    if (!et.equals(beginState)) {
      LOG.warn(zkw.prefix("Attempt to transition the " + "unassigned node for "
          + encoded + " from " + beginState + " to " + endState + " failed, "
          + "the node existed but was in the state " + et
          + " set by the server " + serverName));
      return -1;
    }

    // Write new data, ensuring data has not changed since we last read it
    try {
      rt = EntityGroupTransaction.createEntityGroupTransition(endState,
          entityGroup.getEntityGroupName(), serverName, payload);
      if (!ZKUtil.setData(zkw, node, rt.toByteArray(), stat.getVersion())) {
        LOG.warn(zkw.prefix("Attempt to transition the "
            + "unassigned node for " + encoded + " from " + beginState + " to "
            + endState + " failed, "
            + "the node existed and was in the expected state but then when "
            + "setting data we got a version mismatch"));
View Full Code Here

  static String toString(final byte[] znodeBytes) {
    // This method should not exist. Used by ZKUtil stringifying
    // EntityGroupTransition. Have the
    // method in here so EntityGroupTransition does not leak into ZKUtil.
    try {
      EntityGroupTransaction rt = EntityGroupTransaction.parseFrom(znodeBytes);
      return rt.toString();
    } catch (DeserializationException e) {
      return "";
    }
  }
View Full Code Here

  int createNodeSplitting(final ZooKeeperWatcher zkw,
      final EntityGroupInfo entityGroup, final ServerName serverName)
      throws KeeperException, IOException {
    LOG.debug(zkw.prefix("Creating ephemeral node for "
        + entityGroup.getEncodedName() + " in SPLITTING state"));
    EntityGroupTransaction data = EntityGroupTransaction
        .createEntityGroupTransition(
            EventHandler.EventType.FSERVER_ZK_ENTITYGROUP_SPLITTING,
            entityGroup.getEntityGroupName(), serverName);
    String node = ZKAssign.getNodeName(zkw, entityGroup.getEncodedName());
    if (!ZKUtil.createEphemeralNodeAndWatch(zkw, node, data.toByteArray())) {
      throw new IOException("Failed create of ephemeral " + node);
    }
    // Transition node from SPLITTING to SPLITTING and pick up version so we
    // can be sure this znode is ours; version is needed deleting.
    return transitionNodeSplitting(zkw, entityGroup, serverName, -1);
View Full Code Here

      Stat stat = new Stat();
      byte[] data = ZKAssign.getDataAndWatch(watcher, encodedEntityGroupName,
          stat);
      if (data == null)
        return false;
      EntityGroupTransaction rt;
      try {
        rt = EntityGroupTransaction.parseFrom(data);
      } catch (DeserializationException e) {
        LOG.warn("Failed parse znode data", e);
        return false;
      }
      EntityGroupInfo egInfo = entityGroupInfo;
      if (egInfo == null) {
        egInfo = entityGroupStates.getEntityGroupInfo(rt.getEntityGroupName());
        if (egInfo == null)
          return false;
      }
      processEntityGroupsInTransition(rt, egInfo, stat.getVersion());
      return true;
View Full Code Here

            Stat stat = new Stat();
            byte[] data = ZKAssign.getDataAndWatch(watcher, path, stat);
            if (data == null)
              return;

            EntityGroupTransaction rt = EntityGroupTransaction.parseFrom(data);
            handleEntityGroup(rt, stat.getVersion());
          } catch (KeeperException e) {
            server.abort(
                "Unexpected ZK exception reading unassigned node data", e);
          } catch (DeserializationException e) {
View Full Code Here

TOP

Related Classes of com.alibaba.wasp.EntityGroupTransaction

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.