Skip to content

[improve][cli] Add client side looping in "pulsar-admin topics analyze-backlog" cli to avoid potential HTTP call timeout#25126

Open
oneby-wang wants to merge 21 commits intoapache:masterfrom
oneby-wang:pulsar_cli_client_side_analyze_backlog
Open

[improve][cli] Add client side looping in "pulsar-admin topics analyze-backlog" cli to avoid potential HTTP call timeout#25126
oneby-wang wants to merge 21 commits intoapache:masterfrom
oneby-wang:pulsar_cli_client_side_analyze_backlog

Conversation

@oneby-wang
Copy link
Copy Markdown
Contributor

@oneby-wang oneby-wang commented Jan 6, 2026

Fixes #25537

Motivation

Use client-side looping instead of increasing broker settings to avoid potential HTTP call timeout in "pulsar-admin topics analyze-backlog" cli.

Modifications

Add client-side looping, add test.

Verifying this change

  • Make sure that the change passes the CI checks.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: oneby-wang#21

@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Jan 6, 2026
Comment thread pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java Outdated
Comment thread pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java Outdated
Comment thread pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java Outdated
Comment thread pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java Outdated
@oneby-wang
Copy link
Copy Markdown
Contributor Author

oneby-wang commented Feb 5, 2026

@lhotari Could help me solve the above questions when you have a moment? Especially about how to write integration tests easily in admin CLI module.

I'll refactor this PR using the API that PR #25127 provided once I'm back.

@lhotari
Copy link
Copy Markdown
Member

lhotari commented Feb 6, 2026

@oneby-wang #25127 has been merged

@oneby-wang oneby-wang force-pushed the pulsar_cli_client_side_analyze_backlog branch from b48e0eb to 83bdbf1 Compare February 6, 2026 11:56
Comment thread pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java Outdated
@oneby-wang oneby-wang force-pushed the pulsar_cli_client_side_analyze_backlog branch 3 times, most recently from 425e8bf to 941b50c Compare February 25, 2026 14:05
@oneby-wang oneby-wang force-pushed the pulsar_cli_client_side_analyze_backlog branch from 717742a to 91001d3 Compare March 28, 2026 03:58
@oneby-wang oneby-wang force-pushed the pulsar_cli_client_side_analyze_backlog branch from 91001d3 to 2456a05 Compare April 4, 2026 12:00
@oneby-wang oneby-wang requested a review from lhotari April 6, 2026 05:03
@oneby-wang
Copy link
Copy Markdown
Contributor Author

Hi @lhotari, could you please help review this refactored PR?

Comment on lines -1741 to -1744
cmdTopics.run(split("analyze-backlog persistent://myprop/ns1/ds1 -s sub1"));
verify(mockTopics).analyzeSubscriptionBacklog("persistent://myprop/ns1/ds1", "sub1",
Optional.empty());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be useful to keep a unit test for parameter parsing since this would catch issues before the integration test is run

Comment on lines +3021 to +3022
@Option(names = {"--plain-print",
"-pp"}, description = "Plain(Non-pretty) print the final result output as NDJSON", required = false)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since there's already -p, it's not recommended to add -pp. Instead, it's better to shorten --plain-print to --plain and just not add a short option name at all.

Comment on lines +3036 to +3042
getTopics().analyzeSubscriptionBacklogAsync(persistentTopic, subName, startPosition, result -> {
boolean terminate = result.getEntries() >= backlogScanMaxEntries;
if (!quiet && !terminate) {
print(result, false);
}
return terminate;
}).get();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the async method isn't useful since .get() is called. There would be a need to change to throws Exception when using analyzeSubscriptionBacklog method.

@Option(names = {"--backlog-scan-max-entries",
"-b"}, description = "The maximum number of backlog entries the client will scan before terminating "
+ "its loop", required = false)
private long backlogScanMaxEntries = -1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--backlog-scan-max-entries default of -1 relies on a subtle side-effect for backward compat — CmdTopics.java:3019 With -1, the predicate result.getEntries() >= -1 is always true, so the loop completes on the first iteration (matching old single-call behavior). That works, but it conflates "unset" with "terminate immediately." Preferred: treat unset as "no cap" (use the no-predicate overload analyzeSubscriptionBacklogAsync(topic, sub, pos)) and only take the looping path when -b is supplied.
That makes intent explicit and avoids relying on entries >= -1 semantics. Also add a validation error for -b 0 or negative user input, since those are meaningless.

Copy link
Copy Markdown
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs ready-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Add client side looping to "pulsar-admin topics analyze-backlog" cli command

2 participants