Search in sources :

Example 1 with ShardSegments

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

use of org.elasticsearch.action.admin.indices.segments.ShardSegments 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 3 with ShardSegments

use of org.elasticsearch.action.admin.indices.segments.ShardSegments in project elasticsearch by elastic.

the class CompletionSuggestSearchIT method testPrunedSegments.

// see #3555
public void testPrunedSegments() throws IOException {
    createIndexAndMappingAndSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0).build(), completionMappingBuilder);
    client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder().startObject().startObject(FIELD).startArray("input").value("The Beatles").endArray().endObject().endObject()).get();
    client().prepareIndex(INDEX, TYPE, "2").setSource(jsonBuilder().startObject().field("somefield", "somevalue").endObject()).get();
    ForceMergeResponse actionGet = client().admin().indices().prepareForceMerge().setFlush(true).setMaxNumSegments(1).execute().actionGet();
    assertAllSuccessful(actionGet);
    refresh();
    // update the first one and then merge.. the target segment will have no value in FIELD
    client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder().startObject().field("somefield", "somevalue").endObject()).get();
    actionGet = client().admin().indices().prepareForceMerge().setFlush(true).setMaxNumSegments(1).execute().actionGet();
    assertAllSuccessful(actionGet);
    refresh();
    assertSuggestions("b");
    assertThat(2L, equalTo(client().prepareSearch(INDEX).setSize(0).get().getHits().getTotalHits()));
    for (IndexShardSegments seg : client().admin().indices().prepareSegments().get().getIndices().get(INDEX)) {
        ShardSegments[] shards = seg.getShards();
        for (ShardSegments shardSegments : shards) {
            assertThat(shardSegments.getSegments().size(), equalTo(1));
        }
    }
}
Also used : ForceMergeResponse(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse) ShardSegments(org.elasticsearch.action.admin.indices.segments.ShardSegments) IndexShardSegments(org.elasticsearch.action.admin.indices.segments.IndexShardSegments) IndexShardSegments(org.elasticsearch.action.admin.indices.segments.IndexShardSegments)

Example 4 with ShardSegments

use of org.elasticsearch.action.admin.indices.segments.ShardSegments in project elasticsearch by elastic.

the class OldIndexUtils method assertUpgraded.

public static void assertUpgraded(Client client, String... index) throws Exception {
    for (IndexUpgradeStatus status : getUpgradeStatus(client, index)) {
        assertTrue("index " + status.getIndex() + " should not be zero sized", status.getTotalBytes() != 0);
        assertEquals("index " + status.getIndex() + " should be upgraded", 0, status.getToUpgradeBytes());
    }
    // double check using the segments api that all segments are actually upgraded
    IndicesSegmentResponse segsRsp;
    if (index == null) {
        segsRsp = client.admin().indices().prepareSegments().execute().actionGet();
    } else {
        segsRsp = client.admin().indices().prepareSegments(index).execute().actionGet();
    }
    for (IndexSegments indexSegments : segsRsp.getIndices().values()) {
        for (IndexShardSegments shard : indexSegments) {
            for (ShardSegments segs : shard.getShards()) {
                for (Segment seg : segs.getSegments()) {
                    assertEquals("Index " + indexSegments.getIndex() + " has unupgraded segment " + seg.toString(), Version.CURRENT.luceneVersion.major, seg.version.major);
                    assertEquals("Index " + indexSegments.getIndex() + " has unupgraded segment " + seg.toString(), Version.CURRENT.luceneVersion.minor, seg.version.minor);
                }
            }
        }
    }
}
Also used : ShardSegments(org.elasticsearch.action.admin.indices.segments.ShardSegments) IndexShardSegments(org.elasticsearch.action.admin.indices.segments.IndexShardSegments) IndexUpgradeStatus(org.elasticsearch.action.admin.indices.upgrade.get.IndexUpgradeStatus) 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)

Aggregations

IndexShardSegments (org.elasticsearch.action.admin.indices.segments.IndexShardSegments)4 ShardSegments (org.elasticsearch.action.admin.indices.segments.ShardSegments)4 IndexSegments (org.elasticsearch.action.admin.indices.segments.IndexSegments)3 Segment (org.elasticsearch.index.engine.Segment)3 IndicesSegmentResponse (org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse)2 Version (org.elasticsearch.Version)1 ForceMergeResponse (org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse)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 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)1 Table (org.elasticsearch.common.Table)1 RecoveryState (org.elasticsearch.indices.recovery.RecoveryState)1