This is an automated email from the ASF dual-hosted git repository.
lushiji 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 5beb8948ba Return activeLogChannel if new create (#3894)
5beb8948ba is described below
commit 5beb8948baa0f287e597ff2a29ec672ac2cb1220
Author: houxiaoyu <[email protected]>
AuthorDate: Fri May 12 19:07:24 2023 +0800
Return activeLogChannel if new create (#3894)
* Return activeLogChannel if new create
---
.../bookie/EntryLogManagerForSingleEntryLog.java | 1 +
.../bookkeeper/bookie/DefaultEntryLogTest.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 d6b6b9b303..59bcc02a57 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/DefaultEntryLogTest.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/DefaultEntryLogTest.java
index 64943dc4c5..d18c9cf284 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
@@ -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;
@@ -1434,6 +1440,21 @@ public class DefaultEntryLogTest {
}
}
+ @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