-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport 2.x] [Remote Translog] Trimming based on Remote Segment Sto…
…re (#7383) (#7699) * [Remote Translog] Trimming based on Remote Segment Store (#7383) * [Remote Translog] Set min referenced as per remote segment store only when enabled. Add IT for failover using remote translog as well Signed-off-by: Gaurav Bafna <[email protected]> Signed-off-by: Ashish Singh <[email protected]>
- Loading branch information
Showing
13 changed files
with
307 additions
and
63 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
codecov: | ||
require_ci_to_pass: yes | ||
|
||
ignore: | ||
- "test" | ||
|
||
coverage: | ||
precision: 2 | ||
round: down | ||
|
76 changes: 76 additions & 0 deletions
76
server/src/internalClusterTest/java/org/opensearch/remotestore/RemoteStoreBaseIT.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,76 @@ | ||
/* | ||
* 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.junit.After; | ||
import org.junit.Before; | ||
import org.opensearch.cluster.metadata.IndexMetadata; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.util.FeatureFlags; | ||
import org.opensearch.index.IndexModule; | ||
import org.opensearch.index.IndexSettings; | ||
import org.opensearch.indices.replication.common.ReplicationType; | ||
import org.opensearch.plugins.Plugin; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
import org.opensearch.test.transport.MockTransportService; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; | ||
|
||
public class RemoteStoreBaseIT extends OpenSearchIntegTestCase { | ||
protected static final String REPOSITORY_NAME = "test-remore-store-repo"; | ||
protected static final int SHARD_COUNT = 1; | ||
protected static final int REPLICA_COUNT = 1; | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return asList(MockTransportService.TestPlugin.class); | ||
} | ||
|
||
@Override | ||
protected boolean addMockInternalEngine() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected Settings featureFlagSettings() { | ||
return Settings.builder().put(super.featureFlagSettings()).put(FeatureFlags.REMOTE_STORE, "true").build(); | ||
} | ||
|
||
public Settings indexSettings() { | ||
return Settings.builder() | ||
.put(super.indexSettings()) | ||
.put(IndexModule.INDEX_QUERY_CACHE_ENABLED_SETTING.getKey(), false) | ||
.put(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, true) | ||
.put(IndexMetadata.SETTING_REMOTE_STORE_REPOSITORY, REPOSITORY_NAME) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, SHARD_COUNT) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, REPLICA_COUNT) | ||
.put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), "300s") | ||
.put(IndexMetadata.SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT) | ||
.build(); | ||
} | ||
|
||
@Before | ||
public void setup() { | ||
internalCluster().startClusterManagerOnlyNode(); | ||
Path absolutePath = randomRepoPath().toAbsolutePath(); | ||
assertAcked( | ||
clusterAdmin().preparePutRepository(REPOSITORY_NAME).setType("fs").setSettings(Settings.builder().put("location", absolutePath)) | ||
); | ||
} | ||
|
||
@After | ||
public void teardown() { | ||
assertAcked(clusterAdmin().prepareDeleteRepository(REPOSITORY_NAME)); | ||
} | ||
|
||
} |
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
118 changes: 118 additions & 0 deletions
118
.../src/internalClusterTest/java/org/opensearch/remotestore/ReplicaToPrimaryPromotionIT.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,118 @@ | ||
/* | ||
* 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 com.carrotsearch.randomizedtesting.RandomizedTest; | ||
import org.opensearch.action.admin.indices.close.CloseIndexResponse; | ||
import org.opensearch.cluster.ClusterState; | ||
import org.opensearch.cluster.metadata.IndexMetadata; | ||
import org.opensearch.cluster.node.DiscoveryNode; | ||
import org.opensearch.cluster.routing.IndexShardRoutingTable; | ||
import org.opensearch.cluster.routing.ShardRouting; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.test.BackgroundIndexer; | ||
import org.opensearch.test.InternalTestCluster; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
|
||
import java.util.Locale; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; | ||
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount; | ||
|
||
@OpenSearchIntegTestCase.ClusterScope(numDataNodes = 0) | ||
public class ReplicaToPrimaryPromotionIT extends RemoteStoreBaseIT { | ||
private int shard_count = 5; | ||
|
||
@Override | ||
public Settings indexSettings() { | ||
return Settings.builder() | ||
.put(super.indexSettings()) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, shard_count) | ||
.put(IndexMetadata.SETTING_REMOTE_TRANSLOG_STORE_ENABLED, true) | ||
.put(IndexMetadata.SETTING_REMOTE_TRANSLOG_STORE_REPOSITORY, REPOSITORY_NAME) | ||
.build(); | ||
} | ||
|
||
public void testPromoteReplicaToPrimary() throws Exception { | ||
internalCluster().startNode(); | ||
internalCluster().startNode(); | ||
final String indexName = randomAlphaOfLength(5).toLowerCase(Locale.ROOT); | ||
shard_count = scaledRandomIntBetween(1, 5); | ||
createIndex(indexName); | ||
int numOfDocs = 0; | ||
int numIter = scaledRandomIntBetween(0, 10); | ||
for (int i = 0; i < numIter; i++) { | ||
final int numOfDoc = scaledRandomIntBetween(0, 200); | ||
logger.info("num of docs in iter {} {}", numOfDoc, i); | ||
if (numOfDoc > 0) { | ||
try ( | ||
BackgroundIndexer indexer = new BackgroundIndexer( | ||
indexName, | ||
"_doc", | ||
client(), | ||
numOfDoc, | ||
RandomizedTest.scaledRandomIntBetween(2, 5), | ||
false, | ||
null | ||
) | ||
) { | ||
indexer.setUseAutoGeneratedIDs(true); | ||
indexer.start(numOfDoc); | ||
waitForIndexed(numOfDoc, indexer); | ||
numOfDocs += numOfDoc; | ||
indexer.stopAndAwaitStopped(); | ||
if (random().nextBoolean()) { | ||
// 90% refresh + 10% flush | ||
if (random().nextInt(10) != 0) { | ||
refresh(indexName); | ||
} else { | ||
flush(indexName); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
ensureGreen(indexName); | ||
|
||
// sometimes test with a closed index | ||
final IndexMetadata.State indexState = randomFrom(IndexMetadata.State.OPEN, IndexMetadata.State.CLOSE); | ||
if (indexState == IndexMetadata.State.CLOSE) { | ||
CloseIndexResponse closeIndexResponse = client().admin().indices().prepareClose(indexName).get(); | ||
assertThat("close index not acked - " + closeIndexResponse, closeIndexResponse.isAcknowledged(), equalTo(true)); | ||
ensureGreen(indexName); | ||
} | ||
|
||
// pick up a data node that contains a random primary shard | ||
ClusterState state = client(internalCluster().getClusterManagerName()).admin().cluster().prepareState().get().getState(); | ||
final int numShards = state.metadata().index(indexName).getNumberOfShards(); | ||
final ShardRouting primaryShard = state.routingTable().index(indexName).shard(randomIntBetween(0, numShards - 1)).primaryShard(); | ||
final DiscoveryNode randomNode = state.nodes().resolveNode(primaryShard.currentNodeId()); | ||
|
||
// stop the random data node, all remaining shards are promoted to primaries | ||
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(randomNode.getName())); | ||
ensureYellowAndNoInitializingShards(indexName); | ||
|
||
state = client(internalCluster().getClusterManagerName()).admin().cluster().prepareState().get().getState(); | ||
for (IndexShardRoutingTable shardRoutingTable : state.routingTable().index(indexName)) { | ||
for (ShardRouting shardRouting : shardRoutingTable.activeShards()) { | ||
assertThat(shardRouting + " should be promoted as a primary", shardRouting.primary(), is(true)); | ||
} | ||
} | ||
|
||
if (indexState == IndexMetadata.State.CLOSE) { | ||
assertAcked(client().admin().indices().prepareOpen(indexName)); | ||
ensureYellowAndNoInitializingShards(indexName); | ||
} | ||
refresh(indexName); | ||
assertHitCount(client().prepareSearch(indexName).setSize(0).get(), numOfDocs); | ||
} | ||
} |
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
Oops, something went wrong.