private DataNodeIdentifier pickHeaviestLoad(DataNodeIdentifier otherNode) {
    DataNodeIdentifier replacementNode = null;

    PriorityBlockingQueue<DataNodeStatusPair> invertedStatusQueue =
        new PriorityBlockingQueue<DataNodeStatusPair>(
            datanodeStatuses.size(),
            new Comparator<DataNodeStatusPair>() {
              public int compare(DataNodeStatusPair a, DataNodeStatusPair b) {
                return -1 * a.compareTo(b);
              }
            });

    for (DataNodeStatusPair each : datanodeStatuses) {
      invertedStatusQueue.put(each);
    }

    while (replacementNode == null) {
      DataNodeStatusPair next = invertedStatusQueue.poll();
      DataNodeIdentifier nextId = next.getIdentifier();
      if (!nextId.equals(otherNode)) {
        replacementNode = nextId;
      }
    }

    return replacementNode;
  }
  private DataNodeIdentifier pickReplacement(
      SegmentGroup affectedGroup, DataNodeIdentifier oldNode) {
    DataNodeIdentifier replacementNode = null;
    List<DataNodeStatusPair> removedPairs = new ArrayList<DataNodeStatusPair>();

    while (replacementNode == null) {
      DataNodeStatusPair next = datanodeStatuses.poll();
      removedPairs.add(next);
      DataNodeIdentifier nextId = next.getIdentifier();
      if (!nextId.equals(oldNode) && !affectedGroup.isMember(nextId)) {
        replacementNode = nextId;
      }
    }

    for (DataNodeStatusPair each : removedPairs) {
      datanodeStatuses.add(each);
    }

    return replacementNode;
  }
  private void updateStatus(DataNodeIdentifier oldNode, DataNodeIdentifier replacementNode) {
    int segmentsPerSegmentGroup = coordinator.getSegmentsPerSegmentGroup();

    DataNodeStatusPair oldPair = null;
    DataNodeStatusPair newPair = null;

    for (DataNodeStatusPair eachPair : datanodeStatuses) {
      if (oldNode.equals(eachPair.getIdentifier())) {
        oldPair = eachPair;
      } else if (replacementNode.equals(eachPair.getIdentifier())) {
        newPair = eachPair;
      }
    }

    oldPair.getStatus().addStoredSegments(-1 * segmentsPerSegmentGroup);
    newPair.getStatus().addStoredSegments(segmentsPerSegmentGroup);

    datanodeStatuses.remove(oldPair);
    datanodeStatuses.remove(newPair);

    datanodeStatuses.add(oldPair);
    datanodeStatuses.add(newPair);
  }
Example #4
0
 public boolean isResponder(DataNodeIdentifier candidateResponder) {
   return resultResponder.equals(candidateResponder);
 }