Skip to content

Conversation

@3pacccccc
Copy link
Contributor

@3pacccccc 3pacccccc commented Jul 10, 2025

Motivation

Currently, when adding a message to a ledger, ManagedLedgerImpl.ADD_OP_COUNT_UPDATER is incremented twice:

  1. First increment occurs in createOpAddEntryNoRetainBuffer() when creating the OpAddEntry
  2. Second increment occurs in OpAddEntry.initiate()

This double increment leads to incorrect operation counting and potential metric inaccuracies.
here's the example I've tested on my local.
1752159904760

Modifications

  • Changed the second occurrence in OpAddEntry.initiate() from incrementAndGet() to get() to prevent duplicate counting
  • Added a test case testAddOpCountWithMessageAdd() to verify the correct increment behavior

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: 3pacccccc#11

@github-actions
Copy link

@3pacccccc 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 -->

@3pacccccc 3pacccccc closed this Jul 10, 2025
@3pacccccc 3pacccccc reopened this Jul 10, 2025
@github-actions github-actions bot added doc-not-needed Your PR changes do not impact docs and removed doc-label-missing labels Jul 10, 2025

// internally asyncAddEntry() will take the ownership of the buffer and release it at the end
addOpCount = ManagedLedgerImpl.ADD_OP_COUNT_UPDATER.incrementAndGet(ml);
addOpCount = ManagedLedgerImpl.ADD_OP_COUNT_UPDATER.get(ml);
Copy link
Member

Choose a reason for hiding this comment

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

How about remove this line instead of ManagedLedgerImpl.ADD_OP_COUNT_UPDATER.get(ml) ?

OpAddEntry.addOpCount was already set in OpAddEntry.createOpAddEntryNoRetainBuffer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this makes more sense. Thanks for pointing it out. I've already removed it,please take a look again

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.

6 participants