Search in sources :

Example 1 with FakeJTATransaction

use of org.infinispan.transaction.impl.FakeJTATransaction in project infinispan by infinispan.

the class PreloadManager method preloadEntry.

private Single<?> preloadEntry(long flags, MarshallableEntry<Object, Object> me, DataConversion keyDataConversion, DataConversion valueDataConversion) {
    // CallInterceptor will preserve the timestamps if the metadata is an InternalMetadataImpl instance
    InternalMetadataImpl metadata = new InternalMetadataImpl(me.getMetadata(), me.created(), me.lastUsed());
    // TODO If the storage media type is application/x-protostream, this will convert to POJOs and back
    Object key = keyDataConversion.toStorage(me.getKey());
    Object value = valueDataConversion.toStorage(me.getValue());
    PutKeyValueCommand cmd = commandsFactory.buildPutKeyValueCommand(key, value, keyPartitioner.getSegment(key), metadata, flags);
    cmd.setInternalMetadata(me.getInternalMetadata());
    CompletionStage<?> stage;
    if (configuration.transaction().transactionMode().isTransactional()) {
        try {
            Transaction transaction = new FakeJTATransaction();
            InvocationContext ctx = invocationContextFactory.createInvocationContext(transaction, false);
            LocalTransaction localTransaction = ((LocalTxInvocationContext) ctx).getCacheTransaction();
            stage = CompletionStages.handleAndCompose(invocationHelper.invokeAsync(ctx, cmd), (__, t) -> completeTransaction(key, localTransaction, t)).whenComplete((__, t) -> transactionTable.removeLocalTransaction(localTransaction));
        } catch (Exception e) {
            throw log.problemPreloadingKey(key, e);
        }
    } else {
        stage = invocationHelper.invokeAsync(cmd, 1);
    }
    // The return value doesn't matter, but it cannot be null
    return Completable.fromCompletionStage(stage).toSingleDefault(me);
}
Also used : Single(io.reactivex.rxjava3.core.Single) LogFactory(org.infinispan.util.logging.LogFactory) InvocationHelper(org.infinispan.cache.impl.InvocationHelper) CompletionStages(org.infinispan.util.concurrent.CompletionStages) EnumUtil(org.infinispan.commons.util.EnumUtil) Start(org.infinispan.factories.annotations.Start) FlagBitSets(org.infinispan.context.impl.FlagBitSets) Scopes(org.infinispan.factories.scopes.Scopes) InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl) StoreConfiguration(org.infinispan.configuration.cache.StoreConfiguration) InvocationContext(org.infinispan.context.InvocationContext) LocalTxInvocationContext(org.infinispan.context.impl.LocalTxInvocationContext) ComponentRef(org.infinispan.factories.impl.ComponentRef) AdvancedCache(org.infinispan.AdvancedCache) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) Log(org.infinispan.util.logging.Log) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) Scope(org.infinispan.factories.scopes.Scope) InvocationContextFactory(org.infinispan.context.InvocationContextFactory) Transaction(javax.transaction.Transaction) CommandsFactory(org.infinispan.commands.CommandsFactory) Flowable(io.reactivex.rxjava3.core.Flowable) MethodHandles(java.lang.invoke.MethodHandles) Publisher(org.reactivestreams.Publisher) Util(org.infinispan.commons.util.Util) Completable(io.reactivex.rxjava3.core.Completable) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Inject(org.infinispan.factories.annotations.Inject) CompletionStage(java.util.concurrent.CompletionStage) LocalTransaction(org.infinispan.transaction.impl.LocalTransaction) TransactionCoordinator(org.infinispan.transaction.impl.TransactionCoordinator) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) Configuration(org.infinispan.configuration.cache.Configuration) DataConversion(org.infinispan.encoding.DataConversion) TransactionManager(javax.transaction.TransactionManager) FakeJTATransaction(org.infinispan.transaction.impl.FakeJTATransaction) TransactionTable(org.infinispan.transaction.impl.TransactionTable) TimeService(org.infinispan.commons.time.TimeService) PersistenceException(org.infinispan.persistence.spi.PersistenceException) Transaction(javax.transaction.Transaction) LocalTransaction(org.infinispan.transaction.impl.LocalTransaction) FakeJTATransaction(org.infinispan.transaction.impl.FakeJTATransaction) LocalTransaction(org.infinispan.transaction.impl.LocalTransaction) FakeJTATransaction(org.infinispan.transaction.impl.FakeJTATransaction) InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl) LocalTxInvocationContext(org.infinispan.context.impl.LocalTxInvocationContext) InvocationContext(org.infinispan.context.InvocationContext) LocalTxInvocationContext(org.infinispan.context.impl.LocalTxInvocationContext) PersistenceException(org.infinispan.persistence.spi.PersistenceException) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand)

Example 2 with FakeJTATransaction

use of org.infinispan.transaction.impl.FakeJTATransaction in project infinispan by infinispan.

the class StateConsumerImpl method doApplyState.

