This is an automated email from the ASF dual-hosted git repository.

penghui pushed a commit to branch branch-2.11
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-2.11 by this push:
     new e9da4127e6d [fix][broker] Fix open cursor with null-initialPosition 
result with earliest position (#18416)
e9da4127e6d is described below

commit e9da4127e6d0fd332a7c5eaeeb2f7f73ab7ad820
Author: houxiaoyu <[email protected]>
AuthorDate: Fri Nov 18 10:13:15 2022 +0800

    [fix][broker] Fix open cursor with null-initialPosition result with 
earliest position (#18416)
    
    (cherry picked from commit e0606b44c86aded4d46ddf4b2845967a3f9dc4ed)
---
 .../java/org/apache/bookkeeper/mledger/ManagedLedger.java | 12 ++++--------
 .../apache/bookkeeper/mledger/impl/ManagedCursorTest.java | 15 ++++++++++++++-
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git 
a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedLedger.java 
b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedLedger.java
index 0ebbd514a52..9600e390de0 100644
--- 
a/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedLedger.java
+++ 
b/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/ManagedLedger.java
@@ -219,8 +219,7 @@ public interface ManagedLedger {
      * @param name
      *            the name associated with the ManagedCursor
      * @param initialPosition
-     *            the cursor will be set at latest position or not when first 
created
-     *            default is <b>true</b>
+     *            if null, the cursor will be set at latest position when 
first created
      * @return the ManagedCursor
      * @throws ManagedLedgerException
      */
@@ -235,8 +234,7 @@ public interface ManagedLedger {
      * @param name
      *            the name associated with the ManagedCursor
      * @param initialPosition
-     *            the cursor will be set at latest position or not when first 
created
-     *            default is <b>true</b>
+     *            if null, the cursor will be set at latest position when 
first created
      * @param properties
      *             user defined properties that will be attached to the first 
position of the cursor, if the open
      *             operation will trigger the creation of the cursor.
@@ -322,8 +320,7 @@ public interface ManagedLedger {
      * @param name
      *            the name associated with the ManagedCursor
      * @param initialPosition
-     *            the cursor will be set at lastest position or not when first 
created
-     *            default is <b>true</b>
+     *            if null, the cursor will be set at latest position when 
first created
      * @param callback
      *            callback object
      * @param ctx
@@ -338,8 +335,7 @@ public interface ManagedLedger {
      * @param name
      *            the name associated with the ManagedCursor
      * @param initialPosition
-     *            the cursor will be set at lastest position or not when first 
created
-     *            default is <b>true</b>
+     *            if null, the cursor will be set at latest position when 
first created
      * @param cursorProperties
      *            the properties for the Cursor
      * @param callback
diff --git 
a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorTest.java
 
b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorTest.java
index 1a8feea1e0d..5b8476d244a 100644
--- 
a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorTest.java
+++ 
b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedCursorTest.java
@@ -101,7 +101,6 @@ import org.apache.pulsar.metadata.api.extended.SessionEvent;
 import org.apache.pulsar.metadata.impl.FaultInjectionMetadataStore;
 import org.apache.pulsar.metadata.api.MetadataStoreException;
 import org.apache.pulsar.metadata.api.Stat;
-import org.apache.pulsar.common.api.proto.IntRange;
 import org.awaitility.Awaitility;
 import org.mockito.MockedStatic;
 import org.mockito.Mockito;
@@ -146,6 +145,20 @@ public class ManagedCursorTest extends 
MockedBookKeeperTestCase {
         ledger.close();
     }
 
+    public void testOpenCursorWithNullInitialPosition() throws Exception {
+        ManagedLedgerConfig config = new ManagedLedgerConfig();
+        ManagedLedger ledger = 
factory.open("testOpenCursorWithNullInitialPosition", config);
+        // Write some data.
+        ledger.addEntry(new byte[]{1});
+        ledger.addEntry(new byte[]{2});
+        ledger.addEntry(new byte[]{3});
+        ledger.addEntry(new byte[]{4});
+        ledger.addEntry(new byte[]{5});
+
+        ManagedCursorImpl cursor = (ManagedCursorImpl) 
ledger.openCursor("c_testOpenCursorWithNullInitialPosition", null);
+        assertEquals(cursor.getMarkDeletedPosition(), 
ledger.getLastConfirmedEntry());
+    }
+
     private static void closeCursorLedger(ManagedCursorImpl managedCursor) {
         Awaitility.await().until(() -> {
             LedgerHandle ledgerHandle = 
Whitebox.getInternalState(managedCursor, "cursorLedger");

Reply via email to