Skip to content

[fix][broker] Fix getEstimatedSizeSinceMarkDeletePosition throw IllegalArgumentException#26184

Open
Technoboy- wants to merge 3 commits into
apache:masterfrom
Technoboy-:fix-warn1
Open

[fix][broker] Fix getEstimatedSizeSinceMarkDeletePosition throw IllegalArgumentException#26184
Technoboy- wants to merge 3 commits into
apache:masterfrom
Technoboy-:fix-warn1

Conversation

@Technoboy-

Copy link
Copy Markdown
Contributor

Motivation


2026-07-04T08:12:28,153+0000 [pulsar-compaction-monitor-26-1] WARN  org.apache.pulsar.broker.service.persistent.PersistentTopic - [persistent://email/org-74/__change_events-partition-0] Error getting policies and skipping compaction check
java.lang.IllegalArgumentException: Invalid range: (25257774:-1..25234514:0]
	at com.google.common.collect.Range.<init>(Range.java:363)
	at com.google.common.collect.Range.create(Range.java:161)
	at com.google.common.collect.Range.openClosed(Range.java:210)
	at org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.getEstimatedSizeSinceMarkDeletePosition(ManagedCursorImpl.java:1306)
--
	at org.apache.pulsar.common.util.SingleThreadNonConcurrentFixedRateScheduler$ScheduledFutureTask.run(SingleThreadNonConcurrentFixedRateScheduler.java:371)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Unknown Source)
2026-07-04T08:12:28,159+0000 [pulsar-compaction-monitor-26-1] WARN  org.apache.pulsar.broker.service.persistent.PersistentTopic - [persistent://email/org-87/__change_events-partition-0] Error getting policies and skipping compaction check
java.lang.IllegalArgumentException: Invalid range: (25519982:-1..25495087:0]
	at com.google.common.collect.Range.<init>(Range.java:363)
	at com.google.common.collect.Range.create(Range.java:161)
	at com.google.common.collect.Range.openClosed(Range.java:210)
	at org.apache.bookkeeper.mledger.impl.ManagedCursorImpl.getEstimatedSizeSinceMarkDeletePosition(ManagedCursorImpl.java:1306)

Modifications

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a production warning where ManagedCursorImpl#getEstimatedSizeSinceMarkDeletePosition() could throw IllegalArgumentException when the cursor’s markDeletePosition is ahead of the ledger’s lastPosition (creating an invalid Guava Range), which caused compaction checks to be skipped.

Changes:

  • Add an early-return guard in getEstimatedSizeSinceMarkDeletePosition() when markDeletePosition is null or >= lastPosition, preventing invalid Range construction.
  • Reuse a single lastPosition snapshot when computing the backlog range for both deleted-message counting and entry counting.
  • Add a unit test covering the “cursor markDeletePosition ahead of lastPosition” scenario.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java Prevent invalid (markDelete..last] ranges by returning 0 when mark-delete is at/after last position; use a consistent lastPosition snapshot for range calculations.
managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorTest.java Adds regression test ensuring estimated unacked size returns 0 (and doesn’t throw) when the cursor is ahead of the ledger last position.

@Technoboy- Technoboy- changed the title Fix getEstimatedSizeSinceMarkDeletePosition throw IllegalArgumentException [fix][broker] Fix getEstimatedSizeSinceMarkDeletePosition throw IllegalArgumentException Jul 13, 2026
@nodece nodece requested a review from lhotari July 14, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants