Skip to content

Commit 2a350d2

Browse files
3pacccccccrossoverJie
authored andcommitted
[fix][broker] Fix duplicate increment of ADD_OP_COUNT_UPDATER in OpAddEntry (apache#24506)
Co-authored-by: crossoverJie <[email protected]> (cherry picked from commit 39ac65a) (cherry picked from commit ffc2495)
1 parent 3b536b5 commit 2a350d2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/OpAddEntry.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ public void initiate() {
134134
ByteBuf duplicateBuffer = data.retainedDuplicate();
135135

136136
// internally asyncAddEntry() will take the ownership of the buffer and release it at the end
137-
addOpCount = ManagedLedgerImpl.ADD_OP_COUNT_UPDATER.incrementAndGet(ml);
138137
lastInitTime = System.nanoTime();
139138
if (ml.getManagedLedgerInterceptor() != null) {
140139
long originalDataLen = data.readableBytes();

managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3308,6 +3308,25 @@ public void addFailed(ManagedLedgerException exception, Object ctx) {
33083308
setFieldValue(ManagedLedgerImpl.class, ledger, "currentLedger", null);
33093309
}
33103310

3311+
@Test
3312+
public void testAddOpCountWithMessageAdd() throws Exception {
3313+
ManagedLedgerFactoryConfig config = new ManagedLedgerFactoryConfig();
3314+
config.setMaxCacheSize(0);
3315+
3316+
@Cleanup("shutdown")
3317+
ManagedLedgerFactoryImpl factory = new ManagedLedgerFactoryImpl(metadataStore, bkc, config);
3318+
ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("my_test_ledger");
3319+
3320+
for (int i = 0; i < 10; i++) {
3321+
OpAddEntry op = OpAddEntry.createNoRetainBuffer(ledger,
3322+
ByteBufAllocator.DEFAULT.buffer(128), null, null, new AtomicBoolean());
3323+
ledger.internalAsyncAddEntry(op);
3324+
long addOpCount = ManagedLedgerImpl.ADD_OP_COUNT_UPDATER.get(ledger);
3325+
Assert.assertEquals(i + 1, addOpCount);
3326+
}
3327+
}
3328+
3329+
33113330
@Test
33123331
public void avoidUseSameOpAddEntryBetweenDifferentLedger() throws Exception {
33133332
ManagedLedgerFactoryConfig config = new ManagedLedgerFactoryConfig();

0 commit comments

Comments
 (0)