Skip to content

Commit

Permalink
Add deleted doc count in _cat/shards
Browse files Browse the repository at this point in the history
Signed-off-by: Shreyansh Ray <[email protected]>
  • Loading branch information
rayshrey committed Jan 2, 2024
1 parent 71d7e4d commit eef855b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Interpret byte array as primitive using VarHandles ([#11362](https://github.com/opensearch-project/OpenSearch/pull/11362))
- Automatically add scheme to discovery.ec2.endpoint ([#11512](https://github.com/opensearch-project/OpenSearch/pull/11512))
- Restore support for Java 8 for RestClient ([#11562](https://github.com/opensearch-project/OpenSearch/pull/11562))
- Add deleted doc count in _cat/shards ([#11678](https://github.com/opensearch-project/OpenSearch/pull/11678))

### Deprecated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
warmer.total_time .+ \n
path.data .+ \n
path.state .+ \n
docs.deleted .+ \n
$/
---
"Help before - 2.4.0":
Expand Down Expand Up @@ -171,6 +172,7 @@
warmer.total_time .+ \n
path.data .+ \n
path.state .+ \n
docs.deleted .+ \n
$/
---
"Test cat shards output":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ protected Table getTableWithHeader(final RestRequest request) {

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

table.endHeaders();
return table;
Expand Down Expand Up @@ -448,6 +449,7 @@ Table buildTable(RestRequest request, ClusterStateResponse state, IndicesStatsRe

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

table.endRow();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.opensearch.cluster.routing.ShardRoutingState;
import org.opensearch.cluster.routing.TestShardRouting;
import org.opensearch.common.Table;
import org.opensearch.index.shard.DocsStats;
import org.opensearch.index.shard.ShardPath;
import org.opensearch.test.OpenSearchTestCase;
import org.opensearch.test.rest.FakeRestRequest;
Expand All @@ -65,6 +66,8 @@ public class RestShardsActionTests extends OpenSearchTestCase {

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

List<ShardRouting> shardRoutings = new ArrayList<>(numShards);
Expand All @@ -76,10 +79,12 @@ public void testBuildTable() {
Path path = createTempDir().resolve("indices")
.resolve(shardRouting.shardId().getIndex().getUUID())
.resolve(String.valueOf(shardRouting.shardId().id()));
CommonStats commonStats = new CommonStats();
commonStats.docs = new DocsStats(numDocs, numDeletedDocs, 0);
ShardStats shardStats = new ShardStats(
shardRouting,
new ShardPath(false, path, path, shardRouting.shardId()),
null,
commonStats,
null,
null,
null
Expand Down Expand Up @@ -120,6 +125,7 @@ public void testBuildTable() {
assertThat(headers.get(6).value, equalTo("ip"));
assertThat(headers.get(7).value, equalTo("id"));
assertThat(headers.get(8).value, equalTo("node"));
assertThat(headers.get(74).value, equalTo("docs.deleted"));

final List<List<Table.Cell>> rows = table.getRows();
assertThat(rows.size(), equalTo(numShards));
Expand All @@ -132,10 +138,12 @@ public void testBuildTable() {
assertThat(row.get(1).value, equalTo(shardRouting.getId()));
assertThat(row.get(2).value, equalTo(shardRouting.primary() ? "p" : "r"));
assertThat(row.get(3).value, equalTo(shardRouting.state()));
assertThat(row.get(4).value, equalTo(shardStats.getStats().getDocs().getCount()));
assertThat(row.get(6).value, equalTo(localNode.getHostAddress()));
assertThat(row.get(7).value, equalTo(localNode.getId()));
assertThat(row.get(72).value, equalTo(shardStats.getDataPath()));
assertThat(row.get(73).value, equalTo(shardStats.getStatePath()));
assertThat(row.get(74).value, equalTo(shardStats.getStats().getDocs().getDeleted()));
}
}
}

0 comments on commit eef855b

Please sign in to comment.