Skip to content

Commit 0696dfd

Browse files
committed
Include search replica in _cat/indices response
Signed-off-by: Vinay Krishna Pudyodu <[email protected]>
1 parent 0eabc79 commit 0696dfd

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

server/src/main/java/org/opensearch/cluster/health/ClusterIndexHealth.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public final class ClusterIndexHealth implements Iterable<ClusterShardHealth>, W
7171
private static final String STATUS = "status";
7272
private static final String NUMBER_OF_SHARDS = "number_of_shards";
7373
private static final String NUMBER_OF_REPLICAS = "number_of_replicas";
74+
private static final String NUMBER_OF_SEARCH_REPLICAS = "number_of_search_replicas";
7475
private static final String ACTIVE_PRIMARY_SHARDS = "active_primary_shards";
7576
private static final String ACTIVE_SHARDS = "active_shards";
7677
private static final String RELOCATING_SHARDS = "relocating_shards";
@@ -85,6 +86,7 @@ public final class ClusterIndexHealth implements Iterable<ClusterShardHealth>, W
8586
int i = 0;
8687
int numberOfShards = (int) parsedObjects[i++];
8788
int numberOfReplicas = (int) parsedObjects[i++];
89+
int numberOfSearchReplicas = (int) parsedObjects[i++];
8890
int activeShards = (int) parsedObjects[i++];
8991
int relocatingShards = (int) parsedObjects[i++];
9092
int initializingShards = (int) parsedObjects[i++];
@@ -107,6 +109,7 @@ public final class ClusterIndexHealth implements Iterable<ClusterShardHealth>, W
107109
index,
108110
numberOfShards,
109111
numberOfReplicas,
112+
numberOfSearchReplicas,
110113
activeShards,
111114
relocatingShards,
112115
initializingShards,
@@ -126,6 +129,7 @@ public final class ClusterIndexHealth implements Iterable<ClusterShardHealth>, W
126129
static {
127130
PARSER.declareInt(constructorArg(), new ParseField(NUMBER_OF_SHARDS));
128131
PARSER.declareInt(constructorArg(), new ParseField(NUMBER_OF_REPLICAS));
132+
PARSER.declareInt(constructorArg(), new ParseField(NUMBER_OF_SEARCH_REPLICAS));
129133
PARSER.declareInt(constructorArg(), new ParseField(ACTIVE_SHARDS));
130134
PARSER.declareInt(constructorArg(), new ParseField(RELOCATING_SHARDS));
131135
PARSER.declareInt(constructorArg(), new ParseField(INITIALIZING_SHARDS));
@@ -139,6 +143,7 @@ public final class ClusterIndexHealth implements Iterable<ClusterShardHealth>, W
139143
private final String index;
140144
private final int numberOfShards;
141145
private final int numberOfReplicas;
146+
private final int numberOfSearchReplicas;
142147
private final int activeShards;
143148
private final int relocatingShards;
144149
private final int initializingShards;
@@ -152,6 +157,7 @@ public ClusterIndexHealth(final IndexMetadata indexMetadata, final IndexRoutingT
152157
this.index = indexMetadata.getIndex().getName();
153158
this.numberOfShards = indexMetadata.getNumberOfShards();
154159
this.numberOfReplicas = indexMetadata.getNumberOfReplicas();
160+
this.numberOfSearchReplicas = indexMetadata.getNumberOfSearchOnlyReplicas();
155161

156162
shards = new HashMap<>();
157163
for (IndexShardRoutingTable shardRoutingTable : indexRoutingTable) {
@@ -200,6 +206,7 @@ public ClusterIndexHealth(
200206
this.index = indexMetadata.getIndex().getName();
201207
this.numberOfShards = indexMetadata.getNumberOfShards();
202208
this.numberOfReplicas = indexMetadata.getNumberOfReplicas();
209+
this.numberOfSearchReplicas = indexMetadata.getNumberOfSearchOnlyReplicas();
203210

204211
shards = new HashMap<>();
205212

@@ -299,6 +306,7 @@ public ClusterIndexHealth(final StreamInput in) throws IOException {
299306
index = in.readString();
300307
numberOfShards = in.readVInt();
301308
numberOfReplicas = in.readVInt();
309+
numberOfSearchReplicas = in.readVInt();
302310
activePrimaryShards = in.readVInt();
303311
activeShards = in.readVInt();
304312
relocatingShards = in.readVInt();
@@ -321,6 +329,7 @@ public ClusterIndexHealth(final StreamInput in) throws IOException {
321329
String index,
322330
int numberOfShards,
323331
int numberOfReplicas,
332+
int numberOfSearchReplicas,
324333
int activeShards,
325334
int relocatingShards,
326335
int initializingShards,
@@ -332,6 +341,7 @@ public ClusterIndexHealth(final StreamInput in) throws IOException {
332341
this.index = index;
333342
this.numberOfShards = numberOfShards;
334343
this.numberOfReplicas = numberOfReplicas;
344+
this.numberOfSearchReplicas = numberOfSearchReplicas;
335345
this.activeShards = activeShards;
336346
this.relocatingShards = relocatingShards;
337347
this.initializingShards = initializingShards;
@@ -353,6 +363,10 @@ public int getNumberOfReplicas() {
353363
return numberOfReplicas;
354364
}
355365

366+
public int getNumberOfSearchReplicas() {
367+
return numberOfSearchReplicas;
368+
}
369+
356370
public int getActiveShards() {
357371
return activeShards;
358372
}
@@ -395,6 +409,7 @@ public void writeTo(final StreamOutput out) throws IOException {
395409
out.writeString(index);
396410
out.writeVInt(numberOfShards);
397411
out.writeVInt(numberOfReplicas);
412+
out.writeVInt(numberOfSearchReplicas);
398413
out.writeVInt(activePrimaryShards);
399414
out.writeVInt(activeShards);
400415
out.writeVInt(relocatingShards);
@@ -410,6 +425,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
410425
builder.field(STATUS, getStatus().name().toLowerCase(Locale.ROOT));
411426
builder.field(NUMBER_OF_SHARDS, getNumberOfShards());
412427
builder.field(NUMBER_OF_REPLICAS, getNumberOfReplicas());
428+
builder.field(NUMBER_OF_SEARCH_REPLICAS, getNumberOfSearchReplicas());
413429
builder.field(ACTIVE_PRIMARY_SHARDS, getActivePrimaryShards());
414430
builder.field(ACTIVE_SHARDS, getActiveShards());
415431
builder.field(RELOCATING_SHARDS, getRelocatingShards());
@@ -451,6 +467,8 @@ public String toString() {
451467
+ numberOfShards
452468
+ ", numberOfReplicas="
453469
+ numberOfReplicas
470+
+ ", numberOfSearchReplicas="
471+
+ numberOfSearchReplicas
454472
+ ", activeShards="
455473
+ activeShards
456474
+ ", relocatingShards="
@@ -476,6 +494,7 @@ public boolean equals(Object o) {
476494
return Objects.equals(index, that.index)
477495
&& numberOfShards == that.numberOfShards
478496
&& numberOfReplicas == that.numberOfReplicas
497+
&& numberOfSearchReplicas == that.numberOfSearchReplicas
479498
&& activeShards == that.activeShards
480499
&& relocatingShards == that.relocatingShards
481500
&& initializingShards == that.initializingShards

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ protected Table getTableWithHeader(final RestRequest request, final PageToken pa
420420
table.addCell("uuid", "alias:id,uuid;desc:index uuid");
421421
table.addCell("pri", "alias:p,shards.primary,shardsPrimary;text-align:right;desc:number of primary shards");
422422
table.addCell("rep", "alias:r,shards.replica,shardsReplica;text-align:right;desc:number of replica shards");
423+
table.addCell("srep", "alias:s,shards.searchReplica,shardsSearchReplica;text-align:right;desc:number of search replica shards");
423424
table.addCell("docs.count", "alias:dc,docsCount;text-align:right;desc:available docs");
424425
table.addCell("docs.deleted", "alias:dd,docsDeleted;text-align:right;desc:deleted docs");
425426

@@ -847,6 +848,7 @@ protected Table buildTable(
847848
table.addCell(indexMetadata.getIndexUUID());
848849
table.addCell(indexHealth == null ? null : indexHealth.getNumberOfShards());
849850
table.addCell(indexHealth == null ? null : indexHealth.getNumberOfReplicas());
851+
table.addCell(indexHealth == null ? null : indexHealth.getNumberOfSearchReplicas());
850852

851853
table.addCell(primaryStats.getDocs() == null ? null : primaryStats.getDocs().getCount());
852854
table.addCell(primaryStats.getDocs() == null ? null : primaryStats.getDocs().getDeleted());

server/src/test/java/org/opensearch/cluster/health/ClusterIndexHealthTests.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public static ClusterIndexHealth randomIndexHealth(String indexName, ClusterHeal
125125
randomInt(1000),
126126
randomInt(1000),
127127
randomInt(1000),
128+
randomInt(1000),
128129
randomFrom(ClusterHealthStatus.values()),
129130
shards
130131
);
@@ -164,6 +165,7 @@ protected ClusterIndexHealth mutateInstance(ClusterIndexHealth instance) throws
164165
"index",
165166
"numberOfShards",
166167
"numberOfReplicas",
168+
"numberOfSearchReplicas",
167169
"activeShards",
168170
"relocatingShards",
169171
"initializingShards",
@@ -178,6 +180,7 @@ protected ClusterIndexHealth mutateInstance(ClusterIndexHealth instance) throws
178180
instance.getIndex() + randomAlphaOfLengthBetween(2, 5),
179181
instance.getNumberOfShards(),
180182
instance.getNumberOfReplicas(),
183+
instance.getNumberOfSearchReplicas(),
181184
instance.getActiveShards(),
182185
instance.getRelocatingShards(),
183186
instance.getInitializingShards(),
@@ -191,6 +194,7 @@ protected ClusterIndexHealth mutateInstance(ClusterIndexHealth instance) throws
191194
instance.getIndex(),
192195
instance.getNumberOfShards() + between(1, 10),
193196
instance.getNumberOfReplicas(),
197+
instance.getNumberOfSearchReplicas(),
194198
instance.getActiveShards(),
195199
instance.getRelocatingShards(),
196200
instance.getInitializingShards(),
@@ -204,6 +208,21 @@ protected ClusterIndexHealth mutateInstance(ClusterIndexHealth instance) throws
204208
instance.getIndex(),
205209
instance.getNumberOfShards(),
206210
instance.getNumberOfReplicas() + between(1, 10),
211+
instance.getNumberOfSearchReplicas(),
212+
instance.getActiveShards(),
213+
instance.getRelocatingShards(),
214+
instance.getInitializingShards(),
215+
instance.getUnassignedShards(),
216+
instance.getActivePrimaryShards(),
217+
instance.getStatus(),
218+
instance.getShards()
219+
);
220+
case "numberOfSearchReplicas":
221+
return new ClusterIndexHealth(
222+
instance.getIndex(),
223+
instance.getNumberOfShards(),
224+
instance.getNumberOfReplicas(),
225+
instance.getNumberOfSearchReplicas() + between(1, 10),
207226
instance.getActiveShards(),
208227
instance.getRelocatingShards(),
209228
instance.getInitializingShards(),
@@ -217,6 +236,7 @@ protected ClusterIndexHealth mutateInstance(ClusterIndexHealth instance) throws
217236
instance.getIndex(),
218237
instance.getNumberOfShards(),
219238
instance.getNumberOfReplicas(),
239+
instance.getNumberOfSearchReplicas(),
220240
instance.getActiveShards() + between(1, 10),
221241
instance.getRelocatingShards(),
222242
instance.getInitializingShards(),
@@ -230,6 +250,7 @@ protected ClusterIndexHealth mutateInstance(ClusterIndexHealth instance) throws
230250
instance.getIndex(),
231251
instance.getNumberOfShards(),
232252
instance.getNumberOfReplicas(),
253+
instance.getNumberOfSearchReplicas(),
233254
instance.getActiveShards(),
234255
instance.getRelocatingShards() + between(1, 10),
235256
instance.getInitializingShards(),
@@ -243,6 +264,7 @@ protected ClusterIndexHealth mutateInstance(ClusterIndexHealth instance) throws
243264
instance.getIndex(),
244265
instance.getNumberOfShards(),
245266
instance.getNumberOfReplicas(),
267+
instance.getNumberOfSearchReplicas(),
246268
instance.getActiveShards(),
247269
instance.getRelocatingShards(),
248270
instance.getInitializingShards() + between(1, 10),
@@ -256,6 +278,7 @@ protected ClusterIndexHealth mutateInstance(ClusterIndexHealth instance) throws
256278
instance.getIndex(),
257279
instance.getNumberOfShards(),
258280
instance.getNumberOfReplicas(),
281+
instance.getNumberOfSearchReplicas(),
259282
instance.getActiveShards(),
260283
instance.getRelocatingShards(),
261284
instance.getInitializingShards(),
@@ -269,6 +292,7 @@ protected ClusterIndexHealth mutateInstance(ClusterIndexHealth instance) throws
269292
instance.getIndex(),
270293
instance.getNumberOfShards(),
271294
instance.getNumberOfReplicas(),
295+
instance.getNumberOfSearchReplicas(),
272296
instance.getActiveShards(),
273297
instance.getRelocatingShards(),
274298
instance.getInitializingShards(),
@@ -287,6 +311,7 @@ protected ClusterIndexHealth mutateInstance(ClusterIndexHealth instance) throws
287311
instance.getIndex(),
288312
instance.getNumberOfShards(),
289313
instance.getNumberOfReplicas(),
314+
instance.getNumberOfSearchReplicas(),
290315
instance.getActiveShards(),
291316
instance.getRelocatingShards(),
292317
instance.getInitializingShards(),
@@ -307,6 +332,7 @@ protected ClusterIndexHealth mutateInstance(ClusterIndexHealth instance) throws
307332
instance.getIndex(),
308333
instance.getNumberOfShards(),
309334
instance.getNumberOfReplicas(),
335+
instance.getNumberOfSearchReplicas(),
310336
instance.getActiveShards(),
311337
instance.getRelocatingShards(),
312338
instance.getInitializingShards(),

0 commit comments

Comments
 (0)