use of org.apache.bookkeeper.statelib.api.StateStore in project bookkeeper by apache.
the class AbstractStateStoreWithJournal method init.
@Override
public CompletableFuture<Void> init(StateStoreSpec spec) {
try {
validateStoreSpec(spec);
} catch (IllegalArgumentException e) {
log.error("Fail to init state store due to : ", e);
return FutureUtils.exception(e);
}
this.spec = spec;
this.name = spec.getName();
if (null != spec.getWriteIOScheduler()) {
writeIOScheduler = spec.getWriteIOScheduler();
ownWriteScheduler = false;
} else {
ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("statestore-" + spec.getName() + "-write-io-scheduler-%d").build();
writeIOScheduler = Executors.newSingleThreadScheduledExecutor(threadFactory);
ownWriteScheduler = true;
}
if (null != spec.getReadIOScheduler()) {
readIOScheduler = spec.getReadIOScheduler();
} else if (ownWriteScheduler) {
readIOScheduler = writeIOScheduler;
ownReadScheduler = false;
} else {
ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("statestore-" + spec.getName() + "-read-io-scheduler-%d").build();
readIOScheduler = Executors.newSingleThreadScheduledExecutor(threadFactory);
ownReadScheduler = true;
}
if (null != spec.getCheckpointStore()) {
this.checkpointInterval = spec.getCheckpointDuration();
} else {
this.checkpointInterval = null;
}
if (spec.isReadonly()) {
return initializeLocalStore(spec).thenComposeAsync(ignored -> getLastDLSN(spec), writeIOScheduler).thenComposeAsync(endDLSN -> replayJournal(endDLSN), writeIOScheduler);
} else {
return initializeLocalStore(spec).thenComposeAsync(ignored -> initializeJournalWriter(spec), writeIOScheduler).thenComposeAsync(endDLSN -> {
log.info("Successfully write a barrier record for mvcc store {} at {}", name, endDLSN);
return replayJournal(endDLSN);
}, writeIOScheduler);
}
}
Aggregations