Esempio n. 1
0
 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));
 }
 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));
 }