Skip to content

[fix][broker] Fix duplicate increment of ADD_OP_COUNT_UPDATER in OpAddEntry #24506

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

Merged
merged 2 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public void initiate() {
ByteBuf duplicateBuffer = data.retainedDuplicate();

// internally asyncAddEntry() will take the ownership of the buffer and release it at the end
addOpCount = ManagedLedgerImpl.ADD_OP_COUNT_UPDATER.incrementAndGet(ml);
lastInitTime = System.nanoTime();
if (ml.getManagedLedgerInterceptor() != null) {
long originalDataLen = data.readableBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3318,6 +3318,25 @@ public void addFailed(ManagedLedgerException exception, Object ctx) {
setFieldValue(ManagedLedgerImpl.class, ledger, "currentLedger", null);
}

@Test
public void testAddOpCountWithMessageAdd() throws Exception {
ManagedLedgerFactoryConfig config = new ManagedLedgerFactoryConfig();
config.setMaxCacheSize(0);

@Cleanup("shutdown")
ManagedLedgerFactoryImpl factory = new ManagedLedgerFactoryImpl(metadataStore, bkc, config);
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("my_test_ledger");

for (int i = 0; i < 10; i++) {
OpAddEntry op = OpAddEntry.createNoRetainBuffer(ledger,
ByteBufAllocator.DEFAULT.buffer(128), null, null, new AtomicBoolean());
ledger.internalAsyncAddEntry(op);
long addOpCount = ManagedLedgerImpl.ADD_OP_COUNT_UPDATER.get(ledger);
Assert.assertEquals(i + 1, addOpCount);
}
}


@Test
public void avoidUseSameOpAddEntryBetweenDifferentLedger() throws Exception {
ManagedLedgerFactoryConfig config = new ManagedLedgerFactoryConfig();
Expand Down
Loading