{"record":{"id":"744e7c0db5bbbc5f","repo":"apache/pulsar","slug":"topic-doesn-t-have-any-data","errorCode":null,"errorMessage":"Topic doesn't have any data","messagePattern":"Topic doesn't have any data","errorType":"exception","errorClass":"PulsarAdminException","httpStatus":null,"severity":"error","filePath":"pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java","lineNumber":1415,"sourceCode":"\n    @Command(description = \"Trigger offload of data from a topic to long-term storage (e.g. Amazon S3)\")\n    private class Offload extends CliCommand {\n        @Option(names = { \"-s\", \"--size-threshold\" },\n                description = \"Maximum amount of data to keep in BookKeeper for the specified topic (e.g. 10M, 5G).\",\n                required = true,\n                converter = ByteUnitToLongConverter.class)\n        private Long sizeThreshold;\n\n        @Parameters(description = \"persistent://tenant/namespace/topic\", arity = \"1\")\n        private String topicName;\n\n        @Override\n        void run() throws PulsarAdminException {\n            String persistentTopic = validatePersistentTopic(topicName);\n\n            PersistentTopicInternalStats stats = getTopics().getInternalStats(persistentTopic, false);\n            if (stats.ledgers.size() < 1) {\n                throw new PulsarAdminException(\"Topic doesn't have any data\");\n            }\n\n            LinkedList<PersistentTopicInternalStats.LedgerInfo> ledgers = new LinkedList<>(stats.ledgers);\n            ledgers.get(ledgers.size() - 1).size = stats.currentLedgerSize; // doesn't get filled in now it seems\n            MessageId messageId = findFirstLedgerWithinThreshold(ledgers, sizeThreshold);\n\n            if (messageId == null) {\n                System.out.println(\"Nothing to offload\");\n                return;\n            }\n\n            getTopics().triggerOffload(persistentTopic, messageId);\n            System.out.println(\"Offload triggered for \" + persistentTopic + \" for messages before \" + messageId);\n        }\n    }\n\n    @Command(description = \"Check the status of data offloading from a topic to long-term storage\")\n    private class OffloadStatusCmd extends CliCommand {","sourceCodeStart":1397,"sourceCodeEnd":1433,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java#L1397-L1433","documentation":"The internal size-shrinking/offload threshold command reads the topic's internal stats; if stats.ledgers is empty, there is no ledger data to analyze, so it throws PulsarAdminException 'Topic doesn't have any data'.","triggerScenarios":"Running the command against a topic whose getInternalStats returns zero ledgers — a brand-new topic with no produced messages, or a non-persistent/misidentified topic with no stored data.","commonSituations":"Pointing the command at a freshly created topic; typos resolving to an empty topic; running against a topic that was fully offloaded/deleted; wrong cluster (topic exists elsewhere with data).","solutions":["Produce some messages to the topic first so at least one ledger exists","Verify the topic name/tenant/namespace and that you are on the correct cluster","If the topic should have data, check broker/internal-stats for data loss or cleanup"],"exampleFix":"// before\npulsar-admin topics ... empty-topic   # Topic doesn't have any data\n// after\n# after producing messages\npulsar-admin topics ... persistent://my-tenant/my-ns/my-topic","handlingStrategy":"validation","validationCode":"PersistentTopicInternalStats stats = admin.topics().getInternalStats(topic, false);\nif (stats == null || stats.ledgers == null || stats.ledgers.isEmpty()) {\n    // skip operation: topic has no data\n    return;\n}","typeGuard":"boolean topicHasData(PersistentTopicInternalStats stats) {\n    return stats != null && stats.ledgers != null && !stats.ledgers.isEmpty();\n}","tryCatchPattern":"try {\n    admin.topics().getInternalStats(topic, false);\n} catch (org.apache.pulsar.client.admin.PulsarAdminException e) {\n    if (e.getMessage().contains(\"Topic doesn't have any data\")) {\n        log.warn(\"Skipping: topic has no ledgers/data yet\");\n    } else { throw e; }\n}","preventionTips":["Produce messages before running data-dependent topic commands","Verify topic name, tenant, namespace, and cluster","Handle empty-topic cases explicitly in automation scripts"],"tags":["cli","empty-topic","internal-stats"],"backgroundTag":"empty-topic-data","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"}