use of org.infinispan.persistence.async.AsyncNonBlockingStore in project infinispan by infinispan.
the class AsyncStoreTest method createStore.
private InitializationContext createStore() throws PersistenceException {
ConfigurationBuilder builder = TestCacheManagerFactory.getDefaultCacheConfiguration(false);
DummyInMemoryStoreConfigurationBuilder dummyCfg = builder.persistence().addStore(DummyInMemoryStoreConfigurationBuilder.class).storeName(AsyncStoreTest.class.getName()).segmented(false);
dummyCfg.async().enable();
InitializationContext ctx = PersistenceMockUtil.createContext(getClass(), builder.build(), marshaller);
DummyInMemoryStore underlying = new DummyInMemoryStore();
store = new AsyncNonBlockingStore(underlying);
CompletionStages.join(store.start(ctx));
return ctx;
}
use of org.infinispan.persistence.async.AsyncNonBlockingStore in project keycloak by keycloak.
the class PersistenceManagerImpl method start.
@Override
@Start
public void start() {
enabled = configuration.persistence().usingStores();
if (!enabled)
return;
preloaded = false;
segmentCount = configuration.clustering().hash().numSegments();
isInvalidationCache = configuration.clustering().cacheMode().isInvalidation();
long stamp = lock.writeLock();
try {
Completable storeStartup = Flowable.fromIterable(configuration.persistence().stores()).concatMapSingle(storeConfiguration -> {
NonBlockingStore<?, ?> actualStore = storeFromConfiguration(storeConfiguration);
NonBlockingStore<?, ?> nonBlockingStore;
if (storeConfiguration.async().enabled()) {
nonBlockingStore = new AsyncNonBlockingStore<>(actualStore);
} else {
nonBlockingStore = actualStore;
}
InitializationContextImpl ctx = new InitializationContextImpl(storeConfiguration, cache.wired(), keyPartitioner, persistenceMarshaller, timeService, byteBufferFactory, marshallableEntryFactory, nonBlockingExecutor, globalConfiguration, blockingManager, nonBlockingManager);
CompletionStage<Void> stage = nonBlockingStore.start(ctx).whenComplete((ignore, t) -> {
// On exception, just put a status with only the store - this way we can still invoke stop on it later
if (t != null) {
stores.add(new StoreStatus(nonBlockingStore, null, null));
}
});
return Completable.fromCompletionStage(stage).toSingle(() -> new StoreStatus(nonBlockingStore, storeConfiguration, updateCharacteristics(nonBlockingStore, nonBlockingStore.characteristics(), storeConfiguration)));
}).doOnNext(stores::add).delay(status -> {
if (status.config.purgeOnStartup()) {
return Flowable.fromCompletable(Completable.fromCompletionStage(status.store.clear()));
}
return Flowable.empty();
}).ignoreElements();
long interval = configuration.persistence().availabilityInterval();
if (interval > 0) {
storeStartup = storeStartup.doOnComplete(() -> availabilityTask = nonBlockingManager.scheduleWithFixedDelay(this::pollStoreAvailability, interval, interval, MILLISECONDS));
}
// Blocks here waiting for stores and availability task to start if needed
storeStartup.blockingAwait();
allSegmentedOrShared = allStoresSegmentedOrShared();
} catch (Throwable t) {
log.debug("PersistenceManagerImpl encountered an exception during startup of stores", t);
throw t;
} finally {
lock.unlockWrite(stamp);
}
}
use of org.infinispan.persistence.async.AsyncNonBlockingStore in project infinispan by infinispan.
the class AsyncStoreStressTest method createAsyncStore.
private AsyncNonBlockingStore<Object, Object> createAsyncStore(NonBlockingStore backendStore, StoreConfiguration storeConfiguration) throws PersistenceException {
AsyncNonBlockingStore<Object, Object> store = new AsyncNonBlockingStore<>(backendStore);
BlockingManager blockingManager = new BlockingManagerImpl();
TestingUtil.inject(blockingManager, new TestComponentAccessors.NamedComponent(KnownComponentNames.NON_BLOCKING_EXECUTOR, nonBlockingExecutor), new TestComponentAccessors.NamedComponent(KnownComponentNames.BLOCKING_EXECUTOR, blockingExecutor));
TestingUtil.startComponent(blockingManager);
Cache cacheMock = Mockito.mock(Cache.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(cacheMock.getAdvancedCache().getComponentRegistry().getComponent(KeyPartitioner.class)).thenReturn(SingleSegmentKeyPartitioner.getInstance());
CompletionStages.join(store.start(new DummyInitializationContext(storeConfiguration, cacheMock, marshaller, new ByteBufferFactoryImpl(), new MarshalledEntryFactoryImpl(marshaller), nonBlockingExecutor, new GlobalConfigurationBuilder().globalState().persistentLocation(location).build(), blockingManager, null, new DefaultTimeService())));
return store;
}
Aggregations