-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assign id to searcher using ids of segments (#66668)
The commit id introduced in #63963 does not work well with searchable snapshots as we create a new index commit when restoring from snapshots. This change revises an approach that generates an id using the ids of the segments of an index commit. Relates #63963
- Loading branch information
Showing
9 changed files
with
208 additions
and
30 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
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
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
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
95 changes: 95 additions & 0 deletions
95
...alClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/RetrySearchIntegTests.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,95 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.searchablesnapshots; | ||
|
||
import org.elasticsearch.action.index.IndexRequestBuilder; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.IndexService; | ||
import org.elasticsearch.index.engine.Engine; | ||
import org.elasticsearch.index.shard.IndexShard; | ||
import org.elasticsearch.indices.IndicesService; | ||
import org.elasticsearch.snapshots.SnapshotId; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Set; | ||
|
||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class RetrySearchIntegTests extends BaseSearchableSnapshotsIntegTestCase { | ||
|
||
public void testSearcherId() throws Exception { | ||
final String indexName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); | ||
final int numberOfShards = between(1, 5); | ||
assertAcked( | ||
client().admin() | ||
.indices() | ||
.prepareCreate(indexName) | ||
.setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numberOfShards).build()) | ||
.setMapping("{\"properties\":{\"created_date\":{\"type\": \"date\", \"format\": \"yyyy-MM-dd\"}}}") | ||
); | ||
final List<IndexRequestBuilder> indexRequestBuilders = new ArrayList<>(); | ||
final int docCount = between(0, 100); | ||
for (int i = 0; i < docCount; i++) { | ||
indexRequestBuilders.add(client().prepareIndex(indexName).setSource("created_date", "2011-02-02")); | ||
} | ||
indexRandom(true, false, indexRequestBuilders); | ||
assertThat( | ||
client().admin().indices().prepareForceMerge(indexName).setOnlyExpungeDeletes(true).setFlush(true).get().getFailedShards(), | ||
equalTo(0) | ||
); | ||
refresh(indexName); | ||
forceMerge(); | ||
|
||
final String repositoryName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); | ||
createRepository(repositoryName, "fs"); | ||
|
||
final SnapshotId snapshotOne = createSnapshot(repositoryName, "snapshot-1", List.of(indexName)).snapshotId(); | ||
assertAcked(client().admin().indices().prepareDelete(indexName)); | ||
|
||
final int numberOfReplicas = between(0, 2); | ||
final Settings indexSettings = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, numberOfReplicas).build(); | ||
internalCluster().ensureAtLeastNumDataNodes(numberOfReplicas + 1); | ||
mountSnapshot(repositoryName, snapshotOne.getName(), indexName, indexName, indexSettings); | ||
ensureGreen(indexName); | ||
|
||
final String[] searcherIds = new String[numberOfShards]; | ||
Set<String> allocatedNodes = internalCluster().nodesInclude(indexName); | ||
for (String node : allocatedNodes) { | ||
IndexService indexService = internalCluster().getInstance(IndicesService.class, node).indexServiceSafe(resolveIndex(indexName)); | ||
for (IndexShard indexShard : indexService) { | ||
try (Engine.SearcherSupplier searcher = indexShard.acquireSearcherSupplier()) { | ||
assertNotNull(searcher.getSearcherId()); | ||
if (searcherIds[indexShard.shardId().id()] != null) { | ||
assertThat(searcher.getSearcherId(), equalTo(searcherIds[indexShard.shardId().id()])); | ||
} else { | ||
searcherIds[indexShard.shardId().id()] = searcher.getSearcherId(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
for (String allocatedNode : allocatedNodes) { | ||
if (randomBoolean()) { | ||
internalCluster().restartNode(allocatedNode); | ||
} | ||
} | ||
ensureGreen(indexName); | ||
allocatedNodes = internalCluster().nodesInclude(indexName); | ||
for (String node : allocatedNodes) { | ||
IndexService indexService = internalCluster().getInstance(IndicesService.class, node).indexServiceSafe(resolveIndex(indexName)); | ||
for (IndexShard indexShard : indexService) { | ||
try (Engine.SearcherSupplier searcher = indexShard.acquireSearcherSupplier()) { | ||
assertNotNull(searcher.getSearcherId()); | ||
assertThat(searcher.getSearcherId(), equalTo(searcherIds[indexShard.shardId().id()])); | ||
} | ||
} | ||
} | ||
} | ||
} |