{"record":{"id":"e91b96397eabf0d0","repo":"apache/pulsar","slug":"namespace-does-not-exist","errorCode":null,"errorMessage":"Namespace does not exist","messagePattern":"Namespace does not exist","errorType":"http","errorClass":"org.apache.pulsar.broker.admin.RestException","httpStatus":404,"severity":"error","filePath":"pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java","lineNumber":508,"sourceCode":"\n    protected CompletableFuture<Void> validateClusterExistsAsync(String cluster) {\n        return clusterResources().clusterExistsAsync(cluster).thenAccept(clusterExist -> {\n            if (!clusterExist) {\n                throw new RestException(Status.PRECONDITION_FAILED, \"Cluster \" + cluster + \" does not exist.\");\n            }\n        });\n    }\n\n    /**\n     * Directly get the replication clusters for a namespace, without checking allowed clusters.\n     */\n    protected CompletableFuture<Set<String>> getNamespaceReplicatedClustersAsync(NamespaceName namespaceName) {\n        return namespaceResources().getPoliciesAsync(namespaceName)\n                .thenApply(policies -> {\n                    if (policies.isPresent()) {\n                        return policies.get().replication_clusters;\n                    } else {\n                        throw new RestException(Status.NOT_FOUND, \"Namespace does not exist\");\n                    }\n                });\n    }\n\n    protected List<String> getPartitionedTopicList(TopicDomain topicDomain) {\n        try {\n            return namespaceResources().getPartitionedTopicResources()\n                    .listPartitionedTopicsAsync(namespaceName, topicDomain)\n                    .join();\n        } catch (Exception e) {\n            log.error()\n                    .attr(\"namespace\", namespaceName.toString())\n                    .exception(e)\n                    .log(\"Failed to get partitioned topic list for namespace\");\n            throw new RestException(e);\n        }\n    }\n","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java#L490-L526","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Create the namespace first (PUT /admin/v2/namespaces/tenant/ns) before creating topics in it.","Verify tenant/namespace spelling in the topic name — names are case-sensitive.","Check for concurrent namespace deletion in your automation and re-run the topic creation after re-creating the namespace.","List namespaces under the tenant (GET /admin/v2/namespaces/tenant) to confirm the namespace exists."],"exampleFix":"// before\nadmin.topics().createPartitionedTopic(\"my-tenant/new-ns/orders\", 4); // ns missing\n// after\nadmin.namespaces().createNamespace(\"my-tenant/new-ns\");\nadmin.namespaces().setNamespaceReplicationClusters(\"my-tenant/new-ns\", Sets.newHashSet(\"r1\",\"r2\"));\nadmin.topics().createPartitionedTopic(\"my-tenant/new-ns/orders\", 4);","handlingStrategy":"validation","validationCode":"// Java: ensure the namespace exists before topic creation\ntry {\n    admin.namespaces().getPolicies(nsName);\n} catch (PulsarAdminException.NotFoundException e) {\n    admin.namespaces().createNamespace(nsName);\n}","typeGuard":"static boolean namespaceExists(Iterable<String> namespaces, String ns) {\n    for (String n : namespaces) if (n.equals(ns)) return true;\n    return false;\n}","tryCatchPattern":"try {\n    admin.topics().createPartitionedTopic(fqTopic, n);\n} catch (PulsarAdminException e) {\n    if (e.getStatusCode() == 404 && e.getMessage().contains(\"Namespace does not exist\")) {\n        admin.namespaces().createNamespace(ns);\n        // retry the create\n    }\n}","preventionTips":["Provision namespaces (and replication clusters) before topics in automation.","Guard against concurrent namespace deletion in CI/CD pipelines.","Validate tenant/namespace casing — names are case-sensitive."],"tags":["http-404","namespace","admin-api"],"backgroundTag":"namespace-not-found","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}