jerrypeng commented on a change in pull request #7255:
URL: https://github.com/apache/pulsar/pull/7255#discussion_r444479973



##########
File path: 
pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionMetaDataManager.java
##########
@@ -174,89 +181,124 @@ public synchronized boolean containsFunction(String 
tenant, String namespace, St
     }
 
     /**
-     * Sends an update request to the FMT (Function Metadata Topic)
-     * @param functionMetaData The function metadata that needs to be updated
-     * @return a completable future of when the update has been applied
+     * Called by the worker when we are in the leader mode.  In this state, we 
update our in-memory
+     * data structures and then write to the metadata topic.
+     * @param functionMetaData The function metadata in question
+     * @param delete Is this a delete operation
+     * @throws IllegalStateException if we are not the leader
+     * @throws IllegalArgumentException if the request is out of date.
      */
-    public synchronized CompletableFuture<RequestResult> 
updateFunction(FunctionMetaData functionMetaData) {
-
-        FunctionMetaData existingFunctionMetadata = null;
-        if (containsFunction(functionMetaData.getFunctionDetails().getTenant(),
-                functionMetaData.getFunctionDetails().getNamespace(),
-                functionMetaData.getFunctionDetails().getName())) {
-            existingFunctionMetadata = 
getFunctionMetaData(functionMetaData.getFunctionDetails().getTenant(),
-                    functionMetaData.getFunctionDetails().getNamespace(),
-                    functionMetaData.getFunctionDetails().getName());
+    public synchronized void updateFunctionOnLeader(FunctionMetaData 
functionMetaData, boolean delete)
+            throws IllegalStateException, IllegalArgumentException {
+        if (exclusiveLeaderProducer == null) {
+            throw new IllegalStateException("Not the leader");
+        }
+        boolean needsScheduling;
+        if (delete) {
+            needsScheduling = proccessDeregister(functionMetaData);
+        } else {
+            needsScheduling = processUpdate(functionMetaData);
+        }
+        Request.ServiceRequest serviceRequest = 
Request.ServiceRequest.newBuilder()
+                .setServiceRequestType(delete ? 
Request.ServiceRequest.ServiceRequestType.DELETE : 
Request.ServiceRequest.ServiceRequestType.UPDATE)
+                .setFunctionMetaData(functionMetaData)
+                .setWorkerId(workerConfig.getWorkerId())
+                .setRequestId(UUID.randomUUID().toString())
+                .build();
+        try {
+            lastMessageSeen = 
exclusiveLeaderProducer.send(serviceRequest.toByteArray());
+        } catch (Exception e) {

Review comment:
       Shouldn't we return a 500 error to the end user?  If we call just 
"errorNotifier.triggerError(e)", the worker die and the end user will likely 
not get a response or a timeout error




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to