private CompletionStage<?> doApplyState(Address sender, int segmentId, Collection<InternalCacheEntry<?, ?>> cacheEntries) {
    if (cacheEntries == null || cacheEntries.isEmpty())
        return CompletableFutures.completedNull();
    if (log.isTraceEnabled())
        log.tracef("Applying new state chunk for segment %d of cache %s from node %s: received %d cache entries", segmentId, cacheName, sender, cacheEntries.size());
    // CACHE_MODE_LOCAL avoids handling by StateTransferInterceptor and any potential locks in StateTransferLock
    boolean transactional = transactionManager != null;
    if (transactional) {
        Object key = NO_KEY;
        Transaction transaction = new FakeJTATransaction();
        InvocationContext ctx = icf.createInvocationContext(transaction, false);
        LocalTransaction localTransaction = ((LocalTxInvocationContext) ctx).getCacheTransaction();
        try {
            localTransaction.setStateTransferFlag(PUT_FOR_STATE_TRANSFER);
            for (InternalCacheEntry<?, ?> e : cacheEntries) {
                key = e.getKey();
                CompletableFuture<?> future = invokePut(segmentId, ctx, e);
                if (!future.isDone()) {
                    throw new IllegalStateException("State transfer in-tx put should always be synchronous");
                }
            }
        } catch (Throwable t) {
            logApplyException(t, key);
            return invokeRollback(localTransaction).handle((rv, t1) -> {
                transactionTable.removeLocalTransaction(localTransaction);
                if (t1 != null) {
                    t.addSuppressed(t1);
                }
                return null;
            });
        }
        return invoke1PCPrepare(localTransaction).whenComplete((rv, t) -> {
            transactionTable.removeLocalTransaction(localTransaction);
            if (t != null) {
                logApplyException(t, NO_KEY);
            }
        });
    } else {
        // non-tx cache
        AggregateCompletionStage<Void> aggregateStage = CompletionStages.aggregateCompletionStage();
        for (InternalCacheEntry<?, ?> e : cacheEntries) {
            InvocationContext ctx = icf.createSingleKeyNonTxInvocationContext();
            CompletionStage<?> putStage = invokePut(segmentId, ctx, e);
            aggregateStage.dependsOn(putStage.exceptionally(t -> {
                logApplyException(t, e.getKey());
                return null;
            }));
        }
        return aggregateStage.freeze();
    }
}
Also used : ComponentName(org.infinispan.factories.annotations.ComponentName) CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) LogFactory(org.infinispan.util.logging.LogFactory) Cache(org.infinispan.Cache) Scopes(org.infinispan.factories.scopes.Scopes) Map(java.util.Map) SKIP_SHARED_CACHE_STORE(org.infinispan.context.Flag.SKIP_SHARED_CACHE_STORE) Transaction(javax.transaction.Transaction) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) CACHE_MODE_LOCAL(org.infinispan.context.Flag.CACHE_MODE_LOCAL) Set(java.util.Set) CacheTopology(org.infinispan.topology.CacheTopology) IntSet(org.infinispan.commons.util.IntSet) CompletionStage(java.util.concurrent.CompletionStage) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) FakeJTATransaction(org.infinispan.transaction.impl.FakeJTATransaction) CacheTransaction(org.infinispan.transaction.xa.CacheTransaction) TriangleOrderManager(org.infinispan.distribution.TriangleOrderManager) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) CommandAckCollector(org.infinispan.util.concurrent.CommandAckCollector) EnumUtil(org.infinispan.commons.util.EnumUtil) ArrayList(java.util.ArrayList) Start(org.infinispan.factories.annotations.Start) PassthroughSingleResponseCollector(org.infinispan.remoting.transport.impl.PassthroughSingleResponseCollector) PRIVATE(org.infinispan.persistence.manager.PersistenceManager.AccessMode.PRIVATE) Configurations(org.infinispan.configuration.cache.Configurations) SingleResponseCollector(org.infinispan.remoting.transport.impl.SingleResponseCollector) Address(org.infinispan.remoting.transport.Address) InvocationContextFactory(org.infinispan.context.InvocationContextFactory) SKIP_OWNERSHIP_CHECK(org.infinispan.context.Flag.SKIP_OWNERSHIP_CHECK) Executor(java.util.concurrent.Executor) RollbackCommand(org.infinispan.commands.tx.RollbackCommand) ClusterListenerReplicateCallable(org.infinispan.notifications.cachelistener.cluster.ClusterListenerReplicateCallable) Publisher(org.reactivestreams.Publisher) ValidResponse(org.infinispan.remoting.responses.ValidResponse) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) InternalConflictManager(org.infinispan.conflict.impl.InternalConflictManager) Inject(org.infinispan.factories.annotations.Inject) AtomicLong(java.util.concurrent.atomic.AtomicLong) InvalidateCommand(org.infinispan.commands.write.InvalidateCommand) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) DistributionManager(org.infinispan.distribution.DistributionManager) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) IntSets(org.infinispan.commons.util.IntSets) Stop(org.infinispan.factories.annotations.Stop) InvocationContext(org.infinispan.context.InvocationContext) LocalTxInvocationContext(org.infinispan.context.impl.LocalTxInvocationContext) ComponentRef(org.infinispan.factories.impl.ComponentRef) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SKIP_REMOTE_LOOKUP(org.infinispan.context.Flag.SKIP_REMOTE_LOOKUP) Scope(org.infinispan.factories.scopes.Scope) PERSISTENCE(org.infinispan.util.logging.Log.PERSISTENCE) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) PrepareCommand(org.infinispan.commands.tx.PrepareCommand) CommandsFactory(org.infinispan.commands.CommandsFactory) CompletionStages.handleAndCompose(org.infinispan.util.concurrent.CompletionStages.handleAndCompose) Predicate(java.util.function.Predicate) LocalPublisherManager(org.infinispan.reactive.publisher.impl.LocalPublisherManager) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LockingMode(org.infinispan.transaction.LockingMode) List(java.util.List) PerCacheInboundInvocationHandler(org.infinispan.remoting.inboundhandler.PerCacheInboundInvocationHandler) LocalTransaction(org.infinispan.transaction.impl.LocalTransaction) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) LocalTopologyManager(org.infinispan.topology.LocalTopologyManager) GuardedBy(net.jcip.annotations.GuardedBy) IGNORE_RETURN_VALUES(org.infinispan.context.Flag.IGNORE_RETURN_VALUES) SKIP_XSITE_BACKUP(org.infinispan.context.Flag.SKIP_XSITE_BACKUP) DataRehashed(org.infinispan.notifications.cachelistener.annotation.DataRehashed) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionStages(org.infinispan.util.concurrent.CompletionStages) PUT_FOR_STATE_TRANSFER(org.infinispan.context.Flag.PUT_FOR_STATE_TRANSFER) HashSet(java.util.HashSet) FlagBitSets(org.infinispan.context.impl.FlagBitSets) InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) IRAC_STATE(org.infinispan.context.Flag.IRAC_STATE) Log(org.infinispan.util.logging.Log) Response(org.infinispan.remoting.responses.Response) Flowable(io.reactivex.rxjava3.core.Flowable) Iterator(java.util.Iterator) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) RpcManager(org.infinispan.remoting.rpc.RpcManager) TransactionMode(org.infinispan.transaction.TransactionMode) Completable(io.reactivex.rxjava3.core.Completable) NON_BLOCKING_EXECUTOR(org.infinispan.factories.KnownComponentNames.NON_BLOCKING_EXECUTOR) CompletionStages.ignoreValue(org.infinispan.util.concurrent.CompletionStages.ignoreValue) PrimitiveIterator(java.util.PrimitiveIterator) TimeUnit(java.util.concurrent.TimeUnit) IllegalLifecycleStateException(org.infinispan.commons.IllegalLifecycleStateException) CacheRpcCommand(org.infinispan.commands.remote.CacheRpcCommand) XSiteStateTransferManager(org.infinispan.xsite.statetransfer.XSiteStateTransferManager) SKIP_LOCKING(org.infinispan.context.Flag.SKIP_LOCKING) RemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction) Configuration(org.infinispan.configuration.cache.Configuration) DistributionInfo(org.infinispan.distribution.DistributionInfo) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) TransactionManager(javax.transaction.TransactionManager) Collections(java.util.Collections) TransactionTable(org.infinispan.transaction.impl.TransactionTable) LimitedExecutor(org.infinispan.executors.LimitedExecutor) LocalTransaction(org.infinispan.transaction.impl.LocalTransaction) LocalTxInvocationContext(org.infinispan.context.impl.LocalTxInvocationContext) Transaction(javax.transaction.Transaction) FakeJTATransaction(org.infinispan.transaction.impl.FakeJTATransaction) CacheTransaction(org.infinispan.transaction.xa.CacheTransaction) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) LocalTransaction(org.infinispan.transaction.impl.LocalTransaction) RemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction) FakeJTATransaction(org.infinispan.transaction.impl.FakeJTATransaction) InvocationContext(org.infinispan.context.InvocationContext) LocalTxInvocationContext(org.infinispan.context.impl.LocalTxInvocationContext)

Aggregations

Completable (io.reactivex.rxjava3.core.Completable)2 Flowable (io.reactivex.rxjava3.core.Flowable)2 CompletionStage (java.util.concurrent.CompletionStage)2 Transaction (javax.transaction.Transaction)2 TransactionManager (javax.transaction.TransactionManager)2 CommandsFactory (org.infinispan.commands.CommandsFactory)2 PutKeyValueCommand (org.infinispan.commands.write.PutKeyValueCommand)2 EnumUtil (org.infinispan.commons.util.EnumUtil)2 Configuration (org.infinispan.configuration.cache.Configuration)2 Single (io.reactivex.rxjava3.core.Single)1 MethodHandles (java.lang.invoke.MethodHandles)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 PrimitiveIterator (java.util.PrimitiveIterator)1