diff --git a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java index 555a71e9eb384..dc89dbb1a56ca 100644 --- a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java +++ b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java @@ -163,6 +163,7 @@ public class ManagedCursorImpl implements ManagedCursor { PositionImplRecyclable position = PositionImplRecyclable.create(); position.ledgerId = key; position.entryId = value; + position.ackSet = null; return position; }; private final LongPairRangeSet individualDeletedMessages; diff --git a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/PositionImplRecyclable.java b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/PositionImplRecyclable.java index d84bbb33a12b9..ad955200bba0b 100644 --- a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/PositionImplRecyclable.java +++ b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/PositionImplRecyclable.java @@ -26,7 +26,7 @@ public class PositionImplRecyclable extends PositionImpl implements Position { private final Handle recyclerHandle; - + private static final Recycler RECYCLER = new Recycler() { @Override protected PositionImplRecyclable newObject(Recycler.Handle recyclerHandle) { @@ -44,6 +44,7 @@ public static PositionImplRecyclable create() { } public void recycle() { + ackSet = null; recyclerHandle.recycle(this); } diff --git a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/PositionImplRecyclableTest.java b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/PositionImplRecyclableTest.java new file mode 100644 index 0000000000000..4b4914e605c2b --- /dev/null +++ b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/PositionImplRecyclableTest.java @@ -0,0 +1,34 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.bookkeeper.mledger.impl; + +import static org.testng.Assert.assertNull; +import org.testng.annotations.Test; + +public class PositionImplRecyclableTest { + + @Test + void shouldNotCarryStateInAckSetWhenRecycled() { + PositionImplRecyclable position = PositionImplRecyclable.create(); + position.ackSet = new long[]{1L, 2L, 3L}; + position.recycle(); + PositionImplRecyclable position2 = PositionImplRecyclable.create(); + assertNull(position2.ackSet); + } +} \ No newline at end of file