yangxianjungree commented on code in PR #4863:
URL: https://github.com/apache/bookkeeper/pull/4863#discussion_r3996194321


##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/DefaultEntryLogTest.java:
##########
@@ -1316,6 +1397,53 @@ public void testAppendLedgersMapOnCacheRemoval() throws 
Exception {
         assertEquals((entrySize + 4) * numOfEntries, ledgersMap.get(ledgerId), 
"Total size of entries");
     }
 
+    @Test
+    public void testAppendLedgersMapFailureOnCacheRemovalTriggersFatalError() 
throws Exception {
+        int evictionPeriod = 1;
+
+        ServerConfiguration conf = 
TestBKConfiguration.newServerConfiguration();
+        conf.setEntryLogFilePreAllocationEnabled(false);
+        conf.setEntryLogPerLedgerEnabled(true);
+        conf.setLedgerDirNames(createAndGetLedgerDirs(1));
+        conf.setEntrylogMapAccessExpiryTimeInSeconds(evictionPeriod);
+        LedgerDirsManager ledgerDirsManager = new LedgerDirsManager(conf, 
conf.getLedgerDirs(),
+                new DiskChecker(conf.getDiskUsageThreshold(), 
conf.getDiskUsageWarnThreshold()));
+
+        CountDownLatch fatalLatch = new CountDownLatch(1);
+        ledgerDirsManager.addLedgerDirsListener(new LedgerDirsListener() {
+            @Override
+            public void fatalError() {
+                fatalLatch.countDown();
+            }
+        });
+
+        DefaultEntryLogger entryLogger = new DefaultEntryLogger(conf, 
ledgerDirsManager);
+        EntryLogManagerForEntryLogPerLedger entryLogManager = 
(EntryLogManagerForEntryLogPerLedger) entryLogger
+                .getEntryLogManager();
+
+        long ledgerId = 0L;
+        File tmpFile = File.createTempFile("entrylog", "failed-eviction");
+        tmpFile.deleteOnExit();
+        FileChannel fileChannel = new RandomAccessFile(tmpFile, 
"rw").getChannel();
+        BufferedLogChannel logChannel = new 
BufferedLogChannel(UnpooledByteBufAllocator.DEFAULT, fileChannel, 10, 10,
+                0L, tmpFile, conf.getFlushIntervalInBytes());
+
+        try {
+            entryLogManager.setCurrentLogForLedgerAndAddToRotate(ledgerId, 
logChannel);
+
+            fileChannel.close();
+            Thread.sleep(evictionPeriod * 1000 + 100);
+            entryLogManager.doEntryLogMapCleanup();
+
+            assertTrue(fatalLatch.await(10, TimeUnit.SECONDS),
+                    "Cache removal appendLedgersMap failure should trigger 
fatal error");
+            
assertFalse(entryLogManager.getRotatedLogChannels().contains(logChannel),
+                    "Failed log channel should not be added to rotated logs");
+        } finally {
+            logChannel.close();

Review Comment:
   fixed by closing entryLogger



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to