Search in sources :

Example 1 with Segment

use of org.opensearch.index.engine.Segment in project OpenSearch by opensearch-project.

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.opensearch.index.IndexService) IndexShard(org.opensearch.index.shard.IndexShard) Segment(org.opensearch.index.engine.Segment)

Example 2 with Segment

use of org.opensearch.index.engine.Segment in project OpenSearch by opensearch-project.

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(0L);
                    table.addCell(segment.isCommitted());
                    table.addCell(segment.isSearch());
                    table.addCell(segment.getVersion());
                    table.addCell(segment.isCompound());
                    table.endRow();
                }
            }
        }
    }
    return table;
}
Also used : Table(org.opensearch.common.Table) ShardSegments(org.opensearch.action.admin.indices.segments.ShardSegments) IndexShardSegments(org.opensearch.action.admin.indices.segments.IndexShardSegments) IndexShardSegments(org.opensearch.action.admin.indices.segments.IndexShardSegments) IndexSegments(org.opensearch.action.admin.indices.segments.IndexSegments) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) Segment(org.opensearch.index.engine.Segment)

Example 3 with Segment

use of org.opensearch.index.engine.Segment in project OpenSearch by opensearch-project.

the class IndicesSegmentResponse method addCustomXContentFields.

@Override
protected void addCustomXContentFields(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.humanReadableField(Fields.SIZE_IN_BYTES, Fields.SIZE, segment.getSize());
                    builder.humanReadableField(Fields.MEMORY_IN_BYTES, Fields.MEMORY, segment.getZeroMemory());
                    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.getSegmentSort() != null) {
                        toXContent(builder, segment.getSegmentSort());
                    }
                    if (segment.ramTree != null) {
                        builder.startArray(Fields.RAM_TREE);
                        for (Accountable child : segment.ramTree.getChildResources()) {
                            toXContent(builder, child);
                        }
                        builder.endArray();
                    }
                    if (segment.attributes != null && segment.attributes.isEmpty() == false) {
                        builder.field("attributes", segment.attributes);
                    }
                    builder.endObject();
                }
                builder.endObject();
                builder.endObject();
            }
            builder.endArray();
        }
        builder.endObject();
        builder.endObject();
    }
    builder.endObject();
}
Also used : Accountable(org.apache.lucene.util.Accountable) Segment(org.opensearch.index.engine.Segment)

Example 4 with Segment

use of org.opensearch.index.engine.Segment in project OpenSearch by opensearch-project.

the class IndicesSegmentResponseTests method testToXContentSerialiationWithSortedFields.

public void testToXContentSerialiationWithSortedFields() throws Exception {
    ShardRouting shardRouting = TestShardRouting.newShardRouting("foo", 0, "node_id", true, ShardRoutingState.STARTED);
    Segment segment = new Segment("my");
    SortField sortField = new SortField("foo", SortField.Type.STRING);
    sortField.setMissingValue(SortField.STRING_LAST);
    segment.segmentSort = new Sort(sortField);
    ShardSegments shardSegments = new ShardSegments(shardRouting, Collections.singletonList(segment));
    IndicesSegmentResponse response = new IndicesSegmentResponse(new ShardSegments[] { shardSegments }, 1, 1, 0, Collections.emptyList());
    try (XContentBuilder builder = jsonBuilder()) {
        response.toXContent(builder, ToXContent.EMPTY_PARAMS);
    }
}
Also used : Sort(org.apache.lucene.search.Sort) SortField(org.apache.lucene.search.SortField) ShardRouting(org.opensearch.cluster.routing.ShardRouting) TestShardRouting(org.opensearch.cluster.routing.TestShardRouting) Segment(org.opensearch.index.engine.Segment) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 5 with Segment

use of org.opensearch.index.engine.Segment in project OpenSearch by opensearch-project.

the class OpenSearchIntegTestCase method assertSortedSegments.

/**
 * Asserts that all segments are sorted with the provided {@link Sort}.
 */
public void assertSortedSegments(String indexName, Sort expectedIndexSort) {
    IndicesSegmentResponse segmentResponse = client().admin().indices().prepareSegments(indexName).execute().actionGet();
    IndexSegments indexSegments = segmentResponse.getIndices().get(indexName);
    for (IndexShardSegments indexShardSegments : indexSegments.getShards().values()) {
        for (ShardSegments shardSegments : indexShardSegments.getShards()) {
            for (Segment segment : shardSegments) {
                assertThat(expectedIndexSort, equalTo(segment.getSegmentSort()));
            }
        }
    }
}
Also used : ShardSegments(org.opensearch.action.admin.indices.segments.ShardSegments) IndexShardSegments(org.opensearch.action.admin.indices.segments.IndexShardSegments) IndicesSegmentResponse(org.opensearch.action.admin.indices.segments.IndicesSegmentResponse) IndexShardSegments(org.opensearch.action.admin.indices.segments.IndexShardSegments) IndexSegments(org.opensearch.action.admin.indices.segments.IndexSegments) Segment(org.opensearch.index.engine.Segment)

Aggregations

Segment (org.opensearch.index.engine.Segment)5 IndexSegments (org.opensearch.action.admin.indices.segments.IndexSegments)2 IndexShardSegments (org.opensearch.action.admin.indices.segments.IndexShardSegments)2 ShardSegments (org.opensearch.action.admin.indices.segments.ShardSegments)2 Sort (org.apache.lucene.search.Sort)1 SortField (org.apache.lucene.search.SortField)1 Accountable (org.apache.lucene.util.Accountable)1 IndicesSegmentResponse (org.opensearch.action.admin.indices.segments.IndicesSegmentResponse)1 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)1 ShardRouting (org.opensearch.cluster.routing.ShardRouting)1 TestShardRouting (org.opensearch.cluster.routing.TestShardRouting)1 Table (org.opensearch.common.Table)1 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)1 IndexService (org.opensearch.index.IndexService)1 IndexShard (org.opensearch.index.shard.IndexShard)1