apache/pulsar · error · PulsarAdminException

Topic doesn't have any data

Error message

Topic doesn't have any data

What it means

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'.

Source

Thrown at pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java:1415

    @Command(description = "Trigger offload of data from a topic to long-term storage (e.g. Amazon S3)")
    private class Offload extends CliCommand {
        @Option(names = { "-s", "--size-threshold" },
                description = "Maximum amount of data to keep in BookKeeper for the specified topic (e.g. 10M, 5G).",
                required = true,
                converter = ByteUnitToLongConverter.class)
        private Long sizeThreshold;

        @Parameters(description = "persistent://tenant/namespace/topic", arity = "1")
        private String topicName;

        @Override
        void run() throws PulsarAdminException {
            String persistentTopic = validatePersistentTopic(topicName);

            PersistentTopicInternalStats stats = getTopics().getInternalStats(persistentTopic, false);
            if (stats.ledgers.size() < 1) {
                throw new PulsarAdminException("Topic doesn't have any data");
            }

            LinkedList<PersistentTopicInternalStats.LedgerInfo> ledgers = new LinkedList<>(stats.ledgers);
            ledgers.get(ledgers.size() - 1).size = stats.currentLedgerSize; // doesn't get filled in now it seems
            MessageId messageId = findFirstLedgerWithinThreshold(ledgers, sizeThreshold);

            if (messageId == null) {
                System.out.println("Nothing to offload");
                return;
            }

            getTopics().triggerOffload(persistentTopic, messageId);
            System.out.println("Offload triggered for " + persistentTopic + " for messages before " + messageId);
        }
    }

    @Command(description = "Check the status of data offloading from a topic to long-term storage")
    private class OffloadStatusCmd extends CliCommand {

View on GitHub (pinned to 820761864e)

Solutions

  1. Produce some messages to the topic first so at least one ledger exists
  2. Verify the topic name/tenant/namespace and that you are on the correct cluster
  3. If the topic should have data, check broker/internal-stats for data loss or cleanup

Example fix

// before
pulsar-admin topics ... empty-topic   # Topic doesn't have any data
// after
# after producing messages
pulsar-admin topics ... persistent://my-tenant/my-ns/my-topic
Defensive patterns

Strategy: validation

Validate before calling

PersistentTopicInternalStats stats = admin.topics().getInternalStats(topic, false);
if (stats == null || stats.ledgers == null || stats.ledgers.isEmpty()) {
    // skip operation: topic has no data
    return;
}

Type guard

boolean topicHasData(PersistentTopicInternalStats stats) {
    return stats != null && stats.ledgers != null && !stats.ledgers.isEmpty();
}

Try / catch

try {
    admin.topics().getInternalStats(topic, false);
} catch (org.apache.pulsar.client.admin.PulsarAdminException e) {
    if (e.getMessage().contains("Topic doesn't have any data")) {
        log.warn("Skipping: topic has no ledgers/data yet");
    } else { throw e; }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


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