コード例 #1
0
 private void assertTotalCompoundSegments(int i, int t, String index) {
   IndicesSegmentResponse indicesSegmentResponse =
       client().admin().indices().prepareSegments(index).get();
   IndexSegments indexSegments = indicesSegmentResponse.getIndices().get(index);
   Collection<IndexShardSegments> values = indexSegments.getShards().values();
   int compounds = 0;
   int total = 0;
   for (IndexShardSegments indexShardSegments : values) {
     for (ShardSegments s : indexShardSegments) {
       for (Segment segment : s) {
         if (segment.isSearch() && segment.getNumDocs() > 0) {
           if (segment.isCompound()) {
             compounds++;
           }
           total++;
         }
       }
     }
   }
   assertThat(compounds, Matchers.equalTo(i));
   assertThat(total, Matchers.equalTo(t));
 }
コード例 #2
0
  @Override
  public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject(Fields.INDICES);

    for (IndexSegments indexSegments : getIndices().values()) {
      builder.startObject(indexSegments.getIndex(), XContentBuilder.FieldCaseConversion.NONE);

      builder.startObject(Fields.SHARDS);
      for (IndexShardSegments indexSegment : indexSegments) {
        builder.startArray(Integer.toString(indexSegment.getShardId().id()));
        for (ShardSegments shardSegments : indexSegment) {
          builder.startObject();

          builder.startObject(Fields.ROUTING);
          builder.field(Fields.STATE, shardSegments.getShardRouting().state());
          builder.field(Fields.PRIMARY, shardSegments.getShardRouting().primary());
          builder.field(Fields.NODE, shardSegments.getShardRouting().currentNodeId());
          if (shardSegments.getShardRouting().relocatingNodeId() != null) {
            builder.field(
                Fields.RELOCATING_NODE, shardSegments.getShardRouting().relocatingNodeId());
          }
          builder.endObject();

          builder.field(Fields.NUM_COMMITTED_SEGMENTS, shardSegments.getNumberOfCommitted());
          builder.field(Fields.NUM_SEARCH_SEGMENTS, shardSegments.getNumberOfSearch());

          builder.startObject(Fields.SEGMENTS);
          for (Segment segment : shardSegments) {
            builder.startObject(segment.getName());
            builder.field(Fields.GENERATION, segment.getGeneration());
            builder.field(Fields.NUM_DOCS, segment.getNumDocs());
            builder.field(Fields.DELETED_DOCS, segment.getDeletedDocs());
            builder.byteSizeField(Fields.SIZE_IN_BYTES, Fields.SIZE, segment.getSizeInBytes());
            builder.byteSizeField(
                Fields.MEMORY_IN_BYTES, Fields.MEMORY, segment.getMemoryInBytes());
            builder.field(Fields.COMMITTED, segment.isCommitted());
            builder.field(Fields.SEARCH, segment.isSearch());
            if (segment.getVersion() != null) {
              builder.field(Fields.VERSION, segment.getVersion());
            }
            if (segment.isCompound() != null) {
              builder.field(Fields.COMPOUND, segment.isCompound());
            }
            if (segment.getMergeId() != null) {
              builder.field(Fields.MERGE_ID, segment.getMergeId());
            }
            if (segment.ramTree != null) {
              builder.startArray(Fields.RAM_TREE);
              for (Accountable child : segment.ramTree.getChildResources()) {
                toXContent(builder, child);
              }
              builder.endArray();
            }
            builder.endObject();
          }
          builder.endObject();

          builder.endObject();
        }
        builder.endArray();
      }
      builder.endObject();

      builder.endObject();
    }

    builder.endObject();
    return builder;
  }