{"record":{"id":"65baffbec431e916","repo":"apache/pulsar","slug":"too-few-workers-need-at-least-2-65baff","errorCode":null,"errorMessage":"Too few workers (need at least 2)","messagePattern":"Too few workers \\(need at least 2\\)","errorType":"http","errorClass":"RestException","httpStatus":400,"severity":"error","filePath":"pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/WorkerImpl.java","lineNumber":232,"sourceCode":"        }\n        throwIfNotSuperUser(authParams, \"get list of connectors\");\n        return this.worker().getConnectorsManager().getConnectorDefinitions();\n    }\n\n    @Override\n    public void rebalance(final URI uri, final AuthenticationParameters authParams) {\n        if (!isWorkerServiceAvailable()) {\n            throwUnavailableException();\n        }\n        throwIfNotSuperUser(authParams, \"rebalance cluster\");\n\n        if (worker().getLeaderService().isLeader()) {\n            try {\n                worker().getSchedulerManager().rebalanceIfNotInprogress();\n            } catch (SchedulerManager.RebalanceInProgressException e) {\n                throw new RestException(Status.BAD_REQUEST, \"Rebalance already in progress\");\n            } catch (SchedulerManager.TooFewWorkersException e) {\n                throw new RestException(Status.BAD_REQUEST, \"Too few workers (need at least 2)\");\n            }\n        } else {\n            WorkerInfo workerInfo = worker().getMembershipManager().getLeader();\n            if (workerInfo == null) {\n                throw new RestException(Status.INTERNAL_SERVER_ERROR, \"Leader cannot be determined\");\n            }\n            URI redirect =\n                    UriBuilder.fromUri(uri).host(workerInfo.getWorkerHostname()).port(workerInfo.getPort()).build();\n            throw new WebApplicationException(Response.temporaryRedirect(redirect).build());\n        }\n    }\n\n    @Override\n    public void drain(final URI uri, final String inWorkerId, final AuthenticationParameters authParams,\n                      boolean calledOnLeaderUri) {\n        if (!isWorkerServiceAvailable()) {\n            throwUnavailableException();\n        }","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/WorkerImpl.java#L214-L250","documentation":"This HTTP 400 error comes from the rebalance endpoint when the cluster has fewer than two workers. Rebalancing redistributes function instances between workers; with only one worker there is nothing to redistribute, so SchedulerManager throws TooFewWorkersException which WorkerImpl maps to this message.","triggerScenarios":"Calling POST /admin/v2/worker/rebalance when the membership manager sees only 1 worker in the cluster.","commonSituations":"Single-node dev/test clusters, clusters where other workers have crashed or been deregistered, or firing rebalance right after starting the first worker before others join.","solutions":["Add at least one more worker to the cluster before rebalancing","Verify worker membership via GET /admin/v2/worker/cluster to see registered workers","Investigate why other workers left (crash, network partition, deregistration) if the cluster is supposed to be larger"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"List<WorkerInfo> workers = admin.functions().getCluster();\nif (workers.size() < 2) throw new IllegalStateException(\"Need at least 2 workers before rebalance\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check worker membership count before calling rebalance","Monitor cluster size and alert when it drops below 2","Don't configure rebalance automation on single-node clusters"],"tags":["rest-api","functions-worker","cluster-topology"],"backgroundTag":"too-few-workers","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}