Java Code Examples for org.elasticsearch.index.engine.Engine#CommitId

The following examples show how to use org.elasticsearch.index.engine.Engine#CommitId . 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: IndexShard.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Executes the given flush request against the engine.
 *
 * @param request the flush request
 * @return the commit ID
 */
public Engine.CommitId flush(FlushRequest request) {
    final boolean waitIfOngoing = request.waitIfOngoing();
    final boolean force = request.force();
    logger.trace("flush with {}", request);
    /*
     * We allow flushes while recovery since we allow operations to happen while recovering and we want to keep the translog under
     * control (up to deletes, which we do not GC). Yet, we do not use flush internally to clear deletes and flush the index writer
     * since we use Engine#writeIndexingBuffer for this now.
     */
    verifyNotClosed();
    final Engine engine = getEngine();
    if (engine.isRecovering()) {
        throw new IllegalIndexShardStateException(
                shardId(),
                state,
                "flush is only allowed if the engine is not recovery from translog");
    }
    final long time = System.nanoTime();
    final Engine.CommitId commitId = engine.flush(force, waitIfOngoing);
    engine.refresh("flush"); // TODO this is technically wrong we should remove this in 7.0
    flushMetric.inc(System.nanoTime() - time);
    return commitId;
}
 
Example 2
Source File: IndexShard.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public Engine.CommitId flush(FlushRequest request) throws ElasticsearchException {
    boolean waitIfOngoing = request.waitIfOngoing();
    boolean force = request.force();
    if (logger.isTraceEnabled()) {
        logger.trace("flush with {}", request);
    }
    // we allows flush while recovering, since we allow for operations to happen
    // while recovering, and we want to keep the translog at bay (up to deletes, which
    // we don't gc).
    verifyStartedOrRecovering();

    long time = System.nanoTime();
    Engine.CommitId commitId = engine().flush(force, waitIfOngoing);
    flushMetric.inc(System.nanoTime() - time);
    return commitId;

}
 
Example 3
Source File: SyncedFlushService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private PreSyncedFlushResponse performPreSyncedFlush(PreShardSyncedFlushRequest request) {
    IndexShard indexShard = indicesService.indexServiceSafe(request.shardId().getIndex()).shardSafe(request.shardId().id());
    FlushRequest flushRequest = new FlushRequest().force(false).waitIfOngoing(true);
    logger.trace("{} performing pre sync flush", request.shardId());
    Engine.CommitId commitId = indexShard.flush(flushRequest);
    logger.trace("{} pre sync flush done. commit id {}", request.shardId(), commitId);
    return new PreSyncedFlushResponse(commitId);
}
 
Example 4
Source File: IndexShard.java    From crate with Apache License 2.0 5 votes vote down vote up
public Engine.SyncedFlushResult syncFlush(String syncId, Engine.CommitId expectedCommitId) {
    verifyNotClosed();
    logger.trace("trying to sync flush. sync id [{}]. expected commit id [{}]]", syncId, expectedCommitId);
    Engine engine = getEngine();
    if (engine.isRecovering()) {
        throw new IllegalIndexShardStateException(shardId(), state, "syncFlush is only allowed if the engine is not recovery" +
            " from translog");
    }
    return engine.syncFlush(syncId, expectedCommitId);
}
 
Example 5
Source File: SyncedFlushService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    shardId = ShardId.readShardId(in);
    expectedCommitId = new Engine.CommitId(in);
    syncId = in.readString();
}
 
Example 6
Source File: SyncedFlushService.java    From crate with Apache License 2.0 5 votes vote down vote up
private PreSyncedFlushResponse performPreSyncedFlush(PreShardSyncedFlushRequest request) {
    IndexShard indexShard = indicesService.indexServiceSafe(request.shardId().getIndex()).getShard(request.shardId().id());
    FlushRequest flushRequest = new FlushRequest().force(false).waitIfOngoing(true);
    LOGGER.trace("{} performing pre sync flush", request.shardId());
    indexShard.flush(flushRequest);
    final CommitStats commitStats = indexShard.commitStats();
    final Engine.CommitId commitId = commitStats.getRawCommitId();
    LOGGER.trace("{} pre sync flush done. commit id {}, num docs {}", request.shardId(), commitId, commitStats.getNumDocs());
    return new PreSyncedFlushResponse(commitId, commitStats.getNumDocs(), commitStats.syncId());
}
 
