Called whenever a rebalance task completes. This means one task is done
and some number of partition stores have been migrated.

@param taskId
@param partitionStoresMigrated Number of partition stores moved by this
completed task.
326476
synchronized public void completeTask(int taskId, int partitionStoresMigrated) {
        tasksInFlight.remove(taskId);

        numTasksCompleted++;
        numPartitionStoresMigrated += partitionStoresMigrated;

        updateProgressBar();
    }
1221179
private void validateClusterForRebalance(RebalancePlan rebalancePlan) {
        logger.info("Validating state of deployed cluster to confirm its ready for rebalance.");
        Cluster finalCluster = rebalancePlan.getFinalCluster();
        List<StoreDefinition> finalStoreDefs = rebalancePlan.getFinalStores();

        // Reset the cluster that the admin client points at
        adminClient.setAdminClientCluster(finalCluster);
        // Validate that all the nodes ( new + old ) are in normal state
        adminClient.rebalanceOps.checkEachServerInNormalState(finalCluster);
        // Verify all old RO stores exist at version 2
        adminClient.rebalanceOps.validateReadOnlyStores(finalCluster,
                                                        finalStoreDefs);
    }
347798
@Override
    public void afterCompletion(int status) {
        if (status == Status.STATUS_COMMITTED)
            controller.notifyOfTaskAssignment(partitionId, taskId, expectedExecTime, binaryFlags, txTimeout);
    }
877146
protected void initNewTask(final int taskID)
	{

		this.articleID = taskID;

		this.partCounter = 0;
		this.revisionCounter = 0;

		this.revPrevious = null;
		this.revCurrent = null;
	}
1368025
public void setTaskIds(java.util.Collection<String> taskIds) {
        if (taskIds == null) {
            this.taskIds = null;
            return;
        }

        this.taskIds = new com.amazonaws.internal.SdkInternalList<String>(taskIds);
    }
573243
public void prepareTransferMastership(int partitionId, int hostId) {
        synchronized(m_dataSourcesByPartition) {
            Map<String, ExportDataSource> partitionDataSourceMap = m_dataSourcesByPartition.get(partitionId);

            // this case happens when there are no export tables
            if (partitionDataSourceMap == null) {
                return;
            }
            for (ExportDataSource eds : partitionDataSourceMap.values()) {
                eds.prepareTransferMastership(hostId);
            }
        }
    }
44240
public void releasePartitions(Collection<ResultPartitionID> partitionIds) {
		for (ResultPartitionID partitionId : partitionIds) {
			resultPartitionManager.releasePartition(partitionId, null);
		}
	}
981761
protected void taskStart(int taskId, int rebalanceAsyncId) {
        taskCompletionTimeMs = System.currentTimeMillis();
        taskLog("[TaskId : " + taskId + " ] Starting rebalance of " + partitionStoreCount
                + " partition-stores for async operation id " + rebalanceAsyncId + ".");
        progressBar.beginTask(taskId);
    }
1343140
public void killTask(TaskAttemptID taskId) throws IOException {
    ensureState(JobState.RUNNING);
    info.killTask(org.apache.hadoop.mapred.TaskAttemptID.downgrade(taskId),
                  false);
  }
489082
@Private
  @Override
  public void aggregationThrewException(final List<Integer> taskletIds, final Exception exception) {
    try {
      failedTasklets(exception, taskletIds);
    } catch (final InterruptedException e) {
      throw new RuntimeException(e);
    }
  }
442442
void incrementReservations(TaskType type, int reservedSlots) {
    if (type.equals(TaskType.MAP)) {
      reservedMapSlots += reservedSlots;
    } else if (type.equals(TaskType.REDUCE)) {
      reservedReduceSlots += reservedSlots;
    }
  }
615539
public static List<PartitionDefinition> assignPartitions(List<PartitionDefinition> partitions, int currentTask, int totalTasks) {
        int esPartitions = partitions.size();
        if (totalTasks >= esPartitions) {
            return (currentTask >= esPartitions ? Collections.<PartitionDefinition>emptyList() : Collections.singletonList(partitions.get(currentTask)));
        } else {
            int partitionsPerTask = esPartitions / totalTasks;
            int remainder = esPartitions % totalTasks;

            int partitionsPerCurrentTask = partitionsPerTask;

            // spread the reminder against the tasks
            if (currentTask < remainder) {
                partitionsPerCurrentTask++;
            }

            // find the offset inside the collection
            int offset = partitionsPerTask * currentTask;
            if (currentTask != 0) {
                offset += (remainder > currentTask ? 1 : remainder);
            }

            // common case
            if (partitionsPerCurrentTask == 1) {
                return Collections.singletonList(partitions.get(offset));
            }

            List<PartitionDefinition> pa = new ArrayList<PartitionDefinition>(partitionsPerCurrentTask);
            for (int index = offset; index < offset + partitionsPerCurrentTask; index++) {
                pa.add(partitions.get(index));
            }
            return pa;
        }
    }
