This is an automated email from the ASF dual-hosted git repository. yong pushed a commit to branch branch-4.15 in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
commit df3883346ab9f3062cf7f63859b8b2e4b6aa2b3f Author: houxiaoyu <[email protected]> AuthorDate: Fri May 12 19:07:24 2023 +0800 Return activeLogChannel if new create (#3894) * Return activeLogChannel if new create (cherry picked from commit 5beb8948baa0f287e597ff2a29ec672ac2cb1220) --- .../bookie/EntryLogManagerForSingleEntryLog.java | 1 + .../org/apache/bookkeeper/bookie/EntryLogTest.java | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogManagerForSingleEntryLog.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogManagerForSingleEntryLog.java index f5b8823711..a21870dccf 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogManagerForSingleEntryLog.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogManagerForSingleEntryLog.java @@ -93,6 +93,7 @@ class EntryLogManagerForSingleEntryLog extends EntryLogManagerBase { if (null == activeLogChannel) { // log channel can be null because the file is deferred to be created createNewLog(UNASSIGNED_LEDGERID, "because current active log channel has not initialized yet"); + return activeLogChannel; } boolean reachEntryLogLimit = rollLog ? reachEntryLogLimit(activeLogChannel, entrySize) diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/EntryLogTest.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/EntryLogTest.java index e3627f40ab..7149054e74 100644 --- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/EntryLogTest.java +++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/EntryLogTest.java @@ -26,6 +26,13 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + import com.google.common.collect.Sets; import io.netty.buffer.ByteBuf; @@ -1430,6 +1437,21 @@ public class EntryLogTest { } } + @Test + public void testSingleEntryLogCreateNewLog() throws Exception { + Assert.assertTrue(entryLogger.getEntryLogManager() instanceof EntryLogManagerForSingleEntryLog); + EntryLogManagerForSingleEntryLog singleEntryLog = + (EntryLogManagerForSingleEntryLog) entryLogger.getEntryLogManager(); + EntryLogManagerForSingleEntryLog mockSingleEntryLog = spy(singleEntryLog); + BufferedLogChannel activeLogChannel = mockSingleEntryLog.getCurrentLogForLedgerForAddEntry(1, 1024, true); + Assert.assertTrue(activeLogChannel != null); + + verify(mockSingleEntryLog, times(1)).createNewLog(anyLong(), anyString()); + // `readEntryLogHardLimit` and `reachEntryLogLimit` should not call if new create log + verify(mockSingleEntryLog, times(0)).reachEntryLogLimit(any(), anyLong()); + verify(mockSingleEntryLog, times(0)).readEntryLogHardLimit(any(), anyLong()); + } + /* * with entryLogPerLedger enabled, create multiple entrylogs, add entries of ledgers and read them before and after * flush
