Search in sources :

Example 1 with StateStoreClosedException

use of org.apache.bookkeeper.statelib.api.exceptions.StateStoreClosedException in project bookkeeper by apache.

the class AbstractStateStoreWithJournal method getLastDLSN.

private CompletableFuture<DLSN> getLastDLSN(StateStoreSpec spec) {
    synchronized (this) {
        if (null != closeFuture) {
            return FutureUtils.exception(new StateStoreClosedException(name()));
        }
    }
    try {
        logManager = logNamespace.openLog(spec.getStream());
    } catch (IOException e) {
        return FutureUtils.exception(e);
    }
    CompletableFuture<DLSN> future = FutureUtils.createFuture();
    logManager.getLastDLSNAsync().whenCompleteAsync(new FutureEventListener<DLSN>() {

        @Override
        public void onSuccess(DLSN dlsn) {
            future.complete(dlsn);
        }

        @Override
        public void onFailure(Throwable throwable) {
            if (throwable instanceof LogEmptyException || throwable instanceof LogNotFoundException) {
                FutureUtils.proxyTo(writeCatchUpMarker(), future);
            } else {
                future.completeExceptionally(throwable);
            }
        }
    });
    return future;
}
Also used : LogEmptyException(org.apache.distributedlog.exceptions.LogEmptyException) StateStoreClosedException(org.apache.bookkeeper.statelib.api.exceptions.StateStoreClosedException) LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) DLSN(org.apache.distributedlog.DLSN) IOException(java.io.IOException) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException)

Example 2 with StateStoreClosedException

use of org.apache.bookkeeper.statelib.api.exceptions.StateStoreClosedException in project bookkeeper by apache.

the class AbstractStateStoreWithJournal method initializeJournalWriter.

private CompletableFuture<DLSN> initializeJournalWriter(StateStoreSpec spec) {
    synchronized (this) {
        if (null != closeFuture) {
            return FutureUtils.exception(new StateStoreClosedException(name()));
        }
    }
    try {
        logManager = logNamespace.openLog(spec.getStream());
    } catch (IOException e) {
        return FutureUtils.exception(e);
    }
    return logManager.openAsyncLogWriter().thenComposeAsync(w -> {
        synchronized (this) {
            writer = w;
            nextRevision = writer.getLastTxId();
            if (nextRevision < 0) {
                nextRevision = 0L;
            }
            log.info("Initialized the journal writer for mvcc store {} : last revision = {}", name(), nextRevision);
        }
        return writeCommandBuf(newCatchupMarker());
    }, writeIOScheduler);
}
Also used : StateStoreClosedException(org.apache.bookkeeper.statelib.api.exceptions.StateStoreClosedException) IOException(java.io.IOException)

Example 3 with StateStoreClosedException

use of org.apache.bookkeeper.statelib.api.exceptions.StateStoreClosedException in project bookkeeper by apache.

the class AbstractStateStoreWithJournal method executeIO.

private <T> CompletableFuture<T> executeIO(ScheduledExecutorService scheduler, Callable<T> callable) {
    synchronized (this) {
        if (null != closeFuture) {
            return FutureUtils.exception(new StateStoreClosedException(name()));
        }
    }
    CompletableFuture<T> future = FutureUtils.createFuture();
    scheduler.submit(() -> {
        try {
            T value = callable.call();
            future.complete(value);
        } catch (Exception e) {
            future.completeExceptionally(e);
        }
    });
    return future;
}
Also used : StateStoreClosedException(org.apache.bookkeeper.statelib.api.exceptions.StateStoreClosedException) StateStoreClosedException(org.apache.bookkeeper.statelib.api.exceptions.StateStoreClosedException) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException) StateStoreRuntimeException(org.apache.bookkeeper.statelib.api.exceptions.StateStoreRuntimeException) StateStoreException(org.apache.bookkeeper.statelib.api.exceptions.StateStoreException) IOException(java.io.IOException) LogEmptyException(org.apache.distributedlog.exceptions.LogEmptyException)

Aggregations

IOException (java.io.IOException)3 StateStoreClosedException (org.apache.bookkeeper.statelib.api.exceptions.StateStoreClosedException)3 LogEmptyException (org.apache.distributedlog.exceptions.LogEmptyException)2 LogNotFoundException (org.apache.distributedlog.exceptions.LogNotFoundException)2 StateStoreException (org.apache.bookkeeper.statelib.api.exceptions.StateStoreException)1 StateStoreRuntimeException (org.apache.bookkeeper.statelib.api.exceptions.StateStoreRuntimeException)1 DLSN (org.apache.distributedlog.DLSN)1 LogRecordWithDLSN (org.apache.distributedlog.LogRecordWithDLSN)1