diff --git oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/StandbyClientSync.java oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/StandbyClientSync.java index 2b07d8d..1b07c04 100644 --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/StandbyClientSync.java +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/StandbyClientSync.java @@ -19,8 +19,6 @@ package org.apache.jackrabbit.oak.segment.standby.client; -import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCount; - import java.io.Closeable; import java.io.IOException; import java.lang.management.ManagementFactory; @@ -139,12 +137,12 @@ public final class StandbyClientSync implements ClientStandbyStatusMBean, Runnab try (StandbyClient client = new StandbyClient(observer.getID(), secure, readTimeoutMs)) { client.connect(host, port); - long sizeBefore = fileStore.getStats().getApproximateSize(); + int genBefore = headGeneration(fileStore); new StandbyClientSyncExecution(fileStore, client, newRunningSupplier()).execute(); - long sizeAfter = fileStore.getStats().getApproximateSize(); + int genAfter = headGeneration(fileStore); - if (autoClean && sizeAfter > 1.25 * sizeBefore) { - log.info("Store size increased from {} to {}, will run cleanup.", humanReadableByteCount(sizeBefore), humanReadableByteCount(sizeAfter)); + if (autoClean && (genAfter > genBefore)) { + log.info("New head generation detected (prevHeadGen: {} newHeadGen: {}), running cleanup.", genBefore, genAfter); cleanupAndRemove(); } } @@ -162,6 +160,10 @@ public final class StandbyClientSync implements ClientStandbyStatusMBean, Runnab } } + private int headGeneration(FileStore fileStore) { + return fileStore.getHead().getRecordId().getSegment().getGcGeneration(); + } + private void cleanupAndRemove() throws IOException { fileStore.cleanup(); } diff --git oak-segment-tar/src/main/resources/OSGI-INF/metatype/metatype.properties oak-segment-tar/src/main/resources/OSGI-INF/metatype/metatype.properties index 86ff7b2..9dc70b8 100644 --- oak-segment-tar/src/main/resources/OSGI-INF/metatype/metatype.properties +++ oak-segment-tar/src/main/resources/OSGI-INF/metatype/metatype.properties @@ -47,4 +47,4 @@ standby.readtimeout.name = Standby Read Timeout standby.readtimeout.description = Timeout for requests issued from the standby instance in milliseconds standby.autoclean.name = Standby Automatic Cleanup -standby.autoclean.description = Call the cleanup method if the size of the store increases over 25% on a sync cycle +standby.autoclean.description = Call the cleanup method when the root segment Garbage Collector (GC) generation number increases \ No newline at end of file