Search in sources :

Example 1 with Segment

use of org.elasticsearch.index.engine.Segment in project elasticsearch by elastic.

the class RestSegmentsAction method buildTable.

private Table buildTable(final RestRequest request, ClusterStateResponse state, Map<String, IndexSegments> indicesSegments) {
    Table table = getTableWithHeader(request);
    DiscoveryNodes nodes = state.getState().nodes();
    for (IndexSegments indexSegments : indicesSegments.values()) {
        Map<Integer, IndexShardSegments> shards = indexSegments.getShards();
        for (IndexShardSegments indexShardSegments : shards.values()) {
            ShardSegments[] shardSegments = indexShardSegments.getShards();
            for (ShardSegments shardSegment : shardSegments) {
                List<Segment> segments = shardSegment.getSegments();
                for (Segment segment : segments) {
                    table.startRow();
                    table.addCell(shardSegment.getShardRouting().getIndexName());
                    table.addCell(shardSegment.getShardRouting().getId());
                    table.addCell(shardSegment.getShardRouting().primary() ? "p" : "r");
                    table.addCell(nodes.get(shardSegment.getShardRouting().currentNodeId()).getHostAddress());
                    table.addCell(shardSegment.getShardRouting().currentNodeId());
                    table.addCell(segment.getName());
                    table.addCell(segment.getGeneration());
                    table.addCell(segment.getNumDocs());
                    table.addCell(segment.getDeletedDocs());
                    table.addCell(segment.getSize());
                    table.addCell(segment.getMemoryInBytes());
                    table.addCell(segment.isCommitted());
                    table.addCell(segment.isSearch());
                    table.addCell(segment.getVersion());
                    table.addCell(segment.isCompound());
                    table.endRow();
                }
            }
        }
    }
    return table;
}
Also used : Table(org.elasticsearch.common.Table) ShardSegments(org.elasticsearch.action.admin.indices.segments.ShardSegments) IndexShardSegments(org.elasticsearch.action.admin.indices.segments.IndexShardSegments) IndexShardSegments(org.elasticsearch.action.admin.indices.segments.IndexShardSegments) IndexSegments(org.elasticsearch.action.admin.indices.segments.IndexSegments) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Segment(org.elasticsearch.index.engine.Segment)

Example 2 with Segment

use of org.elasticsearch.index.engine.Segment in project elasticsearch by elastic.

the class IndicesSegmentResponse method toXContent.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject(Fields.INDICES);
    for (IndexSegments indexSegments : getIndices().values()) {
        builder.startObject(indexSegments.getIndex());
        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;
}
Also used : Accountable(org.apache.lucene.util.Accountable) Segment(org.elasticsearch.index.engine.Segment)

Example 3 with Segment

use of org.elasticsearch.index.engine.Segment in project elasticsearch by elastic.

the class ShardSegments method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    shardRouting.writeTo(out);
    out.writeVInt(segments.size());
    for (Segment segment : segments) {
        segment.writeTo(out);
    }
}
Also used : Segment(org.elasticsearch.index.engine.Segment)

Example 4 with Segment

use of org.elasticsearch.index.engine.Segment in project elasticsearch by elastic.

the class OldIndexBackwardsCompatibilityIT method assertIndexSanity.

