Skip to content

Commit

Permalink
[Broker] Prevent carrying state of PositionImplRecyclable when recycl…
Browse files Browse the repository at this point in the history
…ed (apache#10404)
  • Loading branch information
lhotari authored Apr 27, 2021
1 parent 7458dad commit 2daa8c0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<PositionImpl> individualDeletedMessages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class PositionImplRecyclable extends PositionImpl implements Position {

private final Handle<PositionImplRecyclable> recyclerHandle;

private static final Recycler<PositionImplRecyclable> RECYCLER = new Recycler<PositionImplRecyclable>() {
@Override
protected PositionImplRecyclable newObject(Recycler.Handle<PositionImplRecyclable> recyclerHandle) {
Expand All @@ -44,6 +44,7 @@ public static PositionImplRecyclable create() {
}

public void recycle() {
ackSet = null;
recyclerHandle.recycle(this);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 2daa8c0

Please sign in to comment.