Skip to content

Commit

Permalink
Re-factor some of the remote store settings
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Kale <[email protected]>
  • Loading branch information
Sachin Kale committed Aug 20, 2024
1 parent e7eb80f commit 6593fb2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import org.opensearch.common.collect.Tuple;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.indices.RemoteStoreSettings;
import org.opensearch.node.remotestore.RemoteStoreNodeAttribute;
import org.opensearch.node.remotestore.RemoteStoreNodeService;
import org.opensearch.node.remotestore.RemoteStorePinnedTimestampService;

import java.nio.ByteBuffer;
import java.util.ArrayList;
Expand Down Expand Up @@ -511,4 +513,24 @@ public static List<String> filterOutMetadataFilesBasedOnAge(
}
return metadataFilesWithMinAge;
}

/**
* Determines if the pinned timestamp state is stale based on the provided remote store settings.
*
* This method checks if the last successful fetch timestamp is older than a calculated stale buffer time.
* The stale buffer time is computed using the pinned timestamps scheduler interval and lookback interval
* from the remote store settings.
*
* @return true if the pinned timestamp state is considered stale, false otherwise.
*
* @throws NullPointerException if remoteStoreSettings is null.
* @throws IllegalStateException if unable to retrieve the pinned timestamps.
*/
public static boolean isPinnedTimestampStateStale() {
long lastSuccessfulFetchTimestamp = RemoteStorePinnedTimestampService.getPinnedTimestamps().v1();
long staleBufferInMillis = (RemoteStoreSettings.getPinnedTimestampsSchedulerInterval().millis() * 3) + RemoteStoreSettings
.getPinnedTimestampsLookbackInterval()
.millis();
return lastSuccessfulFetchTimestamp < (System.currentTimeMillis() - staleBufferInMillis);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.opensearch.index.store.lockmanager.RemoteStoreMetadataLockManager;
import org.opensearch.index.store.remote.metadata.RemoteSegmentMetadata;
import org.opensearch.index.store.remote.metadata.RemoteSegmentMetadataHandler;
import org.opensearch.indices.RemoteStoreSettings;
import org.opensearch.indices.replication.checkpoint.ReplicationCheckpoint;
import org.opensearch.node.remotestore.RemoteStorePinnedTimestampService;
import org.opensearch.threadpool.ThreadPool;
Expand Down Expand Up @@ -830,7 +831,7 @@ public void deleteStaleSegments(int lastNMetadataFilesToKeep) throws IOException
}

// Check last fetch status of pinned timestamps. If stale, return.
if (RemoteStorePinnedTimestampService.isPinnedTimestampStateStale()) {
if (RemoteStoreUtils.isPinnedTimestampStateStale()) {
logger.warn("Skipping remote segment store garbage collection as last fetch of pinned timestamp is stale");
return;
}
Expand Down Expand Up @@ -861,8 +862,7 @@ public void deleteStaleSegments(int lastNMetadataFilesToKeep) throws IOException

// Along with last N files, we need to keep files since last successful run of scheduler
long lastSuccessfulFetchOfPinnedTimestamps = pinnedTimestampsState.v1();
long minimumAgeInMillis = lastSuccessfulFetchOfPinnedTimestamps + RemoteStorePinnedTimestampService
.getPinnedTimestampsLookbackInterval()
long minimumAgeInMillis = lastSuccessfulFetchOfPinnedTimestamps + RemoteStoreSettings.getPinnedTimestampsLookbackInterval()
.getMillis();
metadataFilesEligibleToDelete = RemoteStoreUtils.filterOutMetadataFilesBasedOnAge(
metadataFilesEligibleToDelete,
Expand Down

0 comments on commit 6593fb2

Please sign in to comment.