Skip to content

Commit

Permalink
fixing worker namespace initialize race condition (apache#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrypeng authored and sijie committed Mar 4, 2018
1 parent 3af1d48 commit 1832b52
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.apache.pulsar.common.policies.data.RetentionPolicies;
import org.apache.pulsar.functions.worker.rest.WorkerServer;

import javax.ws.rs.core.Response;

@Slf4j
public class Worker extends AbstractService {

Expand Down Expand Up @@ -94,14 +96,17 @@ protected void doStartImpl() {
try {
admin.namespaces().getPolicies(this.workerConfig.getPulsarFunctionsNamespace());
} catch (PulsarAdminException e) {
if (e.getStatusCode() == 404) {
if (e.getStatusCode() == Response.Status.NOT_FOUND.getStatusCode()) {
// if not found than create
try {
admin.namespaces().createNamespace(this.workerConfig.getPulsarFunctionsNamespace());
} catch (PulsarAdminException e1) {
log.error("Failed to create namespace {} for pulsar functions", this.workerConfig
.getPulsarFunctionsNamespace(), e1);
throw new RuntimeException(e1);
// prevent race condition with other workers starting up
if (e1.getStatusCode() != Response.Status.CONFLICT.getStatusCode()) {
log.error("Failed to create namespace {} for pulsar functions", this.workerConfig
.getPulsarFunctionsNamespace(), e1);
throw new RuntimeException(e1);
}
}
try {
admin.namespaces().setRetention(
Expand Down

0 comments on commit 1832b52

Please sign in to comment.