Skip to content

Commit 7694036

Browse files
authored
Merge branch '2.x' into backport/backport-14454-to-2.x
Signed-off-by: Pranshu Shukla <55992439+Pranshu-S@users.noreply.github.com>
2 parents 092397a + 834b7c1 commit 7694036

File tree

94 files changed

+6375
-1082
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+6375
-1082
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
3535
- Adding translog durability validation in index templates ([#15494](https://github.com/opensearch-project/OpenSearch/pull/15494))
3636
- [Workload Management] Add query group level failure tracking ([#15227](https://github.com/opensearch-project/OpenSearch/pull/15527))
3737
- [Reader Writer Separation] Add searchOnly replica routing configuration ([#15410](https://github.com/opensearch-project/OpenSearch/pull/15410))
38+
- Add index creation using the context field ([#15290](https://github.com/opensearch-project/OpenSearch/pull/15290))
39+
- [Remote Publication] Add remote download stats ([#15291](https://github.com/opensearch-project/OpenSearch/pull/15291)))
3840
- Optimize NodeIndicesStats output behind flag ([#14454](https://github.com/opensearch-project/OpenSearch/pull/14454))
3941

4042
### Dependencies

client/rest-high-level/src/main/java/org/opensearch/client/indices/GetIndexResponse.java

+25-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import org.apache.lucene.util.CollectionUtil;
3636
import org.opensearch.cluster.metadata.AliasMetadata;
37+
import org.opensearch.cluster.metadata.Context;
3738
import org.opensearch.cluster.metadata.MappingMetadata;
3839
import org.opensearch.common.settings.Settings;
3940
import org.opensearch.core.xcontent.XContentParser;
@@ -61,6 +62,7 @@ public class GetIndexResponse {
6162
private Map<String, Settings> settings;
6263
private Map<String, Settings> defaultSettings;
6364
private Map<String, String> dataStreams;
65+
private Map<String, Context> contexts;
6466
private String[] indices;
6567

6668
GetIndexResponse(
@@ -69,7 +71,8 @@ public class GetIndexResponse {
6971
Map<String, List<AliasMetadata>> aliases,
7072
Map<String, Settings> settings,
7173
Map<String, Settings> defaultSettings,
72-
Map<String, String> dataStreams
74+
Map<String, String> dataStreams,
75+
Map<String, Context> contexts
7376
) {
7477
this.indices = indices;
7578
// to have deterministic order
@@ -89,6 +92,9 @@ public class GetIndexResponse {
8992
if (dataStreams != null) {
9093
this.dataStreams = dataStreams;
9194
}
95+
if (contexts != null) {
96+
this.contexts = contexts;
97+
}
9298
}
9399

94100
public String[] getIndices() {
@@ -123,6 +129,10 @@ public Map<String, String> getDataStreams() {
123129
return dataStreams;
124130
}
125131

132+
public Map<String, Context> contexts() {
133+
return contexts;
134+
}
135+
126136
/**
127137
* Returns the string value for the specified index and setting. If the includeDefaults flag was not set or set to
128138
* false on the {@link GetIndexRequest}, this method will only return a value where the setting was explicitly set
@@ -167,6 +177,7 @@ private static IndexEntry parseIndexEntry(XContentParser parser) throws IOExcept
167177
Settings indexSettings = null;
168178
Settings indexDefaultSettings = null;
169179
String dataStream = null;
180+
Context context = null;
170181
// We start at START_OBJECT since fromXContent ensures that
171182
while (parser.nextToken() != Token.END_OBJECT) {
172183
ensureExpectedToken(Token.FIELD_NAME, parser.currentToken(), parser);
@@ -185,6 +196,9 @@ private static IndexEntry parseIndexEntry(XContentParser parser) throws IOExcept
185196
case "defaults":
186197
indexDefaultSettings = Settings.fromXContent(parser);
187198
break;
199+
case "context":
200+
context = Context.fromXContent(parser);
201+
break;
188202
default:
189203
parser.skipChildren();
190204
}
@@ -197,7 +211,7 @@ private static IndexEntry parseIndexEntry(XContentParser parser) throws IOExcept
197211
parser.skipChildren();
198212
}
199213
}
200-
return new IndexEntry(indexAliases, indexMappings, indexSettings, indexDefaultSettings, dataStream);
214+
return new IndexEntry(indexAliases, indexMappings, indexSettings, indexDefaultSettings, dataStream, context);
201215
}
202216

203217
// This is just an internal container to make stuff easier for returning
@@ -207,19 +221,22 @@ private static class IndexEntry {
207221
Settings indexSettings = Settings.EMPTY;
208222
Settings indexDefaultSettings = Settings.EMPTY;
209223
String dataStream;
224+
Context context;
210225

211226
IndexEntry(
212227
List<AliasMetadata> indexAliases,
213228
MappingMetadata indexMappings,
214229
Settings indexSettings,
215230
Settings indexDefaultSettings,
216-
String dataStream
231+
String dataStream,
232+
Context context
217233
) {
218234
if (indexAliases != null) this.indexAliases = indexAliases;
219235
if (indexMappings != null) this.indexMappings = indexMappings;
220236
if (indexSettings != null) this.indexSettings = indexSettings;
221237
if (indexDefaultSettings != null) this.indexDefaultSettings = indexDefaultSettings;
222238
if (dataStream != null) this.dataStream = dataStream;
239+
if (context != null) this.context = context;
223240
}
224241
}
225242

@@ -229,6 +246,7 @@ public static GetIndexResponse fromXContent(XContentParser parser) throws IOExce
229246
Map<String, Settings> settings = new HashMap<>();
230247
Map<String, Settings> defaultSettings = new HashMap<>();
231248
Map<String, String> dataStreams = new HashMap<>();
249+
Map<String, Context> contexts = new HashMap<>();
232250
List<String> indices = new ArrayList<>();
233251

234252
if (parser.currentToken() == null) {
@@ -254,12 +272,15 @@ public static GetIndexResponse fromXContent(XContentParser parser) throws IOExce
254272
if (indexEntry.dataStream != null) {
255273
dataStreams.put(indexName, indexEntry.dataStream);
256274
}
275+
if (indexEntry.context != null) {
276+
contexts.put(indexName, indexEntry.context);
277+
}
257278
} else if (parser.currentToken() == Token.START_ARRAY) {
258279
parser.skipChildren();
259280
} else {
260281
parser.nextToken();
261282
}
262283
}
263-
return new GetIndexResponse(indices.toArray(new String[0]), mappings, aliases, settings, defaultSettings, dataStreams);
284+
return new GetIndexResponse(indices.toArray(new String[0]), mappings, aliases, settings, defaultSettings, dataStreams, contexts);
264285
}
265286
}

client/rest-high-level/src/test/java/org/opensearch/client/indices/GetIndexResponseTests.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.opensearch.client.AbstractResponseTestCase;
3737
import org.opensearch.client.GetAliasesResponseTests;
3838
import org.opensearch.cluster.metadata.AliasMetadata;
39+
import org.opensearch.cluster.metadata.Context;
3940
import org.opensearch.cluster.metadata.MappingMetadata;
4041
import org.opensearch.common.settings.IndexScopedSettings;
4142
import org.opensearch.common.settings.Settings;
@@ -66,6 +67,7 @@ protected org.opensearch.action.admin.indices.get.GetIndexResponse createServerT
6667
final Map<String, Settings> settings = new HashMap<>();
6768
final Map<String, Settings> defaultSettings = new HashMap<>();
6869
final Map<String, String> dataStreams = new HashMap<>();
70+
final Map<String, Context> contexts = new HashMap<>();
6971
IndexScopedSettings indexScopedSettings = IndexScopedSettings.DEFAULT_SCOPED_SETTINGS;
7072
boolean includeDefaults = randomBoolean();
7173
for (String index : indices) {
@@ -90,14 +92,19 @@ protected org.opensearch.action.admin.indices.get.GetIndexResponse createServerT
9092
if (randomBoolean()) {
9193
dataStreams.put(index, randomAlphaOfLength(5).toLowerCase(Locale.ROOT));
9294
}
95+
96+
if (randomBoolean()) {
97+
contexts.put(index, new Context(randomAlphaOfLength(5).toLowerCase(Locale.ROOT)));
98+
}
9399
}
94100
return new org.opensearch.action.admin.indices.get.GetIndexResponse(
95101
indices,
96102
mappings,
97103
aliases,
98104
settings,
99105
defaultSettings,
100-
dataStreams
106+
dataStreams,
107+
null
101108
);
102109
}
103110

@@ -116,6 +123,7 @@ protected void assertInstances(
116123
assertEquals(serverTestInstance.getSettings(), clientInstance.getSettings());
117124
assertEquals(serverTestInstance.defaultSettings(), clientInstance.getDefaultSettings());
118125
assertEquals(serverTestInstance.getAliases(), clientInstance.getAliases());
126+
assertEquals(serverTestInstance.contexts(), clientInstance.contexts());
119127
}
120128

121129
private static MappingMetadata createMappingsForIndex() {

server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/CreateIndexIT.java

+60
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,23 @@
4141
import org.opensearch.action.support.IndicesOptions;
4242
import org.opensearch.action.support.master.AcknowledgedResponse;
4343
import org.opensearch.cluster.ClusterState;
44+
import org.opensearch.cluster.applicationtemplates.ClusterStateSystemTemplateLoader;
45+
import org.opensearch.cluster.applicationtemplates.SystemTemplate;
46+
import org.opensearch.cluster.applicationtemplates.SystemTemplateMetadata;
47+
import org.opensearch.cluster.applicationtemplates.TemplateRepositoryMetadata;
48+
import org.opensearch.cluster.metadata.Context;
4449
import org.opensearch.cluster.metadata.IndexMetadata;
4550
import org.opensearch.cluster.metadata.MappingMetadata;
4651
import org.opensearch.cluster.metadata.Metadata;
52+
import org.opensearch.cluster.service.ClusterService;
4753
import org.opensearch.common.settings.Settings;
4854
import org.opensearch.common.unit.TimeValue;
4955
import org.opensearch.common.xcontent.XContentFactory;
5056
import org.opensearch.core.action.ActionListener;
57+
import org.opensearch.core.common.bytes.BytesReference;
5158
import org.opensearch.index.IndexNotFoundException;
5259
import org.opensearch.index.IndexService;
60+
import org.opensearch.index.IndexSettings;
5361
import org.opensearch.index.mapper.MapperParsingException;
5462
import org.opensearch.index.mapper.MapperService;
5563
import org.opensearch.index.query.RangeQueryBuilder;
@@ -58,7 +66,10 @@
5866
import org.opensearch.test.OpenSearchIntegTestCase.ClusterScope;
5967
import org.opensearch.test.OpenSearchIntegTestCase.Scope;
6068

69+
import java.nio.ByteBuffer;
70+
import java.nio.charset.StandardCharsets;
6171
import java.util.Map;
72+
import java.util.UUID;
6273
import java.util.concurrent.CountDownLatch;
6374
import java.util.concurrent.atomic.AtomicInteger;
6475
import java.util.function.BiFunction;
@@ -429,4 +440,53 @@ public void testCreateIndexWithNullReplicaCountPickUpClusterReplica() {
429440
);
430441
}
431442
}
443+
444+
public void testCreateIndexWithContextSettingsAndTemplate() throws Exception {
445+
int numReplicas = 1;
446+
String indexName = "test-idx-1";
447+
Settings settings = Settings.builder()
448+
.put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1)
449+
.put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), (String) null)
450+
.build();
451+
Context context = new Context("test");
452+
453+
String templateContent = "{\n"
454+
+ " \"template\": {\n"
455+
+ " \"settings\": {\n"
456+
+ " \"merge.policy\": \"log_byte_size\"\n"
457+
+ " }\n"
458+
+ " },\n"
459+
+ " \"_meta\": {\n"
460+
+ " \"_type\": \"@abc_template\",\n"
461+
+ " \"_version\": 1\n"
462+
+ " },\n"
463+
+ " \"version\": 1\n"
464+
+ "}\n";
465+
466+
ClusterStateSystemTemplateLoader loader = new ClusterStateSystemTemplateLoader(
467+
internalCluster().clusterManagerClient(),
468+
() -> internalCluster().getInstance(ClusterService.class).state()
469+
);
470+
loader.loadTemplate(
471+
new SystemTemplate(
472+
BytesReference.fromByteBuffer(ByteBuffer.wrap(templateContent.getBytes(StandardCharsets.UTF_8))),
473+
SystemTemplateMetadata.fromComponentTemplateInfo("test", 1L),
474+
new TemplateRepositoryMetadata(UUID.randomUUID().toString(), 1L)
475+
)
476+
);
477+
478+
assertAcked(client().admin().indices().prepareCreate(indexName).setSettings(settings).setContext(context).get());
479+
480+
IndicesService indicesService = internalCluster().getInstance(IndicesService.class, internalCluster().getClusterManagerName());
481+
482+
for (IndexService indexService : indicesService) {
483+
assertEquals(indexName, indexService.index().getName());
484+
assertEquals(
485+
numReplicas,
486+
(int) indexService.getIndexSettings().getSettings().getAsInt(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, null)
487+
);
488+
assertEquals(context, indexService.getMetadata().context());
489+
assertEquals("log_byte_size", indexService.getMetadata().getSettings().get(IndexSettings.INDEX_MERGE_POLICY.getKey()));
490+
}
491+
}
432492
}

server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/RemoteSplitIndexIT.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.opensearch.index.seqno.SeqNoStats;
6767
import org.opensearch.index.shard.IndexShard;
6868
import org.opensearch.indices.IndicesService;
69+
import org.opensearch.indices.RemoteStoreSettings;
6970
import org.opensearch.indices.replication.common.ReplicationType;
7071
import org.opensearch.remotestore.RemoteStoreBaseIntegTestCase;
7172
import org.opensearch.test.OpenSearchIntegTestCase;
@@ -109,13 +110,16 @@ public void cleanUp() throws Exception {
109110
assertAcked(
110111
client().admin().indices().prepareDelete("*").setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN).get()
111112
);
112-
assertBusy(() -> {
113-
try {
114-
assertEquals(0, getFileCount(translogRepoPath));
115-
} catch (IOException e) {
116-
fail();
117-
}
118-
}, 30, TimeUnit.SECONDS);
113+
// With pinned timestamp, we can have tlog files even after deletion.
114+
if (RemoteStoreSettings.isPinnedTimestampsEnabled() == false) {
115+
assertBusy(() -> {
116+
try {
117+
assertEquals(0, getFileCount(translogRepoPath));
118+
} catch (IOException e) {
119+
fail();
120+
}
121+
}, 30, TimeUnit.SECONDS);
122+
}
119123
super.teardown();
120124
}
121125

server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteClusterStateCleanupManagerIT.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.Base64;
3232
import java.util.List;
3333
import java.util.Map;
34+
import java.util.Objects;
3435
import java.util.concurrent.TimeUnit;
3536
import java.util.concurrent.atomic.AtomicLong;
3637

@@ -40,6 +41,7 @@
4041
import static org.opensearch.gateway.remote.RemoteClusterStateCleanupManager.RETAINED_MANIFESTS;
4142
import static org.opensearch.gateway.remote.RemoteClusterStateCleanupManager.SKIP_CLEANUP_STATE_CHANGES;
4243
import static org.opensearch.gateway.remote.RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING;
44+
import static org.opensearch.gateway.remote.RemoteUploadStats.REMOTE_UPLOAD;
4345
import static org.opensearch.gateway.remote.routingtable.RemoteIndexRoutingTable.INDEX_ROUTING_TABLE;
4446
import static org.opensearch.indices.IndicesService.CLUSTER_DEFAULT_INDEX_REFRESH_INTERVAL_SETTING;
4547
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY;
@@ -253,11 +255,13 @@ private void verifyIndexRoutingFilesDeletion(
253255
DiscoveryStats discoveryStats = nodesStatsResponse.getNodes().get(0).getDiscoveryStats();
254256
assertNotNull(discoveryStats.getClusterStateStats());
255257
for (PersistedStateStats persistedStateStats : discoveryStats.getClusterStateStats().getPersistenceStats()) {
256-
Map<String, AtomicLong> extendedFields = persistedStateStats.getExtendedFields();
257-
assertTrue(extendedFields.containsKey(RemotePersistenceStats.INDEX_ROUTING_FILES_CLEANUP_ATTEMPT_FAILED_COUNT));
258-
long cleanupAttemptFailedCount = extendedFields.get(RemotePersistenceStats.INDEX_ROUTING_FILES_CLEANUP_ATTEMPT_FAILED_COUNT)
259-
.get();
260-
assertEquals(0, cleanupAttemptFailedCount);
258+
if (Objects.equals(persistedStateStats.getStatsName(), REMOTE_UPLOAD)) {
259+
Map<String, AtomicLong> extendedFields = persistedStateStats.getExtendedFields();
260+
assertTrue(extendedFields.containsKey(RemoteUploadStats.INDEX_ROUTING_FILES_CLEANUP_ATTEMPT_FAILED_COUNT));
261+
long cleanupAttemptFailedCount = extendedFields.get(RemoteUploadStats.INDEX_ROUTING_FILES_CLEANUP_ATTEMPT_FAILED_COUNT)
262+
.get();
263+
assertEquals(0, cleanupAttemptFailedCount);
264+
}
261265
}
262266
}
263267

server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteStatePublicationIT.java

+35
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88

99
package org.opensearch.gateway.remote;
1010

11+
import org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest;
12+
import org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse;
1113
import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
1214
import org.opensearch.action.admin.cluster.state.ClusterStateResponse;
1315
import org.opensearch.client.Client;
1416
import org.opensearch.common.blobstore.BlobPath;
1517
import org.opensearch.common.settings.Settings;
1618
import org.opensearch.common.util.FeatureFlags;
19+
import org.opensearch.discovery.DiscoveryStats;
1720
import org.opensearch.gateway.remote.model.RemoteClusterMetadataManifest;
1821
import org.opensearch.indices.recovery.RecoverySettings;
1922
import org.opensearch.remotestore.RemoteStoreBaseIntegTestCase;
@@ -155,6 +158,38 @@ public void testRemotePublicationDisableIfRemoteStateDisabled() {
155158
assertNull(internalCluster().getCurrentClusterManagerNodeInstance(RemoteClusterStateService.class));
156159
}
157160

161+
public void testRemotePublicationDownloadStats() {
162+
int shardCount = randomIntBetween(1, 2);
163+
int replicaCount = 1;
164+
int dataNodeCount = shardCount * (replicaCount + 1);
165+
int clusterManagerNodeCount = 1;
166+
prepareCluster(clusterManagerNodeCount, dataNodeCount, INDEX_NAME, replicaCount, shardCount);
167+
String dataNode = internalCluster().getDataNodeNames().stream().collect(Collectors.toList()).get(0);
168+
169+
NodesStatsResponse nodesStatsResponseDataNode = client().admin()
170+
.cluster()
171+
.prepareNodesStats(dataNode)
172+
.addMetric(NodesStatsRequest.Metric.DISCOVERY.metricName())
173+
.get();
174+
175+
assertDataNodeDownloadStats(nodesStatsResponseDataNode);
176+
177+
}
178+
179+
private void assertDataNodeDownloadStats(NodesStatsResponse nodesStatsResponse) {
180+
// assert cluster state stats for data node
181+
DiscoveryStats dataNodeDiscoveryStats = nodesStatsResponse.getNodes().get(0).getDiscoveryStats();
182+
assertNotNull(dataNodeDiscoveryStats.getClusterStateStats());
183+
assertEquals(0, dataNodeDiscoveryStats.getClusterStateStats().getUpdateSuccess());
184+
assertTrue(dataNodeDiscoveryStats.getClusterStateStats().getPersistenceStats().get(0).getSuccessCount() > 0);
185+
assertEquals(0, dataNodeDiscoveryStats.getClusterStateStats().getPersistenceStats().get(0).getFailedCount());
186+
assertTrue(dataNodeDiscoveryStats.getClusterStateStats().getPersistenceStats().get(0).getTotalTimeInMillis() > 0);
187+
188+
assertTrue(dataNodeDiscoveryStats.getClusterStateStats().getPersistenceStats().get(1).getSuccessCount() > 0);
189+
assertEquals(0, dataNodeDiscoveryStats.getClusterStateStats().getPersistenceStats().get(1).getFailedCount());
190+
assertTrue(dataNodeDiscoveryStats.getClusterStateStats().getPersistenceStats().get(1).getTotalTimeInMillis() > 0);
191+
}
192+
158193
private Map<String, Integer> getMetadataFiles(BlobStoreRepository repository, String subDirectory) throws IOException {
159194
BlobPath metadataPath = repository.basePath()
160195
.add(

0 commit comments

Comments
 (0)