Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][cli] Fix set topic retention policy failed #23688

Merged

Conversation

hangc0276
Copy link
Contributor

@hangc0276 hangc0276 commented Dec 6, 2024

Fixes #xyz

Main Issue: #xyz

PIP: #xyz

Motivation

When using this command bin/pulsar-admin topics set-retention -s 20g -t 200d persistent://public/default/test_v1 to set a retention policy for a topic, it failed with following exception

PicocliException: Could not set value for field private java.lang.Integer org.apache.pulsar.admin.cli.CmdTopics$SetRetention.retentionTimeInSec to 17280000 while processing argument at or before arg[5] '200d' in [topics, set-retention, -s, 20g, -t, 200d, persistent://public/default/test_v1]: picocli.CommandLine$PicocliException: Could not set value for field private java.lang.Integer org.apache.pulsar.admin.cli.CmdTopics$SetRetention.retentionTimeInSec to 17280000
Usage: pulsar-admin topics set-retention [-hv] -s=<sizeLimit>
       -t=<retentionTimeInSec> <topicName>
Set the retention policy for a topic
      <topicName>          persistent://tenant/namespace/topic
  -h, --help               Show this help message and exit.
  -s, --size=<sizeLimit>   Retention size limit with optional size unit suffix.
                             For example, 4096, 10M, 16G, 3T.  The size unit
                             suffix character can be k/K, m/M, g/G, or t/T.  If
                             the size unit suffix is not specified, the default
                             unit is bytes. 0 or less than 1MB means no
                             retention and -1 means infinite size retention
  -t, --time=<retentionTimeInSec>
                           Retention time with optional time unit suffix. For
                             example, 100m, 3h, 2d, 5w. If the time unit is not
                             specified, the default unit is seconds. For
                             example, -t 120 will set retention to 2 minutes. 0
                             means no retention and -1 means infinite time
                             retention.
  -v, --version            Print version information and exit.

It is caused by cast Long to Integer failed

converter = TimeUnitToSecondsConverter.class)
private Integer retentionTimeInSec;

public Long convert(String value) throws Exception {
try {
return TimeUnit.SECONDS.toSeconds(RelativeTimeUtil.parseRelativeTimeInSeconds(value));
} catch (Exception e) {
throw new TypeConversionException(e.getMessage());
}
}
}

Modifications

Change the type of retentionTimeInSec from Integer to Long

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

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:

Copy link

github-actions bot commented Dec 6, 2024

@hangc0276 Please add the following content to your PR description and select a checkbox:

- [ ] `doc` <!-- Your PR contains doc changes -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
- [ ] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->

@lhotari lhotari changed the title [fix] [client] Fix set topic retention policy failed [fix][cli] Fix set topic retention policy failed Dec 6, 2024
@lhotari
Copy link
Member

lhotari commented Dec 6, 2024

@hangc0276 Good catch! There seems to also be a problem with sizeLimit. It's an integer and could overflow. Instead of ByteUnitToIntegerConverter, the ByteUnitToLongConverter should be used.

@github-actions github-actions bot added doc-not-needed Your PR changes do not impact docs and removed doc-label-missing labels Dec 6, 2024
@lhotari lhotari added this to the 4.1.0 milestone Dec 6, 2024
@codecov-commenter
Copy link

codecov-commenter commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.38%. Comparing base (bbc6224) to head (ca31316).
Report is 780 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #23688      +/-   ##
============================================
+ Coverage     73.57%   74.38%   +0.80%     
- Complexity    32624    35064    +2440     
============================================
  Files          1877     1945      +68     
  Lines        139502   147448    +7946     
  Branches      15299    16270     +971     
============================================
+ Hits         102638   109678    +7040     
- Misses        28908    29287     +379     
- Partials       7956     8483     +527     
Flag Coverage Δ
inttests 27.26% <ø> (+2.67%) ⬆️
systests 24.37% <ø> (+0.05%) ⬆️
unittests 73.76% <ø> (+0.91%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...in/java/org/apache/pulsar/admin/cli/CmdTopics.java 79.98% <ø> (-1.20%) ⬇️

... and 667 files with indirect coverage changes

@lhotari lhotari merged commit 85b3d54 into apache:master Dec 6, 2024
61 of 65 checks passed
@lhotari
Copy link
Member

lhotari commented Dec 6, 2024

@hangc0276 Good catch! There seems to also be a problem with sizeLimit. It's an integer and could overflow. Instead of ByteUnitToIntegerConverter, the ByteUnitToLongConverter should be used.

Addressed in #23689. It also covers changes to retentionTimeInSec overflow fix made in this PR. @hangc0276 please review #23689

@lhotari
Copy link
Member

lhotari commented Dec 6, 2024

It seems that this PR applies only to branch-3.3 and branch-3.4. The bug was most likely introduced in PIP-280 and PIP-343 changes.

lhotari pushed a commit that referenced this pull request Dec 6, 2024
lhotari pushed a commit that referenced this pull request Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants