Search in sources :

Example 6 with IndexException

use of com.b2international.index.IndexException in project snow-owl by b2ihealthcare.

the class RepositoryTransactionContext method commit.

@Override
public Optional<Commit> commit(String author, String commitComment, String parentLockContext) {
    if (!isDirty()) {
        return Optional.empty();
    }
    // fall back to the current lock context or ROOT if none is present
    if (Strings.isNullOrEmpty(parentLockContext)) {
        parentLockContext = optionalService(Locks.class).map(Locks::lockContext).orElse(DatastoreLockContextDescriptions.ROOT);
    }
    final DatastoreLockContext lockContext = createLockContext(service(User.class).getUsername(), parentLockContext);
    final DatastoreLockTarget lockTarget = createLockTarget(info().id(), path());
    IOperationLockManager locks = service(IOperationLockManager.class);
    Commit commit = null;
    try {
        locks.lock(lockContext, 1000L, lockTarget);
        final long timestamp = service(TimestampProvider.class).getTimestamp();
        log().info("Persisting changes to {}@{}", path(), timestamp);
        commit = staging.commit(null, timestamp, author, commitComment);
        log().info("Changes have been successfully persisted to {}@{}.", path(), timestamp);
        return Optional.ofNullable(commit);
    } catch (final IndexException e) {
        Throwable rootCause = Throwables.getRootCause(e);
        if (rootCause instanceof CycleDetectedException) {
            throw (CycleDetectedException) rootCause;
        }
        throw new SnowowlRuntimeException(e.getMessage(), e);
    } finally {
        locks.unlock(lockContext, lockTarget);
        if (commit != null && isNotificationEnabled()) {
            service(RepositoryCommitNotificationSender.class).publish(this, commit);
        }
        clear();
    }
}
Also used : IndexException(com.b2international.index.IndexException) CycleDetectedException(com.b2international.commons.exceptions.CycleDetectedException) Locks(com.b2international.snowowl.core.locks.Locks) IOperationLockManager(com.b2international.snowowl.core.locks.IOperationLockManager) DatastoreLockTarget(com.b2international.snowowl.core.internal.locks.DatastoreLockTarget) DatastoreLockContext(com.b2international.snowowl.core.internal.locks.DatastoreLockContext) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Aggregations

IndexException (com.b2international.index.IndexException)6 IOException (java.io.IOException)5 SimplePositionedMutableByteRange (org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange)3 CycleDetectedException (com.b2international.commons.exceptions.CycleDetectedException)1 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)1 DatastoreLockContext (com.b2international.snowowl.core.internal.locks.DatastoreLockContext)1 DatastoreLockTarget (com.b2international.snowowl.core.internal.locks.DatastoreLockTarget)1 IOperationLockManager (com.b2international.snowowl.core.locks.IOperationLockManager)1 Locks (com.b2international.snowowl.core.locks.Locks)1 ClusterHealthRequest (org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)1