void assertIndexSanity(String indexName, Version indexCreated) {
    GetIndexResponse getIndexResponse = client().admin().indices().prepareGetIndex().addIndices(indexName).get();
    assertEquals(1, getIndexResponse.indices().length);
    assertEquals(indexName, getIndexResponse.indices()[0]);
    Version actualVersionCreated = Version.indexCreated(getIndexResponse.getSettings().get(indexName));
    assertEquals(indexCreated, actualVersionCreated);
    ensureYellow(indexName);
    RecoveryResponse recoveryResponse = client().admin().indices().prepareRecoveries(indexName).setDetailed(true).setActiveOnly(false).get();
    boolean foundTranslog = false;
    for (List<RecoveryState> states : recoveryResponse.shardRecoveryStates().values()) {
        for (RecoveryState state : states) {
            if (state.getStage() == RecoveryState.Stage.DONE && state.getPrimary() && state.getRecoverySource().getType() == RecoverySource.Type.EXISTING_STORE) {
                assertFalse("more than one primary recoverd?", foundTranslog);
                assertNotEquals(0, state.getTranslog().recoveredOperations());
                foundTranslog = true;
            }
        }
    }
    assertTrue("expected translog but nothing was recovered", foundTranslog);
    IndicesSegmentResponse segmentsResponse = client().admin().indices().prepareSegments(indexName).get();
    IndexSegments segments = segmentsResponse.getIndices().get(indexName);
    int numCurrent = 0;
    int numBWC = 0;
    for (IndexShardSegments indexShardSegments : segments) {
        for (ShardSegments shardSegments : indexShardSegments) {
            for (Segment segment : shardSegments) {
                if (indexCreated.luceneVersion.equals(segment.version)) {
                    numBWC++;
                    if (Version.CURRENT.luceneVersion.equals(segment.version)) {
                        numCurrent++;
                    }
                } else if (Version.CURRENT.luceneVersion.equals(segment.version)) {
                    numCurrent++;
                } else {
                    fail("unexpected version " + segment.version);
                }
            }
        }
    }
    assertNotEquals("expected at least 1 current segment after translog recovery", 0, numCurrent);
    assertNotEquals("expected at least 1 old segment", 0, numBWC);
    SearchResponse test = client().prepareSearch(indexName).get();
    assertThat(test.getHits().getTotalHits(), greaterThanOrEqualTo(1L));
}
Also used : IndicesSegmentResponse(org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse) IndexShardSegments(org.elasticsearch.action.admin.indices.segments.IndexShardSegments) IndexSegments(org.elasticsearch.action.admin.indices.segments.IndexSegments) Segment(org.elasticsearch.index.engine.Segment) RecoveryResponse(org.elasticsearch.action.admin.indices.recovery.RecoveryResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse) Version(org.elasticsearch.Version) GetIndexResponse(org.elasticsearch.action.admin.indices.get.GetIndexResponse) ShardSegments(org.elasticsearch.action.admin.indices.segments.ShardSegments) IndexShardSegments(org.elasticsearch.action.admin.indices.segments.IndexShardSegments) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState)

Example 5 with Segment

use of org.elasticsearch.index.engine.Segment in project elasticsearch by elastic.

the class TransportUpgradeStatusAction method shardOperation.

@Override
protected ShardUpgradeStatus shardOperation(UpgradeStatusRequest request, ShardRouting shardRouting) {
    IndexService indexService = indicesService.indexServiceSafe(shardRouting.shardId().getIndex());
    IndexShard indexShard = indexService.getShard(shardRouting.shardId().id());
    List<Segment> segments = indexShard.segments(false);
    long total_bytes = 0;
    long to_upgrade_bytes = 0;
    long to_upgrade_bytes_ancient = 0;
    for (Segment seg : segments) {
        total_bytes += seg.sizeInBytes;
        if (seg.version.major != Version.CURRENT.luceneVersion.major) {
            to_upgrade_bytes_ancient += seg.sizeInBytes;
            to_upgrade_bytes += seg.sizeInBytes;
        } else if (seg.version.minor != Version.CURRENT.luceneVersion.minor) {
            // TODO: this comparison is bogus! it would cause us to upgrade even with the same format
            // instead, we should check if the codec has changed
            to_upgrade_bytes += seg.sizeInBytes;
        }
    }
    return new ShardUpgradeStatus(indexShard.routingEntry(), total_bytes, to_upgrade_bytes, to_upgrade_bytes_ancient);
}
Also used : IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) Segment(org.elasticsearch.index.engine.Segment)

Aggregations

Segment (org.elasticsearch.index.engine.Segment)8 IndexSegments (org.elasticsearch.action.admin.indices.segments.IndexSegments)3 IndexShardSegments (org.elasticsearch.action.admin.indices.segments.IndexShardSegments)3 ShardSegments (org.elasticsearch.action.admin.indices.segments.ShardSegments)3 IndicesSegmentResponse (org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse)2 FieldInfo (org.apache.lucene.index.FieldInfo)1 IndexReader (org.apache.lucene.index.IndexReader)1 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)1 Directory (org.apache.lucene.store.Directory)1 Accountable (org.apache.lucene.util.Accountable)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 Version (org.elasticsearch.Version)1 ShardOperationFailedException (org.elasticsearch.action.ShardOperationFailedException)1 GetIndexResponse (org.elasticsearch.action.admin.indices.get.GetIndexResponse)1 RecoveryResponse (org.elasticsearch.action.admin.indices.recovery.RecoveryResponse)1 IndexUpgradeStatus (org.elasticsearch.action.admin.indices.upgrade.get.IndexUpgradeStatus)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 DefaultShardOperationFailedException (org.elasticsearch.action.support.DefaultShardOperationFailedException)1 BroadcastShardOperationFailedException (org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException)1 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)1