index status action - some docs and extract common docs status
This commit is contained in:
parent
a3107bc5b1
commit
965d7303cf
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Licensed to Elastic Search and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Elastic Search licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.action.admin.indices.status;
|
||||
|
||||
/**
|
||||
* @author kimchy (shay.banon)
|
||||
*/
|
||||
public class DocsStatus {
|
||||
|
||||
int numDocs = 0;
|
||||
int maxDoc = 0;
|
||||
int deletedDocs = 0;
|
||||
|
||||
/**
|
||||
* The number of docs.
|
||||
*/
|
||||
public int numDocs() {
|
||||
return numDocs;
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of docs.
|
||||
*/
|
||||
public int getNumDocs() {
|
||||
return numDocs();
|
||||
}
|
||||
|
||||
/**
|
||||
* The max doc.
|
||||
*/
|
||||
public int maxDoc() {
|
||||
return maxDoc;
|
||||
}
|
||||
|
||||
/**
|
||||
* The max doc.
|
||||
*/
|
||||
public int getMaxDoc() {
|
||||
return maxDoc();
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of deleted docs in the index.
|
||||
*/
|
||||
public int deletedDocs() {
|
||||
return deletedDocs;
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of deleted docs in the index.
|
||||
*/
|
||||
public int getDeletedDocs() {
|
||||
return deletedDocs();
|
||||
}
|
||||
}
|
|
@ -30,38 +30,6 @@ import java.util.Iterator;
|
|||
*/
|
||||
public class IndexShardStatus implements Iterable<ShardStatus> {
|
||||
|
||||
public static class Docs {
|
||||
public static final Docs UNKNOWN = new Docs();
|
||||
|
||||
int numDocs = -1;
|
||||
int maxDoc = -1;
|
||||
int deletedDocs = -1;
|
||||
|
||||
public int numDocs() {
|
||||
return numDocs;
|
||||
}
|
||||
|
||||
public int getNumDocs() {
|
||||
return numDocs;
|
||||
}
|
||||
|
||||
public int maxDoc() {
|
||||
return maxDoc;
|
||||
}
|
||||
|
||||
public int getMaxDoc() {
|
||||
return maxDoc();
|
||||
}
|
||||
|
||||
public int deletedDocs() {
|
||||
return deletedDocs;
|
||||
}
|
||||
|
||||
public int getDeletedDocs() {
|
||||
return deletedDocs();
|
||||
}
|
||||
}
|
||||
|
||||
private final ShardId shardId;
|
||||
|
||||
private final ShardStatus[] shards;
|
||||
|
@ -128,46 +96,33 @@ public class IndexShardStatus implements Iterable<ShardStatus> {
|
|||
return translogOperations();
|
||||
}
|
||||
|
||||
private transient Docs docs;
|
||||
private transient DocsStatus docs;
|
||||
|
||||
public Docs docs() {
|
||||
public DocsStatus docs() {
|
||||
if (docs != null) {
|
||||
return docs;
|
||||
}
|
||||
Docs docs = new Docs();
|
||||
DocsStatus docs = null;
|
||||
for (ShardStatus shard : shards()) {
|
||||
if (!shard.shardRouting().primary()) {
|
||||
// only sum docs for the primaries
|
||||
continue;
|
||||
}
|
||||
if (shard.docs().numDocs() != -1) {
|
||||
if (docs.numDocs == -1) {
|
||||
docs.numDocs = 0;
|
||||
}
|
||||
docs.numDocs += shard.docs().numDocs();
|
||||
if (shard.docs() == null) {
|
||||
continue;
|
||||
}
|
||||
if (shard.docs().maxDoc() != -1) {
|
||||
if (docs.maxDoc == -1) {
|
||||
docs.maxDoc = 0;
|
||||
}
|
||||
docs.maxDoc += shard.docs().maxDoc();
|
||||
}
|
||||
if (shard.docs().deletedDocs() != -1) {
|
||||
if (docs.deletedDocs == -1) {
|
||||
docs.deletedDocs = 0;
|
||||
}
|
||||
docs.deletedDocs += shard.docs().deletedDocs();
|
||||
if (docs == null) {
|
||||
docs = new DocsStatus();
|
||||
}
|
||||
docs.numDocs += shard.docs().numDocs();
|
||||
docs.maxDoc += shard.docs().maxDoc();
|
||||
docs.deletedDocs += shard.docs().deletedDocs();
|
||||
}
|
||||
if (docs.numDocs == -1) {
|
||||
this.docs = Docs.UNKNOWN;
|
||||
} else {
|
||||
this.docs = docs;
|
||||
}
|
||||
this.docs = docs;
|
||||
return this.docs;
|
||||
}
|
||||
|
||||
public Docs getDocs() {
|
||||
public DocsStatus getDocs() {
|
||||
return docs();
|
||||
}
|
||||
|
||||
|
|
|
@ -34,38 +34,6 @@ import static org.elasticsearch.common.collect.Lists.*;
|
|||
*/
|
||||
public class IndexStatus implements Iterable<IndexShardStatus> {
|
||||
|
||||
public static class Docs {
|
||||
public static final Docs UNKNOWN = new Docs();
|
||||
|
||||
long numDocs = -1;
|
||||
long maxDoc = -1;
|
||||
long deletedDocs = -1;
|
||||
|
||||
public long numDocs() {
|
||||
return numDocs;
|
||||
}
|
||||
|
||||
public long getNumDocs() {
|
||||
return numDocs();
|
||||
}
|
||||
|
||||
public long maxDoc() {
|
||||
return maxDoc;
|
||||
}
|
||||
|
||||
public long getMaxDoc() {
|
||||
return maxDoc();
|
||||
}
|
||||
|
||||
public long deletedDocs() {
|
||||
return deletedDocs;
|
||||
}
|
||||
|
||||
public long getDeletedDocs() {
|
||||
return deletedDocs();
|
||||
}
|
||||
}
|
||||
|
||||
private final String index;
|
||||
|
||||
private final Map<Integer, IndexShardStatus> indexShards;
|
||||
|
@ -156,42 +124,26 @@ public class IndexStatus implements Iterable<IndexShardStatus> {
|
|||
return translogOperations();
|
||||
}
|
||||
|
||||
private transient Docs docs;
|
||||
private transient DocsStatus docs;
|
||||
|
||||
public Docs docs() {
|
||||
public DocsStatus docs() {
|
||||
if (docs != null) {
|
||||
return docs;
|
||||
}
|
||||
Docs docs = new Docs();
|
||||
DocsStatus docs = null;
|
||||
for (IndexShardStatus shard : this) {
|
||||
if (shard.docs().numDocs() != -1) {
|
||||
if (docs.numDocs == -1) {
|
||||
docs.numDocs = 0;
|
||||
}
|
||||
docs.numDocs += shard.docs().numDocs();
|
||||
}
|
||||
if (shard.docs().maxDoc() != -1) {
|
||||
if (docs.maxDoc == -1) {
|
||||
docs.maxDoc = 0;
|
||||
}
|
||||
docs.maxDoc += shard.docs().maxDoc();
|
||||
}
|
||||
if (shard.docs().deletedDocs() != -1) {
|
||||
if (docs.deletedDocs == -1) {
|
||||
docs.deletedDocs = 0;
|
||||
}
|
||||
docs.deletedDocs += shard.docs().deletedDocs();
|
||||
if (shard.docs() == null) {
|
||||
continue;
|
||||
}
|
||||
docs.numDocs += shard.docs().numDocs();
|
||||
docs.maxDoc += shard.docs().maxDoc();
|
||||
docs.deletedDocs += shard.docs().deletedDocs();
|
||||
}
|
||||
if (docs.numDocs == -1) {
|
||||
this.docs = Docs.UNKNOWN;
|
||||
} else {
|
||||
this.docs = docs;
|
||||
}
|
||||
this.docs = docs;
|
||||
return docs;
|
||||
}
|
||||
|
||||
public Docs getDocs() {
|
||||
public DocsStatus getDocs() {
|
||||
return docs();
|
||||
}
|
||||
|
||||
|
|
|
@ -32,42 +32,12 @@ import static org.elasticsearch.cluster.routing.ImmutableShardRouting.*;
|
|||
import static org.elasticsearch.common.unit.ByteSizeValue.*;
|
||||
|
||||
/**
|
||||
* Shard instance (actual allocated shard) status.
|
||||
*
|
||||
* @author kimchy (shay.banon)
|
||||
*/
|
||||
public class ShardStatus extends BroadcastShardOperationResponse {
|
||||
|
||||
public static class Docs {
|
||||
public static final Docs UNKNOWN = new Docs();
|
||||
|
||||
int numDocs = -1;
|
||||
int maxDoc = -1;
|
||||
int deletedDocs = -1;
|
||||
|
||||
public int numDocs() {
|
||||
return numDocs;
|
||||
}
|
||||
|
||||
public int getNumDocs() {
|
||||
return numDocs();
|
||||
}
|
||||
|
||||
public int maxDoc() {
|
||||
return maxDoc;
|
||||
}
|
||||
|
||||
public int getMaxDoc() {
|
||||
return maxDoc();
|
||||
}
|
||||
|
||||
public int deletedDocs() {
|
||||
return deletedDocs;
|
||||
}
|
||||
|
||||
public int getDeletedDocs() {
|
||||
return deletedDocs();
|
||||
}
|
||||
}
|
||||
|
||||
private ShardRouting shardRouting;
|
||||
|
||||
IndexShardState state;
|
||||
|
@ -78,7 +48,7 @@ public class ShardStatus extends BroadcastShardOperationResponse {
|
|||
|
||||
long translogOperations = -1;
|
||||
|
||||
Docs docs = Docs.UNKNOWN;
|
||||
DocsStatus docs;
|
||||
|
||||
PeerRecoveryStatus peerRecoveryStatus;
|
||||
|
||||
|
@ -94,74 +64,132 @@ public class ShardStatus extends BroadcastShardOperationResponse {
|
|||
this.shardRouting = shardRouting;
|
||||
}
|
||||
|
||||
/**
|
||||
* The shard routing information (cluster wide shard state).
|
||||
*/
|
||||
public ShardRouting shardRouting() {
|
||||
return this.shardRouting;
|
||||
}
|
||||
|
||||
/**
|
||||
* The shard routing information (cluster wide shard state).
|
||||
*/
|
||||
public ShardRouting getShardRouting() {
|
||||
return shardRouting();
|
||||
}
|
||||
|
||||
/**
|
||||
* The shard state (index/local state).
|
||||
*/
|
||||
public IndexShardState state() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* The shard state (index/local state).
|
||||
*/
|
||||
public IndexShardState getState() {
|
||||
return state();
|
||||
}
|
||||
|
||||
/**
|
||||
* The current size of the shard index storage.
|
||||
*/
|
||||
public ByteSizeValue storeSize() {
|
||||
return storeSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* The current size of the shard index storage.
|
||||
*/
|
||||
public ByteSizeValue getStoreSize() {
|
||||
return storeSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* The transaction log id.
|
||||
*/
|
||||
public long translogId() {
|
||||
return translogId;
|
||||
}
|
||||
|
||||
/**
|
||||
* The transaction log id.
|
||||
*/
|
||||
public long getTranslogId() {
|
||||
return translogId();
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of transaction operations in the transaction log.
|
||||
*/
|
||||
public long translogOperations() {
|
||||
return translogOperations;
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of transaction operations in the transaction log.
|
||||
*/
|
||||
public long getTranslogOperations() {
|
||||
return translogOperations();
|
||||
}
|
||||
|
||||
public Docs docs() {
|
||||
/**
|
||||
* Docs level information for the shard index, <tt>null</tt> if not applicable.
|
||||
*/
|
||||
public DocsStatus docs() {
|
||||
return docs;
|
||||
}
|
||||
|
||||
public Docs getDocs() {
|
||||
/**
|
||||
* Docs level information for the shard index, <tt>null</tt> if not applicable.
|
||||
*/
|
||||
public DocsStatus getDocs() {
|
||||
return docs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Peer recovery status (<tt>null</tt> if not applicable). Both real time if an on going recovery
|
||||
* is in progress and summary once it is done.
|
||||
*/
|
||||
public PeerRecoveryStatus peerRecoveryStatus() {
|
||||
return peerRecoveryStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Peer recovery status (<tt>null</tt> if not applicable). Both real time if an on going recovery
|
||||
* is in progress and summary once it done.
|
||||
*/
|
||||
public PeerRecoveryStatus getPeerRecoveryStatus() {
|
||||
return peerRecoveryStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gateway recovery status (<tt>null</tt> if not applicable). Both real time if an on going recovery
|
||||
* is in progress adn summary once it is done.
|
||||
*/
|
||||
public GatewayRecoveryStatus gatewayRecoveryStatus() {
|
||||
return gatewayRecoveryStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gateway recovery status (<tt>null</tt> if not applicable). Both real time if an on going recovery
|
||||
* is in progress adn summary once it is done.
|
||||
*/
|
||||
public GatewayRecoveryStatus getGatewayRecoveryStatus() {
|
||||
return gatewayRecoveryStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* The current on going snapshot to the gateway or the last one if none is on going.
|
||||
*/
|
||||
public GatewaySnapshotStatus gatewaySnapshotStatus() {
|
||||
return gatewaySnapshotStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* The current on going snapshot to the gateway or the last one if none is on going.
|
||||
*/
|
||||
public GatewaySnapshotStatus getGatewaySnapshotStatus() {
|
||||
return gatewaySnapshotStatus();
|
||||
}
|
||||
|
@ -184,7 +212,7 @@ public class ShardStatus extends BroadcastShardOperationResponse {
|
|||
}
|
||||
out.writeLong(translogId);
|
||||
out.writeLong(translogOperations);
|
||||
if (docs == Docs.UNKNOWN) {
|
||||
if (docs == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
|
@ -243,7 +271,7 @@ public class ShardStatus extends BroadcastShardOperationResponse {
|
|||
translogId = in.readLong();
|
||||
translogOperations = in.readLong();
|
||||
if (in.readBoolean()) {
|
||||
docs = new Docs();
|
||||
docs = new DocsStatus();
|
||||
docs.numDocs = in.readInt();
|
||||
docs.maxDoc = in.readInt();
|
||||
docs.deletedDocs = in.readInt();
|
||||
|
|
|
@ -152,7 +152,7 @@ public class TransportIndicesStatusAction extends TransportBroadcastOperationAct
|
|||
shardStatus.translogOperations = indexShard.translog().size();
|
||||
Engine.Searcher searcher = indexShard.searcher();
|
||||
try {
|
||||
shardStatus.docs = new ShardStatus.Docs();
|
||||
shardStatus.docs = new DocsStatus();
|
||||
shardStatus.docs.numDocs = searcher.reader().numDocs();
|
||||
shardStatus.docs.maxDoc = searcher.reader().maxDoc();
|
||||
shardStatus.docs.deletedDocs = searcher.reader().numDeletedDocs();
|
||||
|
|
|
@ -28,24 +28,61 @@ import java.io.IOException;
|
|||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Shard routing represents the state of a shard instance allocated in the cluster.
|
||||
*
|
||||
* @author kimchy (shay.banon)
|
||||
*/
|
||||
public interface ShardRouting extends Streamable, Serializable {
|
||||
|
||||
/**
|
||||
* The shard id.
|
||||
*/
|
||||
ShardId shardId();
|
||||
|
||||
/**
|
||||
* The index name.
|
||||
*/
|
||||
String index();
|
||||
|
||||
/**
|
||||
* The index name.
|
||||
*/
|
||||
String getIndex();
|
||||
|
||||
/**
|
||||
* The shard id.
|
||||
*/
|
||||
int id();
|
||||
|
||||
/**
|
||||
* The shard id.
|
||||
*/
|
||||
int getId();
|
||||
|
||||
/**
|
||||
* The shard state.
|
||||
*/
|
||||
ShardRoutingState state();
|
||||
|
||||
/**
|
||||
* The shard is unassigned (not allocated to any node).
|
||||
*/
|
||||
boolean unassigned();
|
||||
|
||||
/**
|
||||
* The shard is initializing (usually recovering either from peer shard
|
||||
* or from gateway).
|
||||
*/
|
||||
boolean initializing();
|
||||
|
||||
/**
|
||||
* The shard is in started mode.
|
||||
*/
|
||||
boolean started();
|
||||
|
||||
/**
|
||||
* The shard is in relocating mode.
|
||||
*/
|
||||
boolean relocating();
|
||||
|
||||
/**
|
||||
|
@ -53,18 +90,29 @@ public interface ShardRouting extends Streamable, Serializable {
|
|||
*/
|
||||
boolean active();
|
||||
|
||||
/**
|
||||
* The shard is assigned to a node.
|
||||
*/
|
||||
boolean assignedToNode();
|
||||
|
||||
/**
|
||||
* The current node id the shard is allocated to.
|
||||
*/
|
||||
String currentNodeId();
|
||||
|
||||
/**
|
||||
* The relocating node id the shard is either relocating to or relocating from.
|
||||
*/
|
||||
String relocatingNodeId();
|
||||
|
||||
/**
|
||||
* Is this a primary shard.
|
||||
*/
|
||||
boolean primary();
|
||||
|
||||
ShardRoutingState state();
|
||||
|
||||
ShardId shardId();
|
||||
|
||||
/**
|
||||
* A short description of the shard.
|
||||
*/
|
||||
String shortSummary();
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,10 +22,28 @@ package org.elasticsearch.cluster.routing;
|
|||
import org.elasticsearch.ElasticSearchIllegalStateException;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
* The state of the shard as defined by the cluster.
|
||||
*
|
||||
* @author kimchy (shay.banon)
|
||||
*/
|
||||
public enum ShardRoutingState {
|
||||
UNASSIGNED((byte) 1), INITIALIZING((byte) 2), STARTED((byte) 3), RELOCATING((byte) 4);
|
||||
/**
|
||||
* The shard is not assigned to any node.
|
||||
*/
|
||||
UNASSIGNED((byte) 1),
|
||||
/**
|
||||
* The shard is initializing (probably recovering from either a peer shard
|
||||
* or gateway).
|
||||
*/
|
||||
INITIALIZING((byte) 2),
|
||||
/**
|
||||
* The shard is started.
|
||||
*/
|
||||
STARTED((byte) 3),
|
||||
/**
|
||||
* The shard is in the process being relocated.
|
||||
*/
|
||||
RELOCATING((byte) 4);
|
||||
|
||||
private byte value;
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ public class RestIndicesStatusAction extends BaseRestHandler {
|
|||
builder.field("translog_operations", indexStatus.translogOperations());
|
||||
}
|
||||
|
||||
if (indexStatus.docs() != IndexStatus.Docs.UNKNOWN) {
|
||||
if (indexStatus.docs() != null) {
|
||||
builder.startObject("docs");
|
||||
builder.field("num_docs", indexStatus.docs().numDocs());
|
||||
builder.field("max_doc", indexStatus.docs().maxDoc());
|
||||
|
@ -130,7 +130,7 @@ public class RestIndicesStatusAction extends BaseRestHandler {
|
|||
builder.endObject();
|
||||
}
|
||||
|
||||
if (shardStatus.docs() != ShardStatus.Docs.UNKNOWN) {
|
||||
if (shardStatus.docs() != null) {
|
||||
builder.startObject("docs");
|
||||
builder.field("num_docs", shardStatus.docs().numDocs());
|
||||
builder.field("max_doc", shardStatus.docs().maxDoc());
|
||||
|
|
Loading…
Reference in New Issue