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); }