Example 7
Source File: IndexShard.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public Engine.SyncedFlushResult syncFlush(String syncId, Engine.CommitId expectedCommitId) {
    verifyStartedOrRecovering();
    logger.trace("trying to sync flush. sync id [{}]. expected commit id [{}]]", syncId, expectedCommitId);
    return engine().syncFlush(syncId, expectedCommitId);
}
 
Example 8
Source File: SyncedFlushService.java    From crate with Apache License 2.0 4 votes vote down vote up
public Engine.CommitId expectedCommitId() {
    return expectedCommitId;
}
 
Example 9
Source File: SyncedFlushService.java    From crate with Apache License 2.0 4 votes vote down vote up
public ShardSyncedFlushRequest(StreamInput in) throws IOException {
    super(in);
    shardId = new ShardId(in);
    expectedCommitId = new Engine.CommitId(in);
    syncId = in.readString();
}
 
Example 10
Source File: SyncedFlushService.java    From crate with Apache License 2.0 4 votes vote down vote up
public ShardSyncedFlushRequest(ShardId shardId, String syncId, Engine.CommitId expectedCommitId) {
    this.expectedCommitId = expectedCommitId;
    this.shardId = shardId;
    this.syncId = syncId;
}
 
Example 11
Source File: SyncedFlushService.java    From crate with Apache License 2.0 4 votes vote down vote up
public PreSyncedFlushResponse(StreamInput in) throws IOException {
    commitId = new Engine.CommitId(in);
    numDocs = in.readInt();
    existingSyncId = in.readOptionalString();
}
 
Example 12
Source File: SyncedFlushService.java    From crate with Apache License 2.0 4 votes vote down vote up
PreSyncedFlushResponse(Engine.CommitId commitId, int numDocs, String existingSyncId) {
    this.commitId = commitId;
    this.numDocs = numDocs;
    this.existingSyncId = existingSyncId;
}
 
Example 13
Source File: SyncedFlushService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
void sendSyncRequests(final String syncId, final List<ShardRouting> shards, ClusterState state, Map<String, Engine.CommitId> expectedCommitIds,
                      final ShardId shardId, final int totalShards, final ActionListener<ShardsSyncedFlushResult> listener) {
    final CountDown countDown = new CountDown(shards.size());
    final Map<ShardRouting, ShardSyncedFlushResponse> results = ConcurrentCollections.newConcurrentMap();
    for (final ShardRouting shard : shards) {
        final DiscoveryNode node = state.nodes().get(shard.currentNodeId());
        if (node == null) {
            logger.trace("{} is assigned to an unknown node. skipping for sync id [{}]. shard routing {}", shardId, syncId, shard);
            results.put(shard, new ShardSyncedFlushResponse("unknown node"));
            contDownAndSendResponseIfDone(syncId, shards, shardId, totalShards, listener, countDown, results);
            continue;
        }
        final Engine.CommitId expectedCommitId = expectedCommitIds.get(shard.currentNodeId());
        if (expectedCommitId == null) {
            logger.trace("{} can't resolve expected commit id for current node, skipping for sync id [{}]. shard routing {}", shardId, syncId, shard);
            results.put(shard, new ShardSyncedFlushResponse("no commit id from pre-sync flush"));
            contDownAndSendResponseIfDone(syncId, shards, shardId, totalShards, listener, countDown, results);
            continue;
        }
        logger.trace("{} sending synced flush request to {}. sync id [{}].", shardId, shard, syncId);
        transportService.sendRequest(node, SYNCED_FLUSH_ACTION_NAME, new ShardSyncedFlushRequest(shard.shardId(), syncId, expectedCommitId),
                new BaseTransportResponseHandler<ShardSyncedFlushResponse>() {
                    @Override
                    public ShardSyncedFlushResponse newInstance() {
                        return new ShardSyncedFlushResponse();
                    }

                    @Override
                    public void handleResponse(ShardSyncedFlushResponse response) {
                        ShardSyncedFlushResponse existing = results.put(shard, response);
                        assert existing == null : "got two answers for node [" + node + "]";
                        // count after the assert so we won't decrement twice in handleException
                        contDownAndSendResponseIfDone(syncId, shards, shardId, totalShards, listener, countDown, results);
                    }

                    @Override
                    public void handleException(TransportException exp) {
                        logger.trace("{} error while performing synced flush on [{}], skipping", exp, shardId, shard);
                        results.put(shard, new ShardSyncedFlushResponse(exp.getMessage()));
                        contDownAndSendResponseIfDone(syncId, shards, shardId, totalShards, listener, countDown, results);
                    }

                    @Override
                    public String executor() {
                        return ThreadPool.Names.SAME;
                    }
                });
    }

}
 
