Java Code Examples for org.elasticsearch.indices.recovery.RecoveryState#Index

The following examples show how to use org.elasticsearch.indices.recovery.RecoveryState#Index . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StoreRecovery.java    From crate with Apache License 2.0 5 votes vote down vote up
private void addRecoveredFileDetails(SegmentInfos si, Store store, RecoveryState.Index index) throws IOException {
    final Directory directory = store.directory();
    for (String name : Lucene.files(si)) {
        long length = directory.fileLength(name);
        index.addFileDetail(name, length, true);
    }
}
 
Example 2
Source File: StoreRecovery.java    From crate with Apache License 2.0 4 votes vote down vote up
void addIndices(final RecoveryState.Index indexRecoveryStats,
                final Directory target,
                final Directory[] sources,
                final long maxSeqNo,
                final long maxUnsafeAutoIdTimestamp,
                IndexMetaData indexMetaData,
                int shardId,
                boolean split) throws IOException {

    // clean target directory (if previous recovery attempt failed) and create a fresh segment file with the proper lucene version
    Lucene.cleanLuceneIndex(target);
    assert sources.length > 0;
    final int luceneIndexCreatedVersionMajor = Lucene.readSegmentInfos(sources[0]).getIndexCreatedVersionMajor();
    new SegmentInfos(luceneIndexCreatedVersionMajor).commit(target);

    final Directory hardLinkOrCopyTarget = new org.apache.lucene.store.HardlinkCopyDirectoryWrapper(target);

    IndexWriterConfig iwc = new IndexWriterConfig(null)
        .setSoftDeletesField(Lucene.SOFT_DELETES_FIELD)
        .setCommitOnClose(false)
        // we don't want merges to happen here - we call maybe merge on the engine
        // later once we stared it up otherwise we would need to wait for it here
        // we also don't specify a codec here and merges should use the engines for this index
        .setMergePolicy(NoMergePolicy.INSTANCE)
        .setOpenMode(IndexWriterConfig.OpenMode.APPEND);

    try (IndexWriter writer = new IndexWriter(new StatsDirectoryWrapper(hardLinkOrCopyTarget, indexRecoveryStats), iwc)) {
        writer.addIndexes(sources);
        if (split) {
            writer.deleteDocuments(new ShardSplittingQuery(indexMetaData, shardId));
        }
        /*
         * We set the maximum sequence number and the local checkpoint on the target to the maximum of the maximum sequence numbers on
         * the source shards. This ensures that history after this maximum sequence number can advance and we have correct
         * document-level semantics.
         */
        writer.setLiveCommitData(() -> {
            final HashMap<String, String> liveCommitData = new HashMap<>(3);
            liveCommitData.put(SequenceNumbers.MAX_SEQ_NO, Long.toString(maxSeqNo));
            liveCommitData.put(SequenceNumbers.LOCAL_CHECKPOINT_KEY, Long.toString(maxSeqNo));
            liveCommitData.put(Engine.MAX_UNSAFE_AUTO_ID_TIMESTAMP_COMMIT_ID, Long.toString(maxUnsafeAutoIdTimestamp));
            return liveCommitData.entrySet().iterator();
        });
        writer.commit();
    }
}
 
Example 3
Source File: StoreRecovery.java    From crate with Apache License 2.0 4 votes vote down vote up
StatsDirectoryWrapper(Directory in, RecoveryState.Index indexRecoveryStats) {
    super(in);
    this.index = indexRecoveryStats;
}
 
Example 4
Source File: SysShardsExpressionsTest.java    From crate with Apache License 2.0 4 votes vote down vote up
private IndexShard mockIndexShard() {
    IndexService indexService = mock(IndexService.class);
    indexUUID = UUIDs.randomBase64UUID();
    Index index = new Index(indexName, indexUUID);
    ShardId shardId = new ShardId(indexName, indexUUID, 1);

    IndexShard indexShard = mock(IndexShard.class);
    when(indexService.index()).thenReturn(index);
    when(indexShard.shardId()).thenReturn(shardId);
    when(indexShard.state()).thenReturn(IndexShardState.STARTED);

    StoreStats storeStats = new StoreStats(123456L);
    when(indexShard.storeStats()).thenReturn(storeStats);

    Path dataPath = Paths.get("/dummy/" + indexUUID + "/" + shardId.id());
    when(indexShard.shardPath()).thenReturn(new ShardPath(false, dataPath, dataPath, shardId));

    DocsStats docsStats = new DocsStats(654321L, 0L, 200L);
    when(indexShard.docStats()).thenReturn(docsStats).thenThrow(IllegalIndexShardStateException.class);

    ShardRouting shardRouting = ShardRouting.newUnassigned(
        shardId, true, RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    shardRouting = ShardRoutingHelper.initialize(shardRouting, "node1");
    shardRouting = ShardRoutingHelper.moveToStarted(shardRouting);
    shardRouting = ShardRoutingHelper.relocate(shardRouting, "node_X");
    when(indexShard.routingEntry()).thenReturn(shardRouting);
    when(indexShard.minimumCompatibleVersion()).thenReturn(Version.LATEST);

    RecoveryState recoveryState = mock(RecoveryState.class);
    when(indexShard.recoveryState()).thenReturn(recoveryState);
    RecoveryState.Index recoveryStateIndex = mock(RecoveryState.Index.class);
    RecoveryState.Timer recoveryStateTimer = mock(RecoveryState.Timer.class);
    when(recoveryState.getRecoverySource()).thenReturn(RecoverySource.PeerRecoverySource.INSTANCE);
    when(recoveryState.getIndex()).thenReturn(recoveryStateIndex);
    when(recoveryState.getStage()).thenReturn(RecoveryState.Stage.DONE);
    when(recoveryState.getTimer()).thenReturn(recoveryStateTimer);

    when(recoveryStateIndex.totalBytes()).thenReturn(2048L);
    when(recoveryStateIndex.reusedBytes()).thenReturn(1024L);
    when(recoveryStateIndex.recoveredBytes()).thenReturn(1024L);
    when(recoveryStateIndex.totalFileCount()).thenReturn(2);
    when(recoveryStateIndex.reusedFileCount()).thenReturn(1);
    when(recoveryStateIndex.recoveredFileCount()).thenReturn(1);
    when(recoveryStateTimer.time()).thenReturn(10000L);

    return indexShard;
}