Java Code Examples for org.elasticsearch.index.shard.IndexShard#sync()

The following examples show how to use org.elasticsearch.index.shard.IndexShard#sync() . 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: TransportReplicationAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
protected final void processAfterWrite(boolean refresh, IndexShard indexShard, Translog.Location location) {
    if (refresh) {
        try {
            indexShard.refresh("refresh_flag_index");
        } catch (Throwable e) {
            // ignore
        }
    }
    if (indexShard.getTranslogDurability() == Translog.Durabilty.REQUEST && location != null) {
        indexShard.sync(location);
    }
}
 
Example 2
Source File: IndexService.java    From crate with Apache License 2.0 5 votes vote down vote up
private void maybeFSyncTranslogs() {
    if (indexSettings.getTranslogDurability() == Translog.Durability.ASYNC) {
        for (IndexShard shard : this.shards.values()) {
            try {
                if (shard.isSyncNeeded()) {
                    shard.sync();
                }
            } catch (AlreadyClosedException ex) {
                // fine - continue;
            } catch (IOException e) {
                logger.warn("failed to sync translog", e);
            }
        }
    }
}
 
Example 3
Source File: TransportShardUpsertAction.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected ShardResponse processRequestItems(ShardId shardId,
                                            ShardUpsertRequest request,
                                            AtomicBoolean killed) throws InterruptedException {
    ShardResponse shardResponse = new ShardResponse();
    DocTableInfo tableInfo = schemas.getWritableTable(TableIdent.fromIndexName(request.index()));
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    IndexShard indexShard = indexService.shardSafe(shardId.id());

    Translog.Location translogLocation = null;
    for (int i = 0; i < request.itemIndices().size(); i++) {
        int location = request.itemIndices().get(i);
        ShardUpsertRequest.Item item = request.items().get(i);
        if (killed.get()) {
            // set failure on response and skip all next items.
            // this way replica operation will be executed, but only items with a valid source (= was processed on primary)
            // will be processed on the replica
            shardResponse.failure(new InterruptedException());
            break;
        }
        try {
            translogLocation = indexItem(
                    tableInfo,
                    request,
                    item,
                    indexShard,
                    item.insertValues() != null, // try insert first
                    0);
            shardResponse.add(location);
        } catch (Throwable t) {
            if (retryPrimaryException(t)) {
                Throwables.propagate(t);
            }
            logger.debug("{} failed to execute upsert for [{}]/[{}]",
                    t, request.shardId(), request.type(), item.id());
            if (!request.continueOnError()) {
               shardResponse.failure(t);
               break;
            }
            shardResponse.add(location,
                    new ShardResponse.Failure(
                            item.id(),
                            ExceptionsHelper.detailedMessage(t),
                            (t instanceof VersionConflictEngineException)));
        }
    }
    if (indexShard.getTranslogDurability() == Translog.Durabilty.REQUEST && translogLocation != null) {
        indexShard.sync(translogLocation);
    }
    return shardResponse;
}
 
Example 4
Source File: GlobalCheckpointSyncAction.java    From crate with Apache License 2.0 4 votes vote down vote up
private void maybeSyncTranslog(final IndexShard indexShard) throws IOException {
    if (indexShard.getTranslogDurability() == Translog.Durability.REQUEST &&
        indexShard.getLastSyncedGlobalCheckpoint() < indexShard.getLastKnownGlobalCheckpoint()) {
        indexShard.sync();
    }
}