Example 14
Source File: SyncedFlushService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public Engine.CommitId expectedCommitId() {
    return expectedCommitId;
}
 
Example 15
Source File: SyncedFlushService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public ShardSyncedFlushRequest(ShardId shardId, String syncId, Engine.CommitId expectedCommitId) {
    this.expectedCommitId = expectedCommitId;
    this.shardId = shardId;
    this.syncId = syncId;
}
 
Example 16
Source File: SyncedFlushService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    commitId = new Engine.CommitId(in);
}
 
Example 17
Source File: SyncedFlushService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public Engine.CommitId commitId() {
    return commitId;
}
 
Example 18
Source File: SyncedFlushService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
PreSyncedFlushResponse(Engine.CommitId commitId) {
    this.commitId = commitId;
}
 
Example 19
Source File: SyncedFlushService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * send presync requests to all started copies of the given shard
 */
void sendPreSyncRequests(final List<ShardRouting> shards, final ClusterState state, final ShardId shardId, final ActionListener<Map<String, Engine.CommitId>> listener) {
    final CountDown countDown = new CountDown(shards.size());
    final ConcurrentMap<String, Engine.CommitId> commitIds = ConcurrentCollections.newConcurrentMap();
    for (final ShardRouting shard : shards) {
        logger.trace("{} sending pre-synced flush request to {}", shardId, shard);
        final DiscoveryNode node = state.nodes().get(shard.currentNodeId());
        if (node == null) {
            logger.trace("{} shard routing {} refers to an unknown node. skipping.", shardId, shard);
            if (countDown.countDown()) {
                listener.onResponse(commitIds);
            }
            continue;
        }
        transportService.sendRequest(node, PRE_SYNCED_FLUSH_ACTION_NAME, new PreShardSyncedFlushRequest(shard.shardId()), new BaseTransportResponseHandler<PreSyncedFlushResponse>() {
            @Override
            public PreSyncedFlushResponse newInstance() {
                return new PreSyncedFlushResponse();
            }

            @Override
            public void handleResponse(PreSyncedFlushResponse response) {
                Engine.CommitId existing = commitIds.putIfAbsent(node.id(), response.commitId());
                assert existing == null : "got two answers for node [" + node + "]";
                // count after the assert so we won't decrement twice in handleException
                if (countDown.countDown()) {
                    listener.onResponse(commitIds);
                }
            }

            @Override
            public void handleException(TransportException exp) {
                logger.trace("{} error while performing pre synced flush on [{}], skipping", exp, shardId, shard);
                if (countDown.countDown()) {
                    listener.onResponse(commitIds);
                }
            }

            @Override
            public String executor() {
                return ThreadPool.Names.SAME;
            }
        });
    }
}