Skip to content

Commit bba8f04

Browse files
authored
Merge branch 'main' into fix_uploaded_metadata
Signed-off-by: Sooraj Sinha <[email protected]>
2 parents e9288b4 + 66f0110 commit bba8f04

File tree

12 files changed

+133
-24
lines changed

12 files changed

+133
-24
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8585
- Streaming bulk request hangs ([#16158](https://github.com/opensearch-project/OpenSearch/pull/16158))
8686
- Fix warnings from SLF4J on startup when repository-s3 is installed ([#16194](https://github.com/opensearch-project/OpenSearch/pull/16194))
8787
- Fix protobuf-java leak through client library dependencies ([#16254](https://github.com/opensearch-project/OpenSearch/pull/16254))
88+
- Fix get index settings API doesn't show `number_of_routing_shards` setting when it was explicitly set ([#16294](https://github.com/opensearch-project/OpenSearch/pull/16294))
8889
- Fix multi-search with template doesn't return status code ([#16265](https://github.com/opensearch-project/OpenSearch/pull/16265))
8990
- [Streaming Indexing] Fix intermittent 'The bulk request must be terminated by a newline [\n]' failures [#16337](https://github.com/opensearch-project/OpenSearch/pull/16337))
9091
- Fix wrong default value when setting `index.number_of_routing_shards` to null on index creation ([#16331](https://github.com/opensearch-project/OpenSearch/pull/16331))
@@ -96,6 +97,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
9697
- Fix typo super->sb in method toString() of RemoteStoreNodeAttribute ([#15362](https://github.com/opensearch-project/OpenSearch/pull/15362))
9798
- [Workload Management] Fixing Create/Update QueryGroup TransportActions to execute from non-cluster manager nodes ([16422](https://github.com/opensearch-project/OpenSearch/pull/16422))
9899
- Revert changes to upload remote state manifest using minimum codec version([#16403](https://github.com/opensearch-project/OpenSearch/pull/16403))
100+
- Fix flaky test in `testApproximateRangeWithSizeOverDefault` by adjusting totalHits assertion logic ([#16434](https://github.com/opensearch-project/OpenSearch/pull/16434#pullrequestreview-2386999409))
99101

100102
### Security
101103

modules/transport-netty4/src/main/java/org/opensearch/transport/netty4/ssl/SecureNetty4Transport.java

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ protected void initChannel(Channel ch) throws Exception {
146146
.map(SecureTransportSettingsProvider.SecureTransportParameters::dualModeEnabled)
147147
.orElse(false);
148148
if (dualModeEnabled) {
149+
logger.info("SSL Dual mode enabled, using port unification handler");
149150
final ChannelHandler portUnificationHandler = new DualModeSslHandler(
150151
settings,
151152
secureTransportSettingsProvider,

qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/ClusterStatsIT.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public class ClusterStatsIT extends AbstractRollingTestCase {
2626
public void testClusterStats() throws IOException {
2727
Response response = client().performRequest(new Request("GET", "/_cluster/stats"));
2828
validateClusterStatsWithFilterResponse(response, nodeStatsMetrics, indicesStatsMetrics);
29-
if (AbstractRollingTestCase.UPGRADE_FROM_VERSION.onOrAfter(Version.V_3_0_0) || (
30-
CLUSTER_TYPE == ClusterType.UPGRADED && Version.CURRENT.onOrAfter(Version.V_3_0_0))) {
29+
if (AbstractRollingTestCase.UPGRADE_FROM_VERSION.onOrAfter(Version.V_2_18_0) || (
30+
CLUSTER_TYPE == ClusterType.UPGRADED && Version.CURRENT.onOrAfter(Version.V_2_18_0))) {
3131
response = client().performRequest(new Request("GET", "/_cluster/stats/os/nodes/_all"));
3232
validateClusterStatsWithFilterResponse(response, List.of("os"), Collections.emptyList());
3333
response = client().performRequest(new Request("GET", "/_cluster/stats/indices/mappings/nodes/_all"));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
setup:
3+
- do:
4+
indices.create:
5+
body:
6+
settings:
7+
index:
8+
number_of_routing_shards: 4
9+
number_of_shards: 2
10+
number_of_replicas: 1
11+
index: test-index
12+
13+
- do:
14+
indices.create:
15+
body:
16+
settings:
17+
index:
18+
number_of_shards: 2
19+
number_of_replicas: 1
20+
index: test-index1
21+
22+
---
23+
Test retrieval of number_routing_shards settings:
24+
- skip:
25+
version: " - 2.99.99"
26+
reason: "introduced in 3.0.0" # TODO: change it to 2.18.0 after backport to 2.x branch
27+
- do:
28+
indices.get_settings:
29+
flat_settings: true
30+
index: test-index
31+
# show `index.number_of_routing_shards` if it was explicitly set when creating
32+
- match:
33+
test-index.settings.index\.number_of_routing_shards: "4"
34+
35+
- do:
36+
indices.get_settings:
37+
flat_settings: true
38+
index: test-index1
39+
# do not show `index.number_of_routing_shards` if it was not explicitly set when creating
40+
- match:
41+
test-index1.settings.index\.number_of_routing_shards: null

server/src/main/java/org/opensearch/action/admin/cluster/shards/TransportCatShardsAction.java

+10
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ public void onResponse(ClusterStateResponse clusterStateResponse) {
108108
: paginationStrategy.getRequestedEntities()
109109
);
110110
catShardsResponse.setPageToken(Objects.isNull(paginationStrategy) ? null : paginationStrategy.getResponseToken());
111+
// For paginated queries, if strategy outputs no shards to be returned, avoid fetching IndicesStats.
112+
if (shouldSkipIndicesStatsRequest(paginationStrategy)) {
113+
catShardsResponse.setIndicesStatsResponse(IndicesStatsResponse.getEmptyResponse());
114+
cancellableListener.onResponse(catShardsResponse);
115+
return;
116+
}
111117
IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
112118
indicesStatsRequest.setShouldCancelOnTimeout(true);
113119
indicesStatsRequest.all();
@@ -159,4 +165,8 @@ private void validateRequestLimit(
159165
}
160166
}
161167
}
168+
169+
private boolean shouldSkipIndicesStatsRequest(ShardPaginationStrategy paginationStrategy) {
170+
return Objects.nonNull(paginationStrategy) && paginationStrategy.getRequestedEntities().isEmpty();
171+
}
162172
}

server/src/main/java/org/opensearch/action/admin/cluster/stats/ClusterStatsRequest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public ClusterStatsRequest(StreamInput in) throws IOException {
5959
if (in.getVersion().onOrAfter(Version.V_2_16_0)) {
6060
useAggregatedNodeLevelResponses = in.readOptionalBoolean();
6161
}
62-
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
62+
if (in.getVersion().onOrAfter(Version.V_2_18_0)) {
6363
computeAllMetrics = in.readOptionalBoolean();
6464
final long longMetricsFlags = in.readLong();
6565
for (Metric metric : Metric.values()) {
@@ -135,7 +135,7 @@ public void writeTo(StreamOutput out) throws IOException {
135135
if (out.getVersion().onOrAfter(Version.V_2_16_0)) {
136136
out.writeOptionalBoolean(useAggregatedNodeLevelResponses);
137137
}
138-
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
138+
if (out.getVersion().onOrAfter(Version.V_2_18_0)) {
139139
out.writeOptionalBoolean(computeAllMetrics);
140140
long longMetricFlags = 0;
141141
for (Metric metric : requestedMetrics) {
@@ -154,7 +154,7 @@ public void writeTo(StreamOutput out) throws IOException {
154154
* An enumeration of the "core" sections of metrics that may be requested
155155
* from the cluster stats endpoint.
156156
*/
157-
@PublicApi(since = "3.0.0")
157+
@PublicApi(since = "2.18.0")
158158
public enum Metric {
159159
OS("os", 0),
160160
JVM("jvm", 1),
@@ -192,7 +192,7 @@ public int getIndex() {
192192
*
193193
* When no value is provided for param index_metric, default filter is set to _all.
194194
*/
195-
@PublicApi(since = "3.0.0")
195+
@PublicApi(since = "2.18.0")
196196
public enum IndexMetric {
197197
// Metrics computed from ShardStats
198198
SHARDS("shards", 0),

server/src/main/java/org/opensearch/action/admin/indices/stats/IndicesStatsResponse.java

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.opensearch.core.xcontent.XContentBuilder;
4646

4747
import java.io.IOException;
48+
import java.util.Collections;
4849
import java.util.HashMap;
4950
import java.util.List;
5051
import java.util.Map;
@@ -230,4 +231,8 @@ static final class Fields {
230231
public String toString() {
231232
return Strings.toString(MediaTypeRegistry.JSON, this, true, false);
232233
}
234+
235+
public static IndicesStatsResponse getEmptyResponse() {
236+
return new IndicesStatsResponse(new ShardStats[0], 0, 0, 0, Collections.emptyList());
237+
}
233238
}

server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ public Iterator<Setting<?>> settings() {
300300
}
301301

302302
},
303-
Property.IndexScope
303+
Property.IndexScope,
304+
Property.NotCopyableOnResize
304305
);
305306

306307
/**

server/src/main/java/org/opensearch/cluster/metadata/MetadataCreateIndexService.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -626,14 +626,9 @@ IndexMetadata buildAndValidateTemporaryIndexMetadata(
626626
final boolean isHiddenAfterTemplates = IndexMetadata.INDEX_HIDDEN_SETTING.get(aggregatedIndexSettings);
627627
final boolean isSystem = validateDotIndex(request.index(), isHiddenAfterTemplates);
628628

629-
// remove the setting it's temporary and is only relevant once we create the index
630-
final Settings.Builder settingsBuilder = Settings.builder().put(aggregatedIndexSettings);
631-
settingsBuilder.remove(IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.getKey());
632-
final Settings indexSettings = settingsBuilder.build();
633-
634629
final IndexMetadata.Builder tmpImdBuilder = IndexMetadata.builder(request.index());
635630
tmpImdBuilder.setRoutingNumShards(routingNumShards);
636-
tmpImdBuilder.settings(indexSettings);
631+
tmpImdBuilder.settings(aggregatedIndexSettings);
637632
tmpImdBuilder.system(isSystem);
638633
addRemoteStoreCustomMetadata(tmpImdBuilder, true);
639634

server/src/main/java/org/opensearch/rest/action/cat/RestIndicesAction.java

+17-7
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,19 @@ public void onResponse(ClusterStateResponse clusterStateResponse) {
212212
groupedListener.onResponse(getSettingsResponse);
213213
groupedListener.onResponse(clusterStateResponse);
214214

215-
sendIndicesStatsRequest(
216-
indicesToBeQueried,
217-
subRequestIndicesOptions,
218-
includeUnloadedSegments,
219-
client,
220-
ActionListener.wrap(groupedListener::onResponse, groupedListener::onFailure)
221-
);
215+
// For paginated queries, if strategy outputs no indices to be returned,
216+
// avoid fetching indices stats.
217+
if (shouldSkipIndicesStatsRequest(paginationStrategy)) {
218+
groupedListener.onResponse(IndicesStatsResponse.getEmptyResponse());
219+
} else {
220+
sendIndicesStatsRequest(
221+
indicesToBeQueried,
222+
subRequestIndicesOptions,
223+
includeUnloadedSegments,
224+
client,
225+
ActionListener.wrap(groupedListener::onResponse, groupedListener::onFailure)
226+
);
227+
}
222228

223229
sendClusterHealthRequest(
224230
indicesToBeQueried,
@@ -1093,4 +1099,8 @@ public Tuple<String, Settings> next() {
10931099
};
10941100
}
10951101

1102+
private boolean shouldSkipIndicesStatsRequest(IndexPaginationStrategy paginationStrategy) {
1103+
return Objects.nonNull(paginationStrategy) && paginationStrategy.getRequestedEntities().isEmpty();
1104+
}
1105+
10961106
}

server/src/test/java/org/opensearch/cluster/metadata/MetadataCreateIndexServiceTests.java

+37
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
import static java.util.Collections.emptyMap;
137137
import static java.util.Collections.singleton;
138138
import static java.util.Collections.singletonList;
139+
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING;
139140
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING;
140141
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING;
141142
import static org.opensearch.cluster.metadata.IndexMetadata.INDEX_READ_ONLY_BLOCK;
@@ -1821,6 +1822,42 @@ private void validateRemoteCustomData(Map<String, String> customData, String exp
18211822
assertEquals(expectedValue, customData.get(expectedKey));
18221823
}
18231824

1825+
public void testNumberOfRoutingShardsShowsInIndexSettings() {
1826+
withTemporaryClusterService(((clusterService, threadPool) -> {
1827+
MetadataCreateIndexService checkerService = new MetadataCreateIndexService(
1828+
Settings.EMPTY,
1829+
clusterService,
1830+
indicesServices,
1831+
null,
1832+
null,
1833+
createTestShardLimitService(randomIntBetween(1, 1000), false, clusterService),
1834+
null,
1835+
null,
1836+
threadPool,
1837+
null,
1838+
new SystemIndices(Collections.emptyMap()),
1839+
false,
1840+
new AwarenessReplicaBalance(Settings.EMPTY, clusterService.getClusterSettings()),
1841+
DefaultRemoteStoreSettings.INSTANCE,
1842+
repositoriesServiceSupplier
1843+
);
1844+
final int routingNumberOfShards = 4;
1845+
Settings indexSettings = Settings.builder()
1846+
.put("index.version.created", Version.CURRENT)
1847+
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 2)
1848+
.put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0)
1849+
.put(INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.getKey(), routingNumberOfShards)
1850+
.build();
1851+
CreateIndexClusterStateUpdateRequest request = new CreateIndexClusterStateUpdateRequest("create index", "test", "test");
1852+
IndexMetadata indexMetadata = checkerService.buildAndValidateTemporaryIndexMetadata(
1853+
indexSettings,
1854+
request,
1855+
routingNumberOfShards
1856+
);
1857+
assertEquals(INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.get(indexMetadata.getSettings()).intValue(), routingNumberOfShards);
1858+
}));
1859+
}
1860+
18241861
public void testGetIndexNumberOfRoutingShardsWithNullSourceIndex() {
18251862
Settings indexSettings = Settings.builder()
18261863
.put("index.version.created", Version.CURRENT)

server/src/test/java/org/opensearch/search/approximate/ApproximatePointRangeQueryTests.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.lucene.search.SortField;
2222
import org.apache.lucene.search.TopDocs;
2323
import org.apache.lucene.search.TotalHits;
24+
import org.apache.lucene.search.TotalHits.Relation;
2425
import org.apache.lucene.store.Directory;
2526
import org.apache.lucene.tests.index.RandomIndexWriter;
2627
import org.opensearch.search.internal.SearchContext;
@@ -175,6 +176,7 @@ public void testApproximateRangeWithSizeOverDefault() throws IOException {
175176
try {
176177
long lower = 0;
177178
long upper = 12000;
179+
long maxHits = 12001;
178180
Query approximateQuery = new ApproximatePointRangeQuery(
179181
"point",
180182
pack(lower).bytes,
@@ -188,7 +190,13 @@ protected String toString(int dimension, byte[] value) {
188190
};
189191
IndexSearcher searcher = new IndexSearcher(reader);
190192
TopDocs topDocs = searcher.search(approximateQuery, 11000);
191-
assertEquals(topDocs.totalHits, new TotalHits(11000, TotalHits.Relation.EQUAL_TO));
193+
194+
if (topDocs.totalHits.relation == Relation.EQUAL_TO) {
195+
assertEquals(topDocs.totalHits.value, 11000);
196+
} else {
197+
assertTrue(11000 <= topDocs.totalHits.value);
198+
assertTrue(maxHits >= topDocs.totalHits.value);
199+
}
192200
} catch (IOException e) {
193201
throw new RuntimeException(e);
194202
}
@@ -226,7 +234,7 @@ protected String toString(int dimension, byte[] value) {
226234
}
227235
};
228236
Query query = LongPoint.newRangeQuery("point", lower, upper);
229-
;
237+
230238
IndexSearcher searcher = new IndexSearcher(reader);
231239
TopDocs topDocs = searcher.search(approximateQuery, 10);
232240
TopDocs topDocs1 = searcher.search(query, 10);
@@ -235,7 +243,6 @@ protected String toString(int dimension, byte[] value) {
235243
assertNotEquals(topDocs.totalHits, topDocs1.totalHits);
236244
assertEquals(topDocs.totalHits, new TotalHits(10, TotalHits.Relation.EQUAL_TO));
237245
assertEquals(topDocs1.totalHits, new TotalHits(101, TotalHits.Relation.EQUAL_TO));
238-
239246
} catch (IOException e) {
240247
throw new RuntimeException(e);
241248
}
@@ -278,7 +285,7 @@ protected String toString(int dimension, byte[] value) {
278285
}
279286
};
280287
Query query = LongPoint.newRangeQuery("point", lower, upper);
281-
;
288+
282289
IndexSearcher searcher = new IndexSearcher(reader);
283290
Sort sort = new Sort(new SortField("point", SortField.Type.LONG));
284291
TopDocs topDocs = searcher.search(approximateQuery, 10, sort);

0 commit comments

Comments
 (0)