Skip to content

Commit

Permalink
Added UT
Browse files Browse the repository at this point in the history
Signed-off-by: Shivansh Arora <[email protected]>
  • Loading branch information
shiv0408 committed Apr 11, 2024
1 parent c320b67 commit 3b7464c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public class RemoteClusterStateService implements Closeable {
public static final TimeValue GLOBAL_METADATA_UPLOAD_TIMEOUT_DEFAULT = TimeValue.timeValueMillis(20000);

public static final TimeValue METADATA_MANIFEST_UPLOAD_TIMEOUT_DEFAULT = TimeValue.timeValueMillis(20000);
public static final TimeValue CLUSTER_STATE_CLEANUP_INTERVAL_DEFAULT = TimeValue.timeValueMillis(60000);
public static final TimeValue CLUSTER_STATE_CLEANUP_INTERVAL_MINIMUM = TimeValue.MINUS_ONE;

public static final Setting<TimeValue> INDEX_METADATA_UPLOAD_TIMEOUT_SETTING = Setting.timeSetting(
"cluster.remote_store.state.index_metadata.upload_timeout",
Expand Down Expand Up @@ -155,8 +157,8 @@ public class RemoteClusterStateService implements Closeable {
*/
public static final Setting<TimeValue> REMOTE_CLUSTER_STATE_CLEANUP_INTERVAL_SETTING = Setting.timeSetting(
"cluster.remote_store.state.cleanup_interval",
TimeValue.timeValueMinutes(5),
TimeValue.timeValueMillis(-1),
CLUSTER_STATE_CLEANUP_INTERVAL_DEFAULT,
CLUSTER_STATE_CLEANUP_INTERVAL_MINIMUM,
Property.NodeScope,
Property.Dynamic
);
Expand Down Expand Up @@ -583,8 +585,8 @@ private void updateCleanupInterval(TimeValue updatedInterval) {
this.staleFileCleanupInterval = updatedInterval;
logger.info("updated remote state cleanup interval to {}", updatedInterval);
// After updating the interval, we need to close the current task and create a new one which will run with updated interval
if (!this.staleFileDeletionTask.getInterval().equals(updatedInterval)) {
this.staleFileDeletionTask.setInterval(updatedInterval);
if (staleFileDeletionTask != null && !staleFileDeletionTask.getInterval().equals(updatedInterval)) {
staleFileDeletionTask.setInterval(updatedInterval);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.gateway.remote.ClusterMetadataManifest.UploadedIndexMetadata;
import org.opensearch.index.remote.RemoteStoreUtils;
import org.opensearch.index.translog.transfer.BlobStoreTransferService;
import org.opensearch.indices.IndicesModule;
import org.opensearch.repositories.FilterRepository;
import org.opensearch.repositories.RepositoriesService;
Expand Down Expand Up @@ -78,6 +79,8 @@
import org.mockito.ArgumentMatchers;

import static java.util.stream.Collectors.toList;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.opensearch.gateway.remote.RemoteClusterStateService.CLUSTER_STATE_CLEANUP_INTERVAL_DEFAULT;
import static org.opensearch.gateway.remote.RemoteClusterStateService.DELIMITER;
import static org.opensearch.gateway.remote.RemoteClusterStateService.FORMAT_PARAMS;
import static org.opensearch.gateway.remote.RemoteClusterStateService.INDEX_METADATA_CURRENT_CODEC_VERSION;
Expand Down Expand Up @@ -1221,10 +1224,27 @@ public void testGlobalMetadataUploadWaitTimeSetting() {
assertEquals(globalMetadataUploadTimeout, remoteClusterStateService.getGlobalMetadataUploadTimeout().seconds());
}

public void testRemoteClusterStateCleanupSetting() {
remoteClusterStateService.start();
// verify default value
assertEquals(
CLUSTER_STATE_CLEANUP_INTERVAL_DEFAULT,
remoteClusterStateService.getStaleFileCleanupInterval()
);

// verify update interval
int cleanupInterval = randomIntBetween(1, 10);
Settings newSettings = Settings.builder()
.put("cluster.remote_store.state.cleanup_interval", cleanupInterval + "s")
.build();
clusterSettings.applySettings(newSettings);
assertEquals(cleanupInterval, remoteClusterStateService.getStaleFileCleanupInterval().seconds());
}

public void testRemoteCleanupTaskScheduled() {
AbstractAsyncTask cleanupTask = remoteClusterStateService.getStaleFileDeletionTask();
assertNull(cleanupTask);

// now the task should be initialized
remoteClusterStateService.start();
assertNotNull(remoteClusterStateService.getStaleFileDeletionTask());
assertTrue(remoteClusterStateService.getStaleFileDeletionTask().mustReschedule());
Expand Down

0 comments on commit 3b7464c

Please sign in to comment.