This is an automated email from the ASF dual-hosted git repository. chenhang pushed a commit to branch branch-4.14 in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
commit 397788ac13012527cddcb86b926af0677773b456 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/TestEntryLog.java | 21 +++++++++++++++++++++ 2 files changed, 22 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/TestEntryLog.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/TestEntryLog.java index b360708474..8cd5b04de0 100644 --- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/TestEntryLog.java +++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/TestEntryLog.java @@ -26,6 +26,12 @@ 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; @@ -1432,6 +1438,21 @@ public class TestEntryLog { } } + @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
