Skip to content

Commit

Permalink
throw IllegalStateException in LogManagerImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
alievmirza committed Sep 27, 2024
1 parent 1b2cea2 commit cc562b6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,11 @@ public long getLastLogIndex(final boolean isFlush) {
Thread.currentThread().interrupt();
throw new IllegalStateException(e);
}
if (c.lastLogId == null) {
assert stopped : "Last log id can be null only when node is stopping.";

throw new IllegalStateException("Node is shutting down");
}
return c.lastLogId.getIndex();
}

Expand Down Expand Up @@ -895,17 +900,9 @@ public LogId getLastLogId(final boolean isFlush) {
throw new IllegalStateException(e);
}
if (c.lastLogId == null) {
assert stopped;

try {
shutDownLatch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();

throw new IllegalStateException(e);
}
assert stopped : "Last log id can be null only when node is stopping.";

return new LogId(this.lastLogIndex, unsafeGetTerm(this.lastLogIndex));
throw new IllegalStateException("Node is shutting down");
}
return c.lastLogId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public void run() {

@BeforeClass
public static void setupNodeTest() {
StorageOptionsFactory.registerRocksDBTableFormatConfig(GROUP_ID, RocksDBLogStorage.class, StorageOptionsFactory
.getDefaultRocksDBTableConfig().setBlockCacheSize(256 * SizeUnit.MB));
// StorageOptionsFactory.registerRocksDBTableFormatConfig(GROUP_ID, RocksDBLogStorage.class, StorageOptionsFactory
// .getDefaultRocksDBTableConfig().setBlockCacheSize(256 * SizeUnit.MB));
dumpThread = new DumpThread();
dumpThread.setName("NodeTest-DumpThread");
dumpThread.setDaemon(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

@RunWith(value = MockitoJUnitRunner.class)
Expand Down Expand Up @@ -416,4 +417,23 @@ public void testCheckAndSetConfiguration() throws Exception {
assertEquals("localhost:8081,localhost:8082", lastEntry.getOldConf().toString());
}

@Test
public void testLastLogIdWhenShutdown() throws Exception {
mockAddEntries();
assertEquals(1, this.logManager.getFirstLogIndex());
assertEquals(10, this.logManager.getLastLogIndex());
this.logManager.shutdown();
Exception e = assertThrows(IllegalStateException.class, () -> this.logManager.getLastLogId(true));
assertEquals("Node is shutting down", e.getMessage());
}

@Test
public void testLastLogIndexWhenShutdown() throws Exception {
mockAddEntries();
assertEquals(1, this.logManager.getFirstLogIndex());
assertEquals(10, this.logManager.getLastLogIndex());
this.logManager.shutdown();
Exception e = assertThrows(IllegalStateException.class, () -> this.logManager.getLastLogIndex(true));
assertEquals("Node is shutting down", e.getMessage());
}
}

0 comments on commit cc562b6

Please sign in to comment.