apache/pulsar · error · org.apache.pulsar.broker.admin.RestException

Namespace does not exist

Error message

Namespace does not exist

What it means

Returned by getNamespaceReplicatedClustersAsync when the namespace policies are absent (policies.isEmpty()) while fetching the replication cluster set. Means the namespace does not exist in the metadata store; surfaces as HTTP 404. Used by flows like creating a replicated partitioned topic in the background.

Source

Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java:508

    protected CompletableFuture<Void> validateClusterExistsAsync(String cluster) {
        return clusterResources().clusterExistsAsync(cluster).thenAccept(clusterExist -> {
            if (!clusterExist) {
                throw new RestException(Status.PRECONDITION_FAILED, "Cluster " + cluster + " does not exist.");
            }
        });
    }

    /**
     * Directly get the replication clusters for a namespace, without checking allowed clusters.
     */
    protected CompletableFuture<Set<String>> getNamespaceReplicatedClustersAsync(NamespaceName namespaceName) {
        return namespaceResources().getPoliciesAsync(namespaceName)
                .thenApply(policies -> {
                    if (policies.isPresent()) {
                        return policies.get().replication_clusters;
                    } else {
                        throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
                    }
                });
    }

    protected List<String> getPartitionedTopicList(TopicDomain topicDomain) {
        try {
            return namespaceResources().getPartitionedTopicResources()
                    .listPartitionedTopicsAsync(namespaceName, topicDomain)
                    .join();
        } catch (Exception e) {
            log.error()
                    .attr("namespace", namespaceName.toString())
                    .exception(e)
                    .log("Failed to get partitioned topic list for namespace");
            throw new RestException(e);
        }
    }

View on GitHub (pinned to 820761864e)

Solutions

  1. Create the namespace first (PUT /admin/v2/namespaces/tenant/ns) before creating topics in it.
  2. Verify tenant/namespace spelling in the topic name — names are case-sensitive.
  3. Check for concurrent namespace deletion in your automation and re-run the topic creation after re-creating the namespace.
  4. List namespaces under the tenant (GET /admin/v2/namespaces/tenant) to confirm the namespace exists.

Example fix

// before
admin.topics().createPartitionedTopic("my-tenant/new-ns/orders", 4); // ns missing
// after
admin.namespaces().createNamespace("my-tenant/new-ns");
admin.namespaces().setNamespaceReplicationClusters("my-tenant/new-ns", Sets.newHashSet("r1","r2"));
admin.topics().createPartitionedTopic("my-tenant/new-ns/orders", 4);
Defensive patterns

Strategy: validation

Validate before calling

// Java: ensure the namespace exists before topic creation
try {
    admin.namespaces().getPolicies(nsName);
} catch (PulsarAdminException.NotFoundException e) {
    admin.namespaces().createNamespace(nsName);
}

Type guard

static boolean namespaceExists(Iterable<String> namespaces, String ns) {
    for (String n : namespaces) if (n.equals(ns)) return true;
    return false;
}

Try / catch

try {
    admin.topics().createPartitionedTopic(fqTopic, n);
} catch (PulsarAdminException e) {
    if (e.getStatusCode() == 404 && e.getMessage().contains("Namespace does not exist")) {
        admin.namespaces().createNamespace(ns);
        // retry the create
    }
}

Prevention

When it happens

Trigger: internalCreatePartitionedTopicToReplicatedClustersInBackground (or similar) looking up policies for a namespace that was deleted before/while the topic was being created, or a typo'd tenant/namespace in the topic name so no policies record exists.

Common situations: Race between namespace deletion and topic creation in automation; creating topics in a namespace that was never created; multi-cluster setups where the namespace exists on one cluster but not the one being addressed; case-sensitivity mistakes in tenant/namespace names.

Related errors


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