From 7437acfcea49a66d938e26897af8f7b29e1654b9 Mon Sep 17 00:00:00 2001 From: kimchy Date: Thu, 19 Aug 2010 22:29:31 +0300 Subject: [PATCH] add progress to indices status API --- .../admin/indices/status/GatewayRecoveryStatus.java | 11 +++++++++++ .../admin/indices/status/PeerRecoveryStatus.java | 11 +++++++++++ .../indices/status/TransportIndicesStatusAction.java | 2 +- .../admin/indices/status/RestIndicesStatusAction.java | 2 ++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/GatewayRecoveryStatus.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/GatewayRecoveryStatus.java index dc2b64de9cd..a0d78c2562d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/GatewayRecoveryStatus.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/GatewayRecoveryStatus.java @@ -169,6 +169,17 @@ public class GatewayRecoveryStatus { return recoveredIndexSize(); } + public int indexRecoveryProgress() { + if (recoveredIndexSize == 0) { + return 0; + } + return (int) (((double) recoveredIndexSize) / expectedRecoveredIndexSize().bytes() * 100); + } + + public int getIndexRecoveryProgress() { + return indexRecoveryProgress(); + } + public long recoveredTranslogOperations() { return recoveredTranslogOperations; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/PeerRecoveryStatus.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/PeerRecoveryStatus.java index 0a6de0c9ede..17d1f1f8910 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/PeerRecoveryStatus.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/PeerRecoveryStatus.java @@ -158,6 +158,17 @@ public class PeerRecoveryStatus { return recoveredIndexSize(); } + public int indexRecoveryProgress() { + if (recoveredIndexSize == 0) { + return 0; + } + return (int) (((double) recoveredIndexSize) / expectedRecoveredIndexSize().bytes() * 100); + } + + public int getIndexRecoveryProgress() { + return indexRecoveryProgress(); + } + public long recoveredTranslogOperations() { return recoveredTranslogOperations; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java index 8a0316cae5a..7258f69c5bc 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java @@ -138,7 +138,7 @@ public class TransportIndicesStatusAction extends TransportBroadcastOperationAct @Override protected ShardStatus shardOperation(IndexShardStatusRequest request) throws ElasticSearchException { InternalIndexService indexService = (InternalIndexService) indicesService.indexServiceSafe(request.index()); - InternalIndexShard indexShard = (InternalIndexShard) indexService.shard(request.shardId()); + InternalIndexShard indexShard = (InternalIndexShard) indexService.shardSafe(request.shardId()); ShardStatus shardStatus = new ShardStatus(indexShard.routingEntry()); shardStatus.state = indexShard.state(); try { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/status/RestIndicesStatusAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/status/RestIndicesStatusAction.java index ea5a83ca590..5ebaea24e6d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/status/RestIndicesStatusAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/status/RestIndicesStatusAction.java @@ -149,6 +149,7 @@ public class RestIndicesStatusAction extends BaseRestHandler { builder.field("throttling_time_in_millis", peerRecoveryStatus.throttlingTime().millis()); builder.startObject("index"); + builder.field("progress", peerRecoveryStatus.indexRecoveryProgress()); builder.field("size", peerRecoveryStatus.indexSize()); builder.field("size_in_bytes", peerRecoveryStatus.indexSize().bytes()); builder.field("reused_size", peerRecoveryStatus.reusedIndexSize()); @@ -177,6 +178,7 @@ public class RestIndicesStatusAction extends BaseRestHandler { builder.field("throttling_time_in_millis", gatewayRecoveryStatus.throttlingTime().millis()); builder.startObject("index"); + builder.field("progress", gatewayRecoveryStatus.indexRecoveryProgress()); builder.field("size", gatewayRecoveryStatus.indexSize()); builder.field("size_in_bytes", gatewayRecoveryStatus.indexSize().bytes()); builder.field("reused_size", gatewayRecoveryStatus.reusedIndexSize());