Java Code Examples for org.elasticsearch.common.lease.Releasables#closeWhileHandlingException()

The following examples show how to use org.elasticsearch.common.lease.Releasables#closeWhileHandlingException() . 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: DLBasedIndexRecoverySourceHandler.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * performs the recovery from the local engine to the target
 */
public RecoveryResponse recoverToTarget() {
    final SnapshotIndexCommit phase1Snapshot;
    phase1Snapshot = shard.snapshotIndex(false);
    
    try {
        recoverLuceneFiles(phase1Snapshot);
    } catch (Throwable e) {
        logger.error("errors while recovery to target", e);
        throw new RecoveryEngineException(shard.shardId(), 1, "phase1 failed", e);
    } finally {
        Releasables.closeWhileHandlingException(phase1Snapshot);
    }
    return response;
}
 
Example 2
Source File: BigArrays.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private <T extends BigArray> T validate(T array) {
    boolean success = false;
    try {
        adjustBreaker(array.ramBytesUsed());
        success = true;
    } finally {
        if (!success) {
            Releasables.closeWhileHandlingException(array);
        }
    }
    return array;
}
 
Example 3
Source File: BigArrays.java    From crate with Apache License 2.0 5 votes vote down vote up
private <T extends BigArray> T validate(T array) {
    boolean success = false;
    try {
        adjustBreaker(array.ramBytesUsed(), true);
        success = true;
    } finally {
        if (!success) {
            Releasables.closeWhileHandlingException(array);
        }
    }
    return array;
}
 
Example 4
Source File: TransportReplicationAction.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public void onResponse(Releasable releasable) {
    try {
        final ReplicaResult replicaResult = shardOperationOnReplica(request, replica);
        releasable.close(); // release shard operation lock before responding to caller
        final TransportReplicationAction.ReplicaResponse response =
                new ReplicaResponse(replica.getLocalCheckpoint(), replica.getLastSyncedGlobalCheckpoint());
        replicaResult.respond(new ResponseListener(response));
    } catch (final Exception e) {
        Releasables.closeWhileHandlingException(releasable); // release shard operation lock before responding to caller
        AsyncReplicaAction.this.onFailure(e);
    }
}
 
Example 5
Source File: Engine.java    From crate with Apache License 2.0 4 votes vote down vote up
protected final GetResult getFromSearcher(Get get, BiFunction<String, SearcherScope, Searcher> searcherFactory,
                                          SearcherScope scope) throws EngineException {
    final Searcher searcher = searcherFactory.apply("get", scope);
    final DocIdAndVersion docIdAndVersion;
    try {
        docIdAndVersion = VersionsAndSeqNoResolver.loadDocIdAndVersion(searcher.reader(), get.uid(), true);
    } catch (Exception e) {
        Releasables.closeWhileHandlingException(searcher);
        //TODO: A better exception goes here
        throw new EngineException(shardId, "Couldn't resolve version", e);
    }

    if (docIdAndVersion != null) {
        if (get.versionType().isVersionConflictForReads(docIdAndVersion.version, get.version())) {
            Releasables.close(searcher);
            throw new VersionConflictEngineException(
                shardId,
                get.id(),
                get.versionType().explainConflictForReads(docIdAndVersion.version, get.version())
            );
        }
        if (get.getIfSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO && (
            get.getIfSeqNo() != docIdAndVersion.seqNo || get.getIfPrimaryTerm() != docIdAndVersion.primaryTerm)) {

            Releasables.close(searcher);
            throw new VersionConflictEngineException(
                shardId,
                get.id(),
                get.getIfSeqNo(),
                get.getIfPrimaryTerm(),
                docIdAndVersion.seqNo,
                docIdAndVersion.primaryTerm
            );
        }
    }

    if (docIdAndVersion != null) {
        // don't release the searcher on this path, it is the
        // responsibility of the caller to call GetResult.release
        return new GetResult(docIdAndVersion, searcher);
    } else {
        Releasables.close(searcher);
        return GetResult.NOT_EXISTS;
    }
}