1259874
public void setMigratePartitionLeaderStatus(boolean migratePartitionLeader) {
        if (!migratePartitionLeader) {
            m_migratePartitionLeaderStatus = MigratePartitionLeaderStatus.NONE;
            m_newLeaderHSID = Long.MIN_VALUE;
            return;
        }

        //The previous leader has already drained all txns
        if (m_migratePartitionLeaderStatus == MigratePartitionLeaderStatus.TXN_DRAINED) {
            m_migratePartitionLeaderStatus = MigratePartitionLeaderStatus.NONE;
            tmLog.info("MigratePartitionLeader transactions on previous partition leader are drained. New leader:" +
                            CoreUtils.hsIdToString(m_hsId) + " status:" + m_migratePartitionLeaderStatus);
            return;
        }

        //Wait for the notification from old partition leader
        m_migratePartitionLeaderStatus = MigratePartitionLeaderStatus.TXN_RESTART;
        tmLog.info("MigratePartitionLeader restart txns on new leader:" + CoreUtils.hsIdToString(m_hsId) + " status:" + m_migratePartitionLeaderStatus);
    }
1295899
private void verifyClusterStoreDefinition() {
        if(SystemStoreConstants.isSystemStore(storeDefinition.getName())) {
            // TODO: Once "todo" in StorageService.initSystemStores is complete,
            // this early return can be removed and verification can be enabled
            // for system stores.
            return;
        }

        Set<Integer> clusterZoneIds = cluster.getZoneIds();

        if(clusterZoneIds.size() > 1) { // Zoned
            Map<Integer, Integer> zoneRepFactor = storeDefinition.getZoneReplicationFactor();
            Set<Integer> storeDefZoneIds = zoneRepFactor.keySet();

            if(!clusterZoneIds.equals(storeDefZoneIds)) {
                throw new VoldemortException("Zone IDs in cluster (" + clusterZoneIds
                                             + ") are incongruent with zone IDs in store defs ("
                                             + storeDefZoneIds + ")");
            }

            for(int zoneId: clusterZoneIds) {
                if(zoneRepFactor.get(zoneId) > cluster.getNumberOfNodesInZone(zoneId)) {
                    throw new VoldemortException("Not enough nodes ("
                                                 + cluster.getNumberOfNodesInZone(zoneId)
                                                 + ") in zone with id " + zoneId
                                                 + " for replication factor of "
                                                 + zoneRepFactor.get(zoneId) + ".");
                }
            }
        } else { // Non-zoned

            if(storeDefinition.getReplicationFactor() > cluster.getNumberOfNodes()) {
                System.err.println(storeDefinition);
                System.err.println(cluster);
                throw new VoldemortException("Not enough nodes (" + cluster.getNumberOfNodes()
                                             + ") for replication factor of "
                                             + storeDefinition.getReplicationFactor() + ".");
            }
        }
    }
1280952
public void finalizeReplicaSync(int partitionId, int replicaIndex, ServiceNamespace namespace, long[] versions) {
        PartitionReplicaVersions replicaVersion = replicaVersions[partitionId];
        replicaVersion.clear(namespace);
        replicaVersion.set(namespace, versions, replicaIndex);
        clearReplicaSyncRequest(partitionId, namespace, replicaIndex);
    }
903052
private boolean taskSuccessfulInPriorAttempt(String taskId) {
    if (this.taskStateStoreOptional.isPresent()) {
      StateStore<TaskState> taskStateStore = this.taskStateStoreOptional.get();
      // Delete the task state file for the task if it already exists.
      // This usually happens if the task is retried upon failure.
      try {
        if (taskStateStore.exists(jobId, taskId + TASK_STATE_STORE_SUCCESS_MARKER_SUFFIX)) {
          log.info("Skipping task {} that successfully executed in a prior attempt.", taskId);

          // skip tasks that executed successfully in a previous attempt
          return true;
        }
      } catch (IOException e) {
        // if an error while looking up the task state store then treat like it was not processed
        return false;
      }
    }

    return false;
  }
997357
protected synchronized void taskCompleted(String uploadId) {
        UploadTask task = uploadTasksMap.remove(uploadId);
        uploadDelegates.remove(uploadId);

        // un-hold foreground upload ID if it's been hold
        if (isExecuteInForeground() && task != null && task.params.id.equals(foregroundUploadId)) {
            Logger.debug(TAG, uploadId + " now un-holded the foreground notification");
            foregroundUploadId = null;
        }

        if (isExecuteInForeground() && uploadTasksMap.isEmpty()) {
            Logger.debug(TAG, "All tasks completed, stopping foreground execution");
            stopForeground(true);
            shutdownIfThereArentAnyActiveTasks();
        }
    }