forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize GC flow with pinned timestamps
Signed-off-by: Sachin Kale <[email protected]>
- Loading branch information
1 parent
4223fab
commit 1a26e5c
Showing
4 changed files
with
119 additions
and
17 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
...rTest/java/org/opensearch/remotestore/RemoteStorePinnedTimestampsGarbageCollectionIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.remotestore; | ||
|
||
import org.opensearch.action.LatchedActionListener; | ||
import org.opensearch.common.blobstore.BlobPath; | ||
import org.opensearch.common.collect.Tuple; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.unit.TimeValue; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.indices.RemoteStoreSettings; | ||
import org.opensearch.node.remotestore.RemoteStorePinnedTimestampService; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
import org.opensearch.test.junit.annotations.TestIssueLogging; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Set; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.opensearch.index.IndexSettings.INDEX_REMOTE_TRANSLOG_KEEP_EXTRA_GEN_SETTING; | ||
import static org.opensearch.index.remote.RemoteStoreEnums.DataCategory.SEGMENTS; | ||
import static org.opensearch.index.remote.RemoteStoreEnums.DataCategory.TRANSLOG; | ||
import static org.opensearch.index.remote.RemoteStoreEnums.DataType.DATA; | ||
import static org.opensearch.index.remote.RemoteStoreEnums.DataType.METADATA; | ||
|
||
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
public class RemoteStorePinnedTimestampsGarbageCollectionIT extends RemoteStoreBaseIntegTestCase { | ||
static final String INDEX_NAME = "remote-store-test-idx-1"; | ||
|
||
@Override | ||
protected Settings nodeSettings(int nodeOrdinal) { | ||
return Settings.builder() | ||
.put(super.nodeSettings(nodeOrdinal)) | ||
.put(RemoteStoreSettings.CLUSTER_REMOTE_STORE_PINNED_TIMESTAMP_ENABLED.getKey(), true) | ||
.build(); | ||
} | ||
|
||
ActionListener<Void> noOpActionListener = new ActionListener<>() { | ||
@Override | ||
public void onResponse(Void unused) {} | ||
|
||
@Override | ||
public void onFailure(Exception e) {} | ||
}; | ||
|
||
private void keepPinnedTimestampSchedulerUpdated() throws InterruptedException { | ||
long currentTime = System.currentTimeMillis(); | ||
int maxRetry = 10; | ||
while(maxRetry > 0 && RemoteStorePinnedTimestampService.getPinnedTimestamps().v1() <= currentTime) { | ||
Thread.sleep(1000); | ||
maxRetry--; | ||
} | ||
} | ||
|
||
public void testLiveIndexNoPinnedTimestamps() throws Exception { | ||
prepareCluster(1, 1, Settings.EMPTY); | ||
Settings indexSettings = Settings.builder() | ||
.put(remoteStoreIndexSettings(0, 1)) | ||
.put(INDEX_REMOTE_TRANSLOG_KEEP_EXTRA_GEN_SETTING.getKey(), 0) | ||
.build(); | ||
createIndex(INDEX_NAME, indexSettings); | ||
ensureYellowAndNoInitializingShards(INDEX_NAME); | ||
ensureGreen(INDEX_NAME); | ||
|
||
RemoteStoreSettings.setPinnedTimestampsLookbackInterval(TimeValue.ZERO); | ||
|
||
RemoteStorePinnedTimestampService remoteStorePinnedTimestampService = internalCluster().getInstance( | ||
RemoteStorePinnedTimestampService.class, | ||
primaryNodeName(INDEX_NAME) | ||
); | ||
|
||
remoteStorePinnedTimestampService.rescheduleAsyncUpdatePinnedTimestampTask(TimeValue.timeValueSeconds(1)); | ||
|
||
int numDocs = randomIntBetween(5, 10); | ||
for (int i = 0; i < numDocs; i++) { | ||
keepPinnedTimestampSchedulerUpdated(); | ||
indexSingleDoc(INDEX_NAME, true); | ||
} | ||
|
||
String translogPathFixedPrefix = RemoteStoreSettings.CLUSTER_REMOTE_STORE_TRANSLOG_PATH_PREFIX.get(getNodeSettings()); | ||
String shardDataPath = getShardLevelBlobPath(client(), INDEX_NAME, BlobPath.cleanPath(), "0", TRANSLOG, DATA, translogPathFixedPrefix) | ||
.buildAsString(); | ||
Path translogDataPath = Path.of(translogRepoPath + "/" + shardDataPath); | ||
String shardMetadataPath = getShardLevelBlobPath(client(), INDEX_NAME, BlobPath.cleanPath(), "0", TRANSLOG, METADATA, translogPathFixedPrefix) | ||
.buildAsString(); | ||
Path translogMetadataPath = Path.of(translogRepoPath + "/" + shardMetadataPath); | ||
|
||
assertBusy(() -> { | ||
assertEquals(1, Files.list(translogDataPath).collect(Collectors.toList()).size()); | ||
assertEquals(1, Files.list(translogMetadataPath).collect(Collectors.toList()).size()); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters