Search in sources :

Example 1 with InternalMetadataImpl

use of org.infinispan.metadata.impl.InternalMetadataImpl in project infinispan by infinispan.

the class StateConsumerImpl method invokePut.

private CompletableFuture<?> invokePut(int segmentId, InvocationContext ctx, InternalCacheEntry<?, ?> e) {
    // CallInterceptor will preserve the timestamps if the metadata is an InternalMetadataImpl instance
    InternalMetadataImpl metadata = new InternalMetadataImpl(e);
    PutKeyValueCommand put = commandsFactory.buildPutKeyValueCommand(e.getKey(), e.getValue(), segmentId, metadata, STATE_TRANSFER_FLAGS);
    put.setInternalMetadata(e.getInternalMetadata());
    ctx.setLockOwner(put.getKeyLockOwner());
    return interceptorChain.invokeAsync(ctx, put);
}
Also used : InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand)

Example 2 with InternalMetadataImpl

use of org.infinispan.metadata.impl.InternalMetadataImpl in project infinispan by infinispan.

the class CallInterceptor method visitPutKeyValueCommand.

@Override
public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable {
    // It's not worth looking up the entry if we're never going to apply the change.
    ValueMatcher valueMatcher = command.getValueMatcher();
    if (valueMatcher == ValueMatcher.MATCH_NEVER) {
        command.fail();
        return null;
    }
    // noinspection unchecked
    Object key = command.getKey();
    MVCCEntry<Object, Object> e = (MVCCEntry) ctx.lookupEntry(key);
    if (e == null) {
        throw new IllegalStateException("Not wrapped");
    }
    Object newValue = command.getValue();
    Metadata metadata = command.getMetadata();
    if (metadata instanceof InternalMetadataImpl) {
        InternalMetadataImpl internalMetadata = (InternalMetadataImpl) metadata;
        metadata = internalMetadata.actual();
        e.setCreated(internalMetadata.created());
        e.setLastUsed(internalMetadata.lastUsed());
    }
    Object prevValue = e.getValue();
    if (!valueMatcher.matches(prevValue, null, newValue)) {
        command.fail();
        return prevValue;
    }
    return performPut(e, ctx, valueMatcher, key, newValue, metadata, command, command.hasAnyFlag(FlagBitSets.PUT_FOR_STATE_TRANSFER | FlagBitSets.PUT_FOR_X_SITE_STATE_TRANSFER));
}
Also used : ValueMatcher(org.infinispan.commands.write.ValueMatcher) Metadata(org.infinispan.metadata.Metadata) InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl) MVCCEntry(org.infinispan.container.entries.MVCCEntry)

Example 3 with InternalMetadataImpl

use of org.infinispan.metadata.impl.InternalMetadataImpl 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 4 with InternalMetadataImpl

use of org.infinispan.metadata.impl.InternalMetadataImpl in project infinispan by infinispan.

the class InternalMetadataTest method testWithInternalCacheEntry.

public void testWithInternalCacheEntry() {
    TestMetadata metadata = new TestMetadata(1, 2);
    InternalMetadataImpl internalMetadata = new InternalMetadataImpl(metadata, 3, 4);
    assertInternalMetadataValues(internalMetadata, 1, 2, 3, 4);
    assertInternalMetadataActual(internalMetadata);
    TestInternalCacheEntry cacheEntry = new TestInternalCacheEntry(internalMetadata, 5, 6);
    InternalMetadataImpl internalMetadata2 = new InternalMetadataImpl(cacheEntry);
    assertInternalMetadataValues(internalMetadata2, 1, 2, 5, 6);
    assertInternalMetadataActual(internalMetadata2);
}
Also used : InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl)

Example 5 with InternalMetadataImpl

use of org.infinispan.metadata.impl.InternalMetadataImpl in project infinispan by infinispan.

the class InternalMetadataTest method testWithInternalCacheEntry2.

public void testWithInternalCacheEntry2() {
    TestMetadata metadata = new TestMetadata(1, 2);
    TestInternalCacheEntry cacheEntry = new TestInternalCacheEntry(metadata, 3, 4);
    InternalMetadataImpl internalMetadata = new InternalMetadataImpl(cacheEntry);
    assertInternalMetadataValues(internalMetadata, 1, 2, 3, 4);
    assertInternalMetadataActual(internalMetadata);
}
Also used : InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl)

Aggregations

InternalMetadataImpl (org.infinispan.metadata.impl.InternalMetadataImpl)10 PutKeyValueCommand (org.infinispan.commands.write.PutKeyValueCommand)5 InternalCacheValue (org.infinispan.container.entries.InternalCacheValue)3 Completable (io.reactivex.rxjava3.core.Completable)2 Flowable (io.reactivex.rxjava3.core.Flowable)2 Single (io.reactivex.rxjava3.core.Single)2 MethodHandles (java.lang.invoke.MethodHandles)2 CompletionStage (java.util.concurrent.CompletionStage)2 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)2 Transaction (javax.transaction.Transaction)2 TransactionManager (javax.transaction.TransactionManager)2 AdvancedCache (org.infinispan.AdvancedCache)2 InvocationHelper (org.infinispan.cache.impl.InvocationHelper)2 CommandsFactory (org.infinispan.commands.CommandsFactory)2 Metadata (org.infinispan.metadata.Metadata)2 Maybe (io.reactivex.rxjava3.core.Maybe)1 Function (io.reactivex.rxjava3.functions.Function)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1