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 19, 2024
1 parent 1ca00c9 commit c19356d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 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
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ public class RemoteStoreSettings {
private volatile RemoteStoreEnums.PathHashAlgorithm pathHashAlgorithm;
private volatile int maxRemoteTranslogReaders;
private volatile boolean isTranslogMetadataEnabled;
private volatile TimeValue pinnedTimestampsSchedulerInterval;
private volatile TimeValue pinnedTimestampsLookbackInterval;
private static volatile TimeValue pinnedTimestampsSchedulerInterval;
private static volatile TimeValue pinnedTimestampsLookbackInterval;

public RemoteStoreSettings(Settings settings, ClusterSettings clusterSettings) {
clusterRemoteTranslogBufferInterval = CLUSTER_REMOTE_TRANSLOG_BUFFER_INTERVAL_SETTING.get(settings);
Expand Down Expand Up @@ -273,11 +273,11 @@ private void setMaxRemoteTranslogReaders(int maxRemoteTranslogReaders) {
this.maxRemoteTranslogReaders = maxRemoteTranslogReaders;
}

public TimeValue getPinnedTimestampsSchedulerInterval() {
public static TimeValue getPinnedTimestampsSchedulerInterval() {
return pinnedTimestampsSchedulerInterval;
}

public TimeValue getPinnedTimestampsLookbackInterval() {
public static TimeValue getPinnedTimestampsLookbackInterval() {
return pinnedTimestampsLookbackInterval;
}
}
3 changes: 1 addition & 2 deletions server/src/main/java/org/opensearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,7 @@ protected Node(
repositoriesServiceReference::get,
settings,
threadPool,
clusterService,
remoteStoreSettings
clusterService
);
resourcesToClose.add(remoteStorePinnedTimestampService);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public class RemoteStorePinnedTimestampService implements Closeable {
private final Settings settings;
private final ThreadPool threadPool;
private final ClusterService clusterService;
private final RemoteStoreSettings remoteStoreSettings;
private BlobStoreRepository blobStoreRepository;
private BlobStoreTransferService blobStoreTransferService;
private RemoteStorePinnedTimestampsBlobStore pinnedTimestampsBlobStore;
Expand All @@ -68,14 +67,12 @@ public RemoteStorePinnedTimestampService(
Supplier<RepositoriesService> repositoriesService,
Settings settings,
ThreadPool threadPool,
ClusterService clusterService,
RemoteStoreSettings remoteStoreSettings
ClusterService clusterService
) {
this.repositoriesService = repositoriesService;
this.settings = settings;
this.threadPool = threadPool;
this.clusterService = clusterService;
this.remoteStoreSettings = remoteStoreSettings;
}

/**
Expand All @@ -86,7 +83,7 @@ public RemoteStorePinnedTimestampService(
public void start() {
validateRemoteStoreConfiguration();
initializeComponents();
startAsyncUpdateTask(remoteStoreSettings.getPinnedTimestampsSchedulerInterval());
startAsyncUpdateTask(RemoteStoreSettings.getPinnedTimestampsSchedulerInterval());
}

private void validateRemoteStoreConfiguration() {
Expand Down Expand Up @@ -126,7 +123,7 @@ private void startAsyncUpdateTask(TimeValue pinnedTimestampsSchedulerInterval) {
public void pinTimestamp(long timestamp, String pinningEntity, ActionListener<Void> listener) {
// If a caller uses current system time to pin the timestamp, following check will almost always fail.
// So, we allow pinning timestamp in the past upto some buffer
long lookbackIntervalInMills = remoteStoreSettings.getPinnedTimestampsLookbackInterval().millis();
long lookbackIntervalInMills = RemoteStoreSettings.getPinnedTimestampsLookbackInterval().millis();
if (timestamp < (System.currentTimeMillis() - lookbackIntervalInMills)) {
throw new IllegalArgumentException(
"Timestamp to be pinned is less than current timestamp - value of cluster.remote_store.pinned_timestamps.lookback_interval"
Expand Down

0 comments on commit c19356d

Please sign in to comment.