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

chenhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 104f3163f8 Fix readEntry parameter order (#4059)
104f3163f8 is described below

commit 104f3163f84e4033577938e629fec98b734ad777
Author: Zhangao <[email protected]>
AuthorDate: Fri Sep 1 12:16:34 2023 +0800

    Fix readEntry parameter order (#4059)
    
    Correct the parameters order of method readEntry
---
 .../bookkeeper/bookie/DefaultEntryLogger.java      |  2 +-
 .../bookkeeper/bookie/DefaultEntryLogTest.java     | 26 ++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/DefaultEntryLogger.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/DefaultEntryLogger.java
index d6b667ba25..575a8b375e 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/DefaultEntryLogger.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/DefaultEntryLogger.java
@@ -840,7 +840,7 @@ public class DefaultEntryLogger implements EntryLogger {
 
     @Override
     public ByteBuf readEntry(long location) throws IOException, 
Bookie.NoEntryException {
-        return internalReadEntry(location, -1L, -1L, false /* validateEntry 
*/);
+        return internalReadEntry(-1L, -1L, location, false /* validateEntry 
*/);
     }
 
 
diff --git 
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/DefaultEntryLogTest.java
 
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/DefaultEntryLogTest.java
index d18c9cf284..38a9ebaf21 100644
--- 
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/DefaultEntryLogTest.java
+++ 
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/DefaultEntryLogTest.java
@@ -20,6 +20,8 @@
  */
 package org.apache.bookkeeper.bookie;
 
+import static 
org.apache.bookkeeper.bookie.storage.EntryLogTestUtils.assertEntryEquals;
+import static org.apache.bookkeeper.bookie.storage.EntryLogTestUtils.makeEntry;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -37,6 +39,7 @@ import com.google.common.collect.Sets;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import io.netty.buffer.UnpooledByteBufAllocator;
+import io.netty.util.ReferenceCountUtil;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -894,6 +897,29 @@ public class DefaultEntryLogTest {
         Assert.assertEquals("EntryId", 1L, readEntryId);
     }
 
+    @Test
+    public void testReadEntryWithoutLedgerID() throws Exception {
+        List<Long> locations = new ArrayList<>();
+        // `+ 1` is not a typo: create one more log file than the max number 
of o cached readers
+        for (int i = 0; i < 10; i++) {
+            ByteBuf e = makeEntry(1L, i, 100);
+            long loc = entryLogger.addEntry(1L, e.slice());
+            locations.add(loc);
+        }
+        entryLogger.flush();
+        for (Long loc : locations) {
+            int i = locations.indexOf(loc);
+            ByteBuf data = entryLogger.readEntry(loc);
+            assertEntryEquals(data, makeEntry(1L, i, 100));
+            long readLedgerId = data.readLong();
+            long readEntryId = data.readLong();
+            Assert.assertEquals("LedgerId", 1L, readLedgerId);
+            Assert.assertEquals("EntryId", i, readEntryId);
+            ReferenceCountUtil.release(data);
+        }
+    }
+
+
     /*
      * tests basic logic of EntryLogManager interface for
      * EntryLogManagerForEntryLogPerLedger.

Reply via email to