karanmehta93 commented on a change in pull request #2090: Update and flush
lastLogMark when replaying journal
URL: https://github.com/apache/bookkeeper/pull/2090#discussion_r282684208
##########
File path:
bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/BookieInitializationTest.java
##########
@@ -136,6 +137,126 @@ public void tearDown() throws Exception {
super.tearDown();
}
+ @Test
+ public void testOneJournalReplayForBookieRestartInReadOnlyMode() throws
Exception {
+ testJournalReplayForBookieRestartInReadOnlyMode(1);
+ }
+
+ @Test
+ public void testFourJournalReplayForBookieRestartInReadOnlyMode() throws
Exception {
+ testJournalReplayForBookieRestartInReadOnlyMode(4);
+ }
+
+ /**
+ * Tests that journal replay works correctly when bookie crashes and
starts up in RO mode
+ */
+ private void testJournalReplayForBookieRestartInReadOnlyMode(int
numOfJournalDirs) throws Exception {
+ File tmpLedgerDir = createTempDir("DiskCheck", "test");
+ File tmpJournalDir = createTempDir("DiskCheck", "test");
+
+ String[] journalDirs = new String[numOfJournalDirs];
+ for (int i = 0; i < numOfJournalDirs; i++) {
+ journalDirs[i] = tmpJournalDir.getAbsolutePath() + "/journal-" + i;
+ }
+
+ final ServerConfiguration conf = newServerConfiguration()
+ .setJournalDirsName(journalDirs)
+ .setLedgerDirNames(new String[] { tmpLedgerDir.getPath() })
+ .setDiskCheckInterval(1000)
+ .setLedgerStorageClass(SortedLedgerStorage.class.getName())
+ .setAutoRecoveryDaemonEnabled(false)
+ .setZkTimeout(5000);
+
+ BookieServer server = new MockBookieServer(conf);
+ server.start();
+
+ List<LastLogMark> lastLogMarkList = new
ArrayList<>(journalDirs.length);
+
+ for (int i = 0; i < journalDirs.length; i++) {
+ Journal journal = server.getBookie().journals.get(i);
+ // LastLogMark should be (0, 0) at the bookie clean start
+ journal.getLastLogMark().readLog();
+ lastLogMarkList.add(journal.getLastLogMark().markLog());
+ assertEquals(0, lastLogMarkList.get(i).getCurMark().compare(new
LogMark(0, 0)));
+ }
+
+ ClientConfiguration clientConf = new ClientConfiguration();
+ clientConf.setMetadataServiceUri(metadataServiceUri);
+ BookKeeper bkClient = new BookKeeper(clientConf);
+
+ // Create multiple ledgers for adding entries to multiple journals
+ for (int i = 0; i < journalDirs.length; i++) {
+ LedgerHandle lh = bkClient.createLedger(1, 1, 1, DigestType.CRC32,
"passwd".getBytes());
+ long entryId = -1;
+ // Ensure that we have non-zero number of entries
+ long numOfEntries = new Random().nextInt(10) + 3;
+ for (int j = 0; j < numOfEntries; j++) {
+ entryId = lh.addEntry("data".getBytes());
+ }
+ assertEquals(entryId, (numOfEntries - 1));
+ lh.close();
+ }
+
+ for (int i = 0; i < journalDirs.length; i++) {
+ Journal journal = server.getBookie().journals.get(i);
+ // In-memory LastLogMark should be updated with every write to
journal
+
assertTrue(journal.getLastLogMark().getCurMark().compare(lastLogMarkList.get(i).getCurMark())
> 0);
+ lastLogMarkList.set(i, journal.getLastLogMark().markLog());
+ }
+
+ // Kill Bookie abruptly before entries are flushed to disk
+ server.shutdown();
+
+ conf.setDiskUsageThreshold(0.001f)
+
.setDiskUsageWarnThreshold(0.0f).setReadOnlyModeEnabled(true).setIsForceGCAllowWhenNoSpace(true)
+ .setMinUsableSizeForIndexFileCreation(5 * 1024);
+
+ server = new BookieServer(conf);
+
+ for (int i = 0; i < journalDirs.length; i++) {
+ Journal journal = server.getBookie().journals.get(i);
+ // LastLogMark should be (0, 0) before bookie restart since bookie
crashed before persisting lastMark
+ assertEquals(0, journal.getLastLogMark().getCurMark().compare(new
LogMark(0, 0)));
+ }
+
+ int numOfRestarts = 3;
+ // Restart server multiple times to ensure that logs are never
replayed and new files are not generated
+ for (int i = 0; i < numOfRestarts; i++) {
+
+ int txnBefore = countNumOfFiles(conf.getJournalDirs(), "txn");
+ int logBefore = countNumOfFiles(conf.getLedgerDirs(), "log");
+ int idxBefore = countNumOfFiles(conf.getLedgerDirs(), "idx");
+
+ server.start();
+
+ for (int j = 0; j < journalDirs.length; j++) {
+ Journal journal = server.getBookie().journals.get(j);
+
assertTrue(journal.getLastLogMark().getCurMark().compare(lastLogMarkList.get(j).getCurMark())
>= 0);
Review comment:
It should be always `> 0`, updated the test.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services