kaushik-develop commented on a change in pull request #12178:
URL: https://github.com/apache/pulsar/pull/12178#discussion_r719766751



##########
File path: 
pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/SchedulerManager.java
##########
@@ -403,6 +548,82 @@ private void scheduleCompaction(ScheduledExecutorService 
executor, long schedule
         }
     }
 
+    @VisibleForTesting
+    List<Assignment> getCurrentPostDrainAssignments() {
+        return currentPostDrainAssignments;
+    }
+
+    @VisibleForTesting
+    void clearCurrentPostDrainAssignments() {
+        currentPostDrainAssignments = null;
+    }
+
+    @VisibleForTesting
+    List<Assignment> invokeDrain(String workerId) {
+
+        long startTime = System.nanoTime();
+
+        Set<String> availableWorkers = getCurrentAvailableWorkers();
+
+        // workerIdToAssignments is a map of the form {workerId : 
{FullyQualifiedInstanceId : Assignment}}
+        Map<String, Map<String, Assignment>> workerIdToAssignments = 
functionRuntimeManager.getCurrentAssignments();
+
+        // initialize stats collection
+        SchedulerStats schedulerStats = new 
SchedulerStats(workerIdToAssignments, availableWorkers);
+
+        boolean drainSuccessful = false;
+        List<Assignment> postDrainAssignments = null;
+
+        try {
+            // The worker was checked to be among the available ones, by the 
caller.
+            Preconditions.checkState(availableWorkers.contains(workerId));
+
+            drainOpStatusMap.put(workerId, DrainOpStatus.DrainInProgress);
+
+            val workerRemovealSuccessful = availableWorkers.remove(workerId);
+            Preconditions.checkState(workerRemovealSuccessful);
+
+            List<FunctionMetaData> allFunctions = 
functionMetaDataManager.getAllFunctionMetaData();
+            Map<String, Function.Instance> allInstances =
+                    computeAllInstances(allFunctions, 
functionRuntimeManager.getRuntimeFactory().externallyManaged());
+
+            // Pretend that current assignments is empty, and get the 
instances to assign.
+            Pair<List<Function.Instance>, List<Assignment>> instancesToAssign
+                    = getUnassignedFunctionInstances(null, allInstances);

Review comment:
       Sounds fair. I will fix.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to