Search in sources :

Example 1 with IndexSegments

use of org.opensearch.action.admin.indices.segments.IndexSegments 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 2 with IndexSegments

use of org.opensearch.action.admin.indices.segments.IndexSegments in project OpenSearch by opensearch-project.

the class RestSegmentsAction method doCatRequest.

@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    clusterStateRequest.clear().nodes(true).routingTable(true).indices(indices);
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            final IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest();
            indicesSegmentsRequest.indices(indices);
            client.admin().indices().segments(indicesSegmentsRequest, new RestResponseListener<IndicesSegmentResponse>(channel) {

                @Override
                public RestResponse buildResponse(final IndicesSegmentResponse indicesSegmentResponse) throws Exception {
                    final Map<String, IndexSegments> indicesSegments = indicesSegmentResponse.getIndices();
                    Table tab = buildTable(request, clusterStateResponse, indicesSegments);
                    return RestTable.buildResponse(tab, channel);
                }
            });
        }
    });
}
Also used : ShardSegments(org.opensearch.action.admin.indices.segments.ShardSegments) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) IndicesSegmentsRequest(org.opensearch.action.admin.indices.segments.IndicesSegmentsRequest) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) IndexSegments(org.opensearch.action.admin.indices.segments.IndexSegments) RestRequest(org.opensearch.rest.RestRequest) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) IndexShardSegments(org.opensearch.action.admin.indices.segments.IndexShardSegments) Table(org.opensearch.common.Table) RestResponse(org.opensearch.rest.RestResponse) Strings(org.opensearch.common.Strings) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) RestActionListener(org.opensearch.rest.action.RestActionListener) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Segment(org.opensearch.index.engine.Segment) IndicesSegmentResponse(org.opensearch.action.admin.indices.segments.IndicesSegmentResponse) RestResponseListener(org.opensearch.rest.action.RestResponseListener) Table(org.opensearch.common.Table) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) RestResponseListener(org.opensearch.rest.action.RestResponseListener) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) IndicesSegmentResponse(org.opensearch.action.admin.indices.segments.IndicesSegmentResponse) IndicesSegmentsRequest(org.opensearch.action.admin.indices.segments.IndicesSegmentsRequest) IndexSegments(org.opensearch.action.admin.indices.segments.IndexSegments)

Example 3 with IndexSegments

use of org.opensearch.action.admin.indices.segments.IndexSegments 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

IndexSegments (org.opensearch.action.admin.indices.segments.IndexSegments)3 IndexShardSegments (org.opensearch.action.admin.indices.segments.IndexShardSegments)3 ShardSegments (org.opensearch.action.admin.indices.segments.ShardSegments)3 Segment (org.opensearch.index.engine.Segment)3 IndicesSegmentResponse (org.opensearch.action.admin.indices.segments.IndicesSegmentResponse)2 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)2 Table (org.opensearch.common.Table)2 Arrays.asList (java.util.Arrays.asList)1 Collections.unmodifiableList (java.util.Collections.unmodifiableList)1 List (java.util.List)1 Map (java.util.Map)1 ClusterStateRequest (org.opensearch.action.admin.cluster.state.ClusterStateRequest)1 ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)1 IndicesSegmentsRequest (org.opensearch.action.admin.indices.segments.IndicesSegmentsRequest)1 NodeClient (org.opensearch.client.node.NodeClient)1 Strings (org.opensearch.common.Strings)1 RestRequest (org.opensearch.rest.RestRequest)1 GET (org.opensearch.rest.RestRequest.Method.GET)1 RestResponse (org.opensearch.rest.RestResponse)1 RestActionListener (org.opensearch.rest.action.RestActionListener)1