apache/pulsar · error · ParameterException

Need to specify either enable-delete-while-inactive or disab

Error message

Need to specify either enable-delete-while-inactive or disable-delete-while-inactive

What it means

Thrown by the 'set-inactive-topic-policies' namespace command when the flags controlling delete-while-inactive are ambiguous: enableDeleteWhileInactive == disableDeleteWhileInactive, i.e. neither flag was set or both were set. The command requires exactly one so it knows whether delete-while-inactive is switched on, and the error message names the two flags without the leading dashes. The command aborts before calling the admin API.

Source

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

        @Option(names = { "--disable-delete-while-inactive", "-d" }, description = "Disable delete while inactive")
        private boolean disableDeleteWhileInactive = false;

        @Option(names = {"--max-inactive-duration", "-t"}, description = "Max duration of topic inactivity in "
                + "seconds, topics that are inactive for longer than this value will be deleted "
                + "(eg: 1s, 10s, 1m, 5h, 3d)", required = true,
                converter = TimeUnitToSecondsConverter.class)
        private Long maxInactiveDurationInSeconds;

        @Option(names = { "--delete-mode", "-m" }, description = "Mode of delete inactive topic, Valid options are: "
                + "[delete_when_no_subscriptions, delete_when_subscriptions_caught_up]", required = true)
        private String inactiveTopicDeleteMode;

        @Override
        void run() throws PulsarAdminException {
            String namespace = validateNamespace(namespaceName);
            if (enableDeleteWhileInactive == disableDeleteWhileInactive) {
                throw new ParameterException("Need to specify either enable-delete-while-inactive or "
                        + "disable-delete-while-inactive");
            }
            InactiveTopicDeleteMode deleteMode = null;
            try {
                deleteMode = InactiveTopicDeleteMode.valueOf(inactiveTopicDeleteMode);
            } catch (IllegalArgumentException e) {
                throw new ParameterException("delete mode can only be set to delete_when_no_subscriptions or "
                        + "delete_when_subscriptions_caught_up");
            }
            getAdmin().namespaces().setInactiveTopicPolicies(namespace, new InactiveTopicPolicies(deleteMode,
                    maxInactiveDurationInSeconds.intValue(), enableDeleteWhileInactive));
        }
    }

    @Command(description = "Set the delayed delivery policy on a namespace")
    private class SetDelayedDelivery extends CliCommand {
        @Parameters(description = "tenant/namespace", arity = "1")
        private String namespaceName;

View on GitHub (pinned to 820761864e)

Solutions

  1. Pass exactly one of the delete-while-inactive enable/disable flags together with --max-inactive-duration and the delete mode.
  2. If enabling, include the enable flag explicitly plus a valid --inactive-topic-delete-mode value (delete_when_no_subscriptions or delete_when_subscriptions_caught_up).
  3. Audit generated command lines to ensure the toggle flag is always present exactly once.

Example fix

// before
pulsar-admin namespaces set-inactive-topic-policies public/default --delete-when-no-subscriptions --max-inactive-duration 30
// after
pulsar-admin namespaces set-inactive-topic-policies public/default --enable-delete-while-inactive --delete-when-no-subscriptions --max-inactive-duration 30
Defensive patterns

Strategy: validation

Validate before calling

MODE="delete_when_no_subscriptions"
if [[ "$MODE" != "delete_when_no_subscriptions" && "$MODE" != "delete_when_subscriptions_caught_up" ]]; then echo "invalid delete mode: $MODE"; exit 1; fi
pulsar-admin namespaces set-inactive-topic-policies public/default --enable-delete-while-inactive "$MODE" --max-inactive-duration 30

Prevention

When it happens

Trigger: Running 'pulsar-admin namespaces set-inactive-topic-policies <ns> --delete-when-no-subscriptions ...' without exactly one of the enable/disable-delete-while-inactive flags, or passing both at once.

Common situations: Omitting the toggle flag because the delete mode value was supplied (assuming mode alone implies enable); template merging adding both flags; older script examples predating the flag rename that drop the toggle.

Related errors


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