apache/pulsar · error · RestException

Exceed the maximum number of namespace in tenant :${tenant}

Error message

Exceed the maximum number of namespace in tenant :${tenant}

What it means

A 412 PRECONDITION_FAILED thrown when creating a namespace would exceed the broker's maxNamespacesPerTenant limit. If the limit is > 0, the broker counts existing namespaces in the tenant and rejects creation when the count already exceeds it. The comment in the source notes there is no distributed lock, so under concurrency the threshold can be exceeded.

Source

Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java:165

                    if (!existed) {
                        throw new RestException(Status.NOT_FOUND, "Tenant not found");
                    }
                    return tenantResources().getListOfNamespacesAsync(tenant);
                });
    }

    protected CompletableFuture<Void> internalCreateNamespace(Policies policies) {
        return validateTenantOperationAsync(namespaceName.getTenant(), TenantOperation.CREATE_NAMESPACE)
                .thenCompose(__ -> validatePoliciesReadOnlyAccessAsync())
                .thenCompose(__ -> validatePoliciesAsync(namespaceName, policies))
                .thenCompose(__ -> {
                    int maxNamespacesPerTenant = pulsar().getConfiguration().getMaxNamespacesPerTenant();
                    // no distributed locks are added here.In a concurrent scenario, the threshold will be exceeded.
                    if (maxNamespacesPerTenant > 0) {
                        return tenantResources().getListOfNamespacesAsync(namespaceName.getTenant())
                                .thenAccept(namespaces -> {
                                    if (namespaces != null && namespaces.size() > maxNamespacesPerTenant) {
                                        throw new RestException(Status.PRECONDITION_FAILED,
                                                "Exceed the maximum number of namespace in tenant :"
                                                        + namespaceName.getTenant());
                                    }
                                });
                    }
                    return CompletableFuture.completedFuture(null);
                })
                .thenCompose(__ -> namespaceResources().createPoliciesAsync(namespaceName, policies))
                .thenAccept(__ -> log.info()
                        .attr("namespace", namespaceName)
                        .log("Created namespace"));
    }

    protected CompletableFuture<List<String>> internalGetListOfTopics(AsyncResponse response, Policies policies,
                                                                      CommandGetTopicsOfNamespace.Mode mode) {
        // Use maxTopicListInFlightLimiter to limit inflight get topic listing responses
        // to avoid OOME caused by a lot of clients using HTTP service lookups to list topics
        AsyncDualMemoryLimiterImpl maxTopicListInFlightLimiter =

View on GitHub (pinned to 820761864e)

Solutions

  1. Raise or disable the limit: set maxNamespacesPerTenant=0 (unlimited) or a higher value in broker.conf and restart/roll brokers.
  2. Delete unused namespaces in the tenant to get under the limit.
  3. Use the tenant's existing namespaces (reuse rather than create) — list via GET /admin/v3/namespaces/{tenant}.

Example fix

# before: broker.conf
maxNamespacesPerTenant=10
# after
maxNamespacesPerTenant=0  # or a value above current usage
Defensive patterns

Strategy: validation

Validate before calling

int existing = admin.namespaces().getNamespaces(tenant).size();
int max = brokerConf.getMaxNamespacesPerTenant(); // >0 means enforced
if (max > 0 && existing >= max) {
  throw new IllegalStateException("tenant " + tenant + " is at namespace limit " + max);
}

Try / catch

try { admin.namespaces().createNamespace(ns); }
catch (PulsarAdminException e) {
  if (e.getStatusCode() == 412) { /* raise limit or reuse existing ns */ }
  else throw e;
}

Prevention

When it happens

Trigger: pulsar-admin namespaces create or Namespaces.createNamespace when the tenant already has more namespaces than maxNamespacesPerTenant (broker.conf, 0 = unlimited); concurrent creations racing past the check.

Common situations: Environments where the limit was lowered after many namespaces already exist; CI/test suites mass-creating namespaces; concurrent provisioning scripts exceeding the soft (unlocked) limit.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/f1769cf6d7db2d89. Report an issue: GitHub.