Fixed deadlock between create function and leader initialization
@@ -199,12 +199,14 @@ public class FunctionMetaDataManager implements AutoCloseable {
* @throws IllegalStateException if we are not the leader
* @throws IllegalArgumentException if the request is out of date.
*/
- public synchronized void updateFunctionOnLeader(FunctionMetaData functionMetaData, boolean delete)
+ public void updateFunctionOnLeader(FunctionMetaData functionMetaData, boolean delete)
throws IllegalStateException, IllegalArgumentException {
+ boolean needsScheduling;
+ synchronized (this) {
if (exclusiveLeaderProducer == null) {
throw new IllegalStateException("Not the leader");
}
- boolean needsScheduling;
+
if (delete) {
needsScheduling = proccessDeregister(functionMetaData);
} else {
@@ -219,7 +221,8 @@ public class FunctionMetaDataManager implements AutoCloseable {
}
} else {
Request.ServiceRequest serviceRequest = Request.ServiceRequest.newBuilder()
- .setServiceRequestType(delete ? Request.ServiceRequest.ServiceRequestType.DELETE : Request.ServiceRequest.ServiceRequestType.UPDATE)
+ .setServiceRequestType(delete ? Request.ServiceRequest.ServiceRequestType.DELETE
+ : Request.ServiceRequest.ServiceRequestType.UPDATE)
.setFunctionMetaData(functionMetaData)
.setWorkerId(workerConfig.getWorkerId())
.setRequestId(UUID.randomUUID().toString())
@@ -238,6 +241,9 @@ public class FunctionMetaDataManager implements AutoCloseable {
log.error("Could not write into Function Metadata topic", e);
throw new IllegalStateException("Internal Error updating function at the leader", e);
}
+
+ }
+
if (needsScheduling) {
this.schedulerManager.schedule();
}
