Skip to content

Commit 75103c2

Browse files
committed
Add deleted doc count in _cat/shards (opensearch-project#11678)
Signed-off-by: Shreyansh Ray <rayshrey@amazon.com>
1 parent 8d6b001 commit 75103c2

4 files changed

Lines changed: 104 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
181181
- Interpret byte array as primitive using VarHandles ([#11362](https://github.com/opensearch-project/OpenSearch/pull/11362))
182182
- Automatically add scheme to discovery.ec2.endpoint ([#11512](https://github.com/opensearch-project/OpenSearch/pull/11512))
183183
- Restore support for Java 8 for RestClient ([#11562](https://github.com/opensearch-project/OpenSearch/pull/11562))
184+
- Add deleted doc count in _cat/shards ([#11678](https://github.com/opensearch-project/OpenSearch/pull/11678))
184185

185186
### Deprecated
186187

rest-api-spec/src/main/resources/rest-api-spec/test/cat.shards/10_basic.yml

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,103 @@
11
"Help":
22
- skip:
3-
version: " - 2.3.99"
3+
version: " - 2.11.99"
4+
reason: deleted docs added in 2.12.0
5+
features: node_selector
6+
- do:
7+
cat.shards:
8+
help: true
9+
node_selector:
10+
version: "2.12.0 - "
11+
12+
- match:
13+
$body: |
14+
/^ index .+ \n
15+
shard .+ \n
16+
prirep .+ \n
17+
state .+ \n
18+
docs .+ \n
19+
store .+ \n
20+
ip .+ \n
21+
id .+ \n
22+
node .+ \n
23+
sync_id .+ \n
24+
unassigned.reason .+ \n
25+
unassigned.at .+ \n
26+
unassigned.for .+ \n
27+
unassigned.details .+ \n
28+
recoverysource.type .+ \n
29+
completion.size .+ \n
30+
fielddata.memory_size .+ \n
31+
fielddata.evictions .+ \n
32+
query_cache.memory_size .+ \n
33+
query_cache.evictions .+ \n
34+
flush.total .+ \n
35+
flush.total_time .+ \n
36+
get.current .+ \n
37+
get.time .+ \n
38+
get.total .+ \n
39+
get.exists_time .+ \n
40+
get.exists_total .+ \n
41+
get.missing_time .+ \n
42+
get.missing_total .+ \n
43+
indexing.delete_current .+ \n
44+
indexing.delete_time .+ \n
45+
indexing.delete_total .+ \n
46+
indexing.index_current .+ \n
47+
indexing.index_time .+ \n
48+
indexing.index_total .+ \n
49+
indexing.index_failed .+ \n
50+
merges.current .+ \n
51+
merges.current_docs .+ \n
52+
merges.current_size .+ \n
53+
merges.total .+ \n
54+
merges.total_docs .+ \n
55+
merges.total_size .+ \n
56+
merges.total_time .+ \n
57+
refresh.total .+ \n
58+
refresh.time .+ \n
59+
refresh.external_total .+ \n
60+
refresh.external_time .+ \n
61+
refresh.listeners .+ \n
62+
search.fetch_current .+ \n
63+
search.fetch_time .+ \n
64+
search.fetch_total .+ \n
65+
search.open_contexts .+ \n
66+
search.query_current .+ \n
67+
search.query_time .+ \n
68+
search.query_total .+ \n
69+
search.scroll_current .+ \n
70+
search.scroll_time .+ \n
71+
search.scroll_total .+ \n
72+
search.point_in_time_current .+ \n
73+
search.point_in_time_time .+ \n
74+
search.point_in_time_total .+ \n
75+
segments.count .+ \n
76+
segments.memory .+ \n
77+
segments.index_writer_memory .+ \n
78+
segments.version_map_memory .+ \n
79+
segments.fixed_bitset_memory .+ \n
80+
seq_no.max .+ \n
81+
seq_no.local_checkpoint .+ \n
82+
seq_no.global_checkpoint .+ \n
83+
warmer.current .+ \n
84+
warmer.total .+ \n
85+
warmer.total_time .+ \n
86+
path.data .+ \n
87+
path.state .+ \n
88+
docs.deleted .+ \n
89+
$/
90+
---
91+
"Help from 2.4.0 to 2.11.0":
92+
- skip:
93+
version: " - 2.3.99 , 2.12.0 - "
494
reason: point in time stats were added in 2.4.0
595
features: node_selector
696
- do:
797
cat.shards:
898
help: true
999
node_selector:
10-
version: "2.4.0 - "
100+
version: "2.4.0 - 2.11.99"
11101

12102
- match:
13103
$body: |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ protected Table getTableWithHeader(final RestRequest request) {
283283

284284
table.addCell("path.data", "alias:pd,dataPath;default:false;text-align:right;desc:shard data path");
285285
table.addCell("path.state", "alias:ps,statsPath;default:false;text-align:right;desc:shard state path");
286+
table.addCell("docs.deleted", "alias:dd,docsDeleted;default:false;text-align:right;desc:number of deleted docs in shard");
286287

287288
table.endHeaders();
288289
return table;
@@ -448,6 +449,7 @@ Table buildTable(RestRequest request, ClusterStateResponse state, IndicesStatsRe
448449

449450
table.addCell(getOrNull(shardStats, ShardStats::getDataPath, s -> s));
450451
table.addCell(getOrNull(shardStats, ShardStats::getStatePath, s -> s));
452+
table.addCell(getOrNull(commonStats, CommonStats::getDocs, DocsStats::getDeleted));
451453

452454
table.endRow();
453455
}

server/src/test/java/org/opensearch/rest/action/cat/RestShardsActionTests.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.opensearch.cluster.routing.ShardRoutingState;
4747
import org.opensearch.cluster.routing.TestShardRouting;
4848
import org.opensearch.common.Table;
49+
import org.opensearch.index.shard.DocsStats;
4950
import org.opensearch.index.shard.ShardPath;
5051
import org.opensearch.test.OpenSearchTestCase;
5152
import org.opensearch.test.rest.FakeRestRequest;
@@ -65,6 +66,8 @@ public class RestShardsActionTests extends OpenSearchTestCase {
6566

6667
public void testBuildTable() {
6768
final int numShards = randomIntBetween(1, 5);
69+
long numDocs = randomLongBetween(0, 10000);
70+
long numDeletedDocs = randomLongBetween(0, 100);
6871
DiscoveryNode localNode = new DiscoveryNode("local", buildNewFakeTransportAddress(), Version.CURRENT);
6972

7073
List<ShardRouting> shardRoutings = new ArrayList<>(numShards);
@@ -76,10 +79,12 @@ public void testBuildTable() {
7679
Path path = createTempDir().resolve("indices")
7780
.resolve(shardRouting.shardId().getIndex().getUUID())
7881
.resolve(String.valueOf(shardRouting.shardId().id()));
82+
CommonStats commonStats = new CommonStats();
83+
commonStats.docs = new DocsStats(numDocs, numDeletedDocs, 0);
7984
ShardStats shardStats = new ShardStats(
8085
shardRouting,
8186
new ShardPath(false, path, path, shardRouting.shardId()),
82-
null,
87+
commonStats,
8388
null,
8489
null,
8590
null
@@ -120,6 +125,7 @@ public void testBuildTable() {
120125
assertThat(headers.get(6).value, equalTo("ip"));
121126
assertThat(headers.get(7).value, equalTo("id"));
122127
assertThat(headers.get(8).value, equalTo("node"));
128+
assertThat(headers.get(74).value, equalTo("docs.deleted"));
123129

124130
final List<List<Table.Cell>> rows = table.getRows();
125131
assertThat(rows.size(), equalTo(numShards));
@@ -132,10 +138,12 @@ public void testBuildTable() {
132138
assertThat(row.get(1).value, equalTo(shardRouting.getId()));
133139
assertThat(row.get(2).value, equalTo(shardRouting.primary() ? "p" : "r"));
134140
assertThat(row.get(3).value, equalTo(shardRouting.state()));
141+
assertThat(row.get(4).value, equalTo(shardStats.getStats().getDocs().getCount()));
135142
assertThat(row.get(6).value, equalTo(localNode.getHostAddress()));
136143
assertThat(row.get(7).value, equalTo(localNode.getId()));
137144
assertThat(row.get(72).value, equalTo(shardStats.getDataPath()));
138145
assertThat(row.get(73).value, equalTo(shardStats.getStatePath()));
146+
assertThat(row.get(74).value, equalTo(shardStats.getStats().getDocs().getDeleted()));
139147
}
140148
}
141149
}

0 commit comments

Comments
 (0)