DefaultCommandStore extends AbstractStore implements CommandStore { protected boolean canDeleteCmdFile(long lowestReadingOffset, long fileStartOffset, long fileSize, long lastModified) { boolean lowestReading = (fileStartOffset + fileSize < lowestReadingOffset); logger.debug("[canDeleteCmdFile][lowestReading]{}, {}+{}<{}", lowestReading, fileStartOffset, fileSize, lowestReadingOffset); if(!lowestReading){ return false; } Date now = new Date(); boolean time = now.getTime() - lastModified >= minTimeMilliToGcAfterModified; logger.debug("[canDeleteCmdFile][time]{}, {} - {} > {}", time, now, new Date(lastModified), minTimeMilliToGcAfterModified); if(!time){ return false; } long totalLength = totalLength(); long totalKeep = (long)fileSize * fileNumToKeep.getAsInt(); boolean fileKeep = totalLength - (fileStartOffset + fileSize) > totalKeep; logger.debug("[canDeleteCmdFile][fileKeep]{}, {} - {} > {}({}*{})", fileKeep, totalLength, (fileStartOffset + fileSize), totalKeep, fileSize, fileNumToKeep); if(!fileKeep){ return false; } return true; } DefaultCommandStore(File file, int maxFileSize, KeeperMonitor keeperMonitor);  DefaultCommandStore(File file, int maxFileSize, int minTimeMilliToGcAfterModified, IntSupplier fileNumToKeep, long commandReaderFlyingThreshold, KeeperMonitor keeperMonitor); @Override int appendCommands(ByteBuf byteBuf); @Override long totalLength(); @Override CommandReader beginRead(long startOffset); @Override boolean awaitCommandsOffset(long offset, int timeMilli); @Override long lowestReadingOffset(); @Override void addCommandsListener(long offset, final CommandsListener listener); @Override void close(); @Override void destroy(); @Override String toString(); String simpleDesc(); @Override long lowestAvailableOffset(); @Override void gc(); static final long DEFAULT_COMMAND_READER_FLYING_THRESHOLD; }
@Test public void testDynamicConfig() throws IOException { final int initDataKeep = 20; final AtomicInteger dataKeep = new AtomicInteger(initDataKeep); int gcAfterCreateMilli = 60000; File commandTemplate = new File(getTestFileDir(), getTestName()); commandStore = new DefaultCommandStore(commandTemplate, maxFileSize, gcAfterCreateMilli, () -> dataKeep.get(), DefaultCommandStore.DEFAULT_COMMAND_READER_FLYING_THRESHOLD, createkeeperMonitor()){ @Override public long totalLength() { return initDataKeep * maxFileSize; } }; Assert.assertFalse(commandStore.canDeleteCmdFile(maxFileSize * 10, 0, maxFileSize, 0)); dataKeep.set(19); Assert.assertFalse(commandStore.canDeleteCmdFile(maxFileSize * 10, 0, maxFileSize, 0)); dataKeep.set(18); Assert.assertTrue(commandStore.canDeleteCmdFile(maxFileSize * 10, 0, maxFileSize, 0)); }