Search in sources :

Example 1 with InitializationContextImpl

use of org.infinispan.persistence.InitializationContextImpl in project infinispan by infinispan.

the class ComposedSegmentedLoadWriteStore method startNewStoreForSegment.

private void startNewStoreForSegment(int segment) {
    if (stores.get(segment) == null) {
        T storeConfiguration = configuration.newConfigurationFrom(segment, ctx);
        AdvancedLoadWriteStore<K, V> newStore = PersistenceUtil.createStoreInstance(storeConfiguration);
        newStore.init(new InitializationContextImpl(storeConfiguration, cache, keyPartitioner, ctx.getPersistenceMarshaller(), ctx.getTimeService(), ctx.getByteBufferFactory(), ctx.getMarshallableEntryFactory(), ctx.getNonBlockingExecutor(), ctx.getGlobalConfiguration(), ctx.getBlockingManager(), ctx.getNonBlockingManager()));
        newStore.start();
        stores.set(segment, newStore);
    }
}
Also used : InitializationContextImpl(org.infinispan.persistence.InitializationContextImpl)

Example 2 with InitializationContextImpl

use of org.infinispan.persistence.InitializationContextImpl in project infinispan by infinispan.

the class OracleTableManagerTest method testShortIndexNamesOverlap.

public void testShortIndexNamesOverlap() {
    DbMetaData dbMetaData = new DbMetaData(DatabaseType.ORACLE, 12, 0, false, false, false);
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class).table().tableNamePrefix("TBL").dataColumnName("DTC").dataColumnType("BINARY").idColumnName("IDC").idColumnType("VARCHAR(255)").timestampColumnName("TSC").timestampColumnType("BIGINT").segmentColumnName("SGC").segmentColumnType("INT").dataSource().jndiUrl("a_fake_jdni_url");
    Configuration configuration = builder.build();
    JdbcStringBasedStoreConfiguration storeConfiguration = (JdbcStringBasedStoreConfiguration) configuration.persistence().stores().get(0);
    InitializationContextImpl context = new InitializationContextImpl(null, null, null, Mockito.mock(PersistenceMarshaller.class), null, null, null, null, null, null, null);
    OracleTableManager tableManager = new OracleTableManager(context, null, storeConfiguration, dbMetaData, "ALongishCacheName");
    String segmentIndexName = tableManager.getIndexName(true, "segment_index");
    String timestampIndexName = tableManager.getIndexName(true, "timestamp_index");
    assertFalse(segmentIndexName.equals(timestampIndexName));
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) JdbcStringBasedStoreConfigurationBuilder(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder) InitializationContextImpl(org.infinispan.persistence.InitializationContextImpl) Configuration(org.infinispan.configuration.cache.Configuration) JdbcStringBasedStoreConfiguration(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfiguration) JdbcStringBasedStoreConfiguration(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfiguration) PersistenceMarshaller(org.infinispan.marshall.persistence.PersistenceMarshaller)

Example 3 with InitializationContextImpl

use of org.infinispan.persistence.InitializationContextImpl 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);
    }
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) ComponentName(org.infinispan.factories.annotations.ComponentName) LogFactory(org.infinispan.util.logging.LogFactory) InvocationHelper(org.infinispan.cache.impl.InvocationHelper) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) KnownComponentNames(org.infinispan.factories.KnownComponentNames) StoreUnavailableException(org.infinispan.persistence.spi.StoreUnavailableException) Scopes(org.infinispan.factories.scopes.Scopes) AdvancedCache(org.infinispan.AdvancedCache) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) InitializationContextImpl(org.infinispan.persistence.InitializationContextImpl) Transaction(javax.transaction.Transaction) MethodHandles(java.lang.invoke.MethodHandles) ByRef(org.infinispan.commons.util.ByRef) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) IntSet(org.infinispan.commons.util.IntSet) CompletionStage(java.util.concurrent.CompletionStage) ComposedSegmentedLoadWriteStore(org.infinispan.persistence.support.ComposedSegmentedLoadWriteStore) DelegatingNonBlockingStore(org.infinispan.persistence.support.DelegatingNonBlockingStore) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue) DataConversion(org.infinispan.encoding.DataConversion) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) Single(io.reactivex.rxjava3.core.Single) TransactionalStoreInterceptor(org.infinispan.interceptors.impl.TransactionalStoreInterceptor) NonBlockingStoreAdapter(org.infinispan.persistence.support.NonBlockingStoreAdapter) EnumUtil(org.infinispan.commons.util.EnumUtil) InternalExpirationManager(org.infinispan.expiration.impl.InternalExpirationManager) CacheLoaderInterceptor(org.infinispan.interceptors.impl.CacheLoaderInterceptor) Start(org.infinispan.factories.annotations.Start) ArrayList(java.util.ArrayList) Maybe(io.reactivex.rxjava3.core.Maybe) StoreConfiguration(org.infinispan.configuration.cache.StoreConfiguration) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) DataWriteCommand(org.infinispan.commands.write.DataWriteCommand) AsyncInterceptor(org.infinispan.interceptors.AsyncInterceptor) InternalEntryFactory(org.infinispan.container.impl.InternalEntryFactory) Properties(java.util.Properties) Executor(java.util.concurrent.Executor) Publisher(org.reactivestreams.Publisher) InvalidTransactionException(javax.transaction.InvalidTransactionException) IOException(java.io.IOException) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) Inject(org.infinispan.factories.annotations.Inject) MVCCEntry(org.infinispan.container.entries.MVCCEntry) InvalidateCommand(org.infinispan.commands.write.InvalidateCommand) Function(io.reactivex.rxjava3.functions.Function) PersistenceMarshaller(org.infinispan.marshall.persistence.PersistenceMarshaller) SystemException(javax.transaction.SystemException) StampedLock(java.util.concurrent.locks.StampedLock) DistributionManager(org.infinispan.distribution.DistributionManager) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) IntSets(org.infinispan.commons.util.IntSets) MarshallableEntryFactory(org.infinispan.persistence.spi.MarshallableEntryFactory) Stop(org.infinispan.factories.annotations.Stop) InvocationContext(org.infinispan.context.InvocationContext) ComponentRef(org.infinispan.factories.impl.ComponentRef) SingleSegmentPublisher(org.infinispan.persistence.support.SingleSegmentPublisher) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) Lifecycle(org.infinispan.commons.api.Lifecycle) Scope(org.infinispan.factories.scopes.Scope) ByteBufferFactory(org.infinispan.commons.io.ByteBufferFactory) PERSISTENCE(org.infinispan.util.logging.Log.PERSISTENCE) CommandsFactory(org.infinispan.commands.CommandsFactory) AsyncNonBlockingStore(org.infinispan.persistence.async.AsyncNonBlockingStore) Predicate(java.util.function.Predicate) Collection(java.util.Collection) AbstractCacheTransaction(org.infinispan.transaction.impl.AbstractCacheTransaction) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) GuardedBy(net.jcip.annotations.GuardedBy) SegmentPublisherWrapper(org.infinispan.persistence.support.SegmentPublisherWrapper) PersistenceException(org.infinispan.persistence.spi.PersistenceException) LocalOnlyCacheLoader(org.infinispan.persistence.spi.LocalOnlyCacheLoader) CompletionStages(org.infinispan.util.concurrent.CompletionStages) CompletableFuture(java.util.concurrent.CompletableFuture) AbstractSegmentedStoreConfiguration(org.infinispan.configuration.cache.AbstractSegmentedStoreConfiguration) FlagBitSets(org.infinispan.context.impl.FlagBitSets) InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl) HashSet(java.util.HashSet) Characteristic(org.infinispan.persistence.spi.NonBlockingStore.Characteristic) BiPredicate(java.util.function.BiPredicate) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) Log(org.infinispan.util.logging.Log) CacheWriterInterceptor(org.infinispan.interceptors.impl.CacheWriterInterceptor) Flowable(io.reactivex.rxjava3.core.Flowable) Iterator(java.util.Iterator) NonBlockingStore(org.infinispan.persistence.spi.NonBlockingStore) Util(org.infinispan.commons.util.Util) NonBlockingManager(org.infinispan.util.concurrent.NonBlockingManager) Completable(io.reactivex.rxjava3.core.Completable) PutMapCommand(org.infinispan.commands.write.PutMapCommand) NotSupportedException(javax.transaction.NotSupportedException) PersistenceUtil(org.infinispan.persistence.internal.PersistenceUtil) Configuration(org.infinispan.configuration.cache.Configuration) BlockingManager(org.infinispan.util.concurrent.BlockingManager) TransactionManager(javax.transaction.TransactionManager) TimeService(org.infinispan.commons.time.TimeService) InputStream(java.io.InputStream) AsyncNonBlockingStore(org.infinispan.persistence.async.AsyncNonBlockingStore) Completable(io.reactivex.rxjava3.core.Completable) InitializationContextImpl(org.infinispan.persistence.InitializationContextImpl) DelegatingNonBlockingStore(org.infinispan.persistence.support.DelegatingNonBlockingStore) AsyncNonBlockingStore(org.infinispan.persistence.async.AsyncNonBlockingStore) NonBlockingStore(org.infinispan.persistence.spi.NonBlockingStore) CompletionStage(java.util.concurrent.CompletionStage) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) Start(org.infinispan.factories.annotations.Start)

Aggregations

InitializationContextImpl (org.infinispan.persistence.InitializationContextImpl)3 Configuration (org.infinispan.configuration.cache.Configuration)2 PersistenceMarshaller (org.infinispan.marshall.persistence.PersistenceMarshaller)2 Completable (io.reactivex.rxjava3.core.Completable)1 Flowable (io.reactivex.rxjava3.core.Flowable)1 Maybe (io.reactivex.rxjava3.core.Maybe)1 Single (io.reactivex.rxjava3.core.Single)1 Function (io.reactivex.rxjava3.functions.Function)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MethodHandles (java.lang.invoke.MethodHandles)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Objects (java.util.Objects)1 Properties (java.util.Properties)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1