-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into snapshot-delete-opt…
…imisations Signed-off-by: Ashish Singh <[email protected]>
- Loading branch information
Showing
66 changed files
with
3,386 additions
and
674 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
72 changes: 72 additions & 0 deletions
72
rest-api-spec/src/main/resources/rest-api-spec/test/search/370_approximate_range.yml
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,72 @@ | ||
--- | ||
"search with approximate range": | ||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
mappings: | ||
properties: | ||
date: | ||
type: date | ||
index: true | ||
doc_values: true | ||
|
||
- do: | ||
bulk: | ||
index: test | ||
refresh: true | ||
body: | ||
- '{"index": {"_index": "test", "_id": "1" }}' | ||
- '{ "date": "2018-10-29T12:12:12.987Z" }' | ||
- '{ "index": { "_index": "test", "_id": "2" }}' | ||
- '{ "date": "2020-10-29T12:12:12.987Z" }' | ||
- '{ "index": { "_index": "test", "_id": "3" } }' | ||
- '{ "date": "2024-10-29T12:12:12.987Z" }' | ||
|
||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test | ||
body: | ||
query: | ||
range: { | ||
date: { | ||
gte: "2018-10-29T12:12:12.987Z" | ||
}, | ||
} | ||
|
||
- match: { hits.total: 3 } | ||
|
||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test | ||
body: | ||
sort: [{ date: asc }] | ||
query: | ||
range: { | ||
date: { | ||
gte: "2018-10-29T12:12:12.987Z" | ||
}, | ||
} | ||
|
||
|
||
- match: { hits.total: 3 } | ||
- match: { hits.hits.0._id: "1" } | ||
|
||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test | ||
body: | ||
sort: [{ date: desc }] | ||
query: | ||
range: { | ||
date: { | ||
gte: "2018-10-29T12:12:12.987Z", | ||
lte: "2020-10-29T12:12:12.987Z" | ||
}, | ||
} | ||
|
||
- match: { hits.total: 2 } | ||
- match: { hits.hits.0._id: "2" } |
129 changes: 129 additions & 0 deletions
129
...usterTest/java/org/opensearch/action/admin/cluster/shards/TransportCatShardsActionIT.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,129 @@ | ||
/* | ||
* 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.action.admin.cluster.shards; | ||
|
||
import org.opensearch.action.admin.cluster.state.ClusterStateResponse; | ||
import org.opensearch.action.admin.indices.stats.IndicesStatsResponse; | ||
import org.opensearch.cluster.metadata.IndexMetadata; | ||
import org.opensearch.cluster.routing.ShardRouting; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.unit.TimeValue; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.core.common.Strings; | ||
import org.opensearch.core.tasks.TaskCancelledException; | ||
import org.opensearch.test.InternalTestCluster; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.concurrent.CountDownLatch; | ||
|
||
import static org.opensearch.cluster.routing.UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING; | ||
import static org.opensearch.common.unit.TimeValue.timeValueMillis; | ||
import static org.opensearch.search.SearchService.NO_TIMEOUT; | ||
|
||
@OpenSearchIntegTestCase.ClusterScope(numDataNodes = 0, scope = OpenSearchIntegTestCase.Scope.TEST) | ||
public class TransportCatShardsActionIT extends OpenSearchIntegTestCase { | ||
|
||
public void testCatShardsWithSuccessResponse() throws InterruptedException { | ||
internalCluster().startClusterManagerOnlyNodes(1); | ||
List<String> nodes = internalCluster().startDataOnlyNodes(3); | ||
createIndex( | ||
"test", | ||
Settings.builder() | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2) | ||
.put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "60m") | ||
.build() | ||
); | ||
ensureGreen("test"); | ||
|
||
final CatShardsRequest shardsRequest = new CatShardsRequest(); | ||
shardsRequest.setCancelAfterTimeInterval(NO_TIMEOUT); | ||
shardsRequest.setIndices(Strings.EMPTY_ARRAY); | ||
CountDownLatch latch = new CountDownLatch(1); | ||
client().execute(CatShardsAction.INSTANCE, shardsRequest, new ActionListener<CatShardsResponse>() { | ||
@Override | ||
public void onResponse(CatShardsResponse catShardsResponse) { | ||
ClusterStateResponse clusterStateResponse = catShardsResponse.getClusterStateResponse(); | ||
IndicesStatsResponse indicesStatsResponse = catShardsResponse.getIndicesStatsResponse(); | ||
for (ShardRouting shard : clusterStateResponse.getState().routingTable().allShards()) { | ||
assertEquals("test", shard.getIndexName()); | ||
assertNotNull(indicesStatsResponse.asMap().get(shard)); | ||
} | ||
latch.countDown(); | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
fail(); | ||
latch.countDown(); | ||
} | ||
}); | ||
latch.await(); | ||
} | ||
|
||
public void testCatShardsWithTimeoutException() throws IOException, AssertionError, InterruptedException { | ||
List<String> masterNodes = internalCluster().startClusterManagerOnlyNodes(1); | ||
List<String> nodes = internalCluster().startDataOnlyNodes(3); | ||
createIndex( | ||
"test", | ||
Settings.builder() | ||
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2) | ||
.put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "60m") | ||
.build() | ||
); | ||
ensureGreen("test"); | ||
|
||
Settings clusterManagerDataPathSettings = internalCluster().dataPathSettings(masterNodes.get(0)); | ||
// Dropping master node to delay in cluster state call. | ||
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(0))); | ||
|
||
CountDownLatch latch = new CountDownLatch(2); | ||
new Thread(() -> { | ||
try { | ||
// Ensures the cancellation timeout expires. | ||
Thread.sleep(2000); | ||
// Starting master node to proceed in cluster state call. | ||
internalCluster().startClusterManagerOnlyNode( | ||
Settings.builder().put("node.name", masterNodes.get(0)).put(clusterManagerDataPathSettings).build() | ||
); | ||
latch.countDown(); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}).start(); | ||
|
||
final CatShardsRequest shardsRequest = new CatShardsRequest(); | ||
TimeValue timeoutInterval = timeValueMillis(1000); | ||
shardsRequest.setCancelAfterTimeInterval(timeoutInterval); | ||
shardsRequest.clusterManagerNodeTimeout(timeValueMillis(2500)); | ||
shardsRequest.setIndices(Strings.EMPTY_ARRAY); | ||
client().execute(CatShardsAction.INSTANCE, shardsRequest, new ActionListener<CatShardsResponse>() { | ||
@Override | ||
public void onResponse(CatShardsResponse catShardsResponse) { | ||
// onResponse should not be called. | ||
latch.countDown(); | ||
throw new AssertionError( | ||
"The cat shards action is expected to fail with a TaskCancelledException, but it received a successful response instead." | ||
); | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
assertSame(e.getClass(), TaskCancelledException.class); | ||
assertEquals(e.getMessage(), "Cancellation timeout of " + timeoutInterval + " is expired"); | ||
latch.countDown(); | ||
} | ||
}); | ||
latch.await(); | ||
} | ||
|
||
} |
Oops, something went wrong.