Search in sources :

Example 1 with RemoveCommand

use of org.infinispan.commands.write.RemoveCommand in project infinispan by infinispan.

the class CacheMgmtInterceptorTest method testVisitRemoveCommand.

public void testVisitRemoveCommand() throws Throwable {
    RemoveCommand command = new RemoveCommand(KEY, null, 0, 0, null);
    InvocationStage stage = makeStage(interceptor.visitRemoveCommand(ctx, command));
    assertFalse(stage.isDone());
    timeService.advance(1);
    nextInterceptor.completeLastInvocation(VALUE);
    assertEquals(VALUE, stage.get());
    assertEquals(1, interceptor.getAverageRemoveTime());
}
Also used : RemoveCommand(org.infinispan.commands.write.RemoveCommand) InvocationStage(org.infinispan.interceptors.InvocationStage)

Example 2 with RemoveCommand

use of org.infinispan.commands.write.RemoveCommand in project infinispan by infinispan.

the class CacheMgmtInterceptorTest method testVisitRemoveCommandException.

public void testVisitRemoveCommandException() throws Throwable {
    RemoveCommand command = new RemoveCommand(KEY, null, 0, 0, null);
    InvocationStage stage = makeStage(interceptor.visitRemoveCommand(ctx, command));
    assertFalse(stage.isDone());
    timeService.advance(1);
    nextInterceptor.completeLastInvocationExceptionally(new TestException());
    expectInvocationException(stage);
    assertEquals(0, interceptor.getAverageRemoveTime());
}
Also used : RemoveCommand(org.infinispan.commands.write.RemoveCommand) InvocationStage(org.infinispan.interceptors.InvocationStage) TestException(org.infinispan.test.TestException)

Example 3 with RemoveCommand

use of org.infinispan.commands.write.RemoveCommand in project infinispan by infinispan.

the class SingleKeyBackupWriteCommand method createWriteCommand.

@Override
WriteCommand createWriteCommand() {
    DataWriteCommand command;
    switch(operation) {
        case REMOVE:
            command = new RemoveCommand(key, null, segmentId, getFlags(), getCommandInvocationId());
            break;
        case WRITE:
            command = EnumUtil.containsAny(getFlags(), FlagBitSets.IRAC_UPDATE) ? new IracPutKeyValueCommand(key, segmentId, getCommandInvocationId(), valueOrFunction, metadata, internalMetadata) : new PutKeyValueCommand(key, valueOrFunction, false, metadata, segmentId, getFlags(), getCommandInvocationId());
            break;
        case COMPUTE:
            command = new ComputeCommand(key, (BiFunction) valueOrFunction, false, segmentId, getFlags(), getCommandInvocationId(), metadata);
            break;
        case REPLACE:
            command = new ReplaceCommand(key, null, valueOrFunction, metadata, segmentId, getFlags(), getCommandInvocationId());
            break;
        case REMOVE_EXPIRED:
            // Doesn't matter if it is max idle or not - important thing is that it raises expired event
            command = new RemoveExpiredCommand(key, valueOrFunction, null, false, segmentId, getFlags(), getCommandInvocationId());
            break;
        case COMPUTE_IF_PRESENT:
            command = new ComputeCommand(key, (BiFunction) valueOrFunction, true, segmentId, getFlags(), getCommandInvocationId(), metadata);
            break;
        case COMPUTE_IF_ABSENT:
            command = new ComputeIfAbsentCommand(key, (Function) valueOrFunction, segmentId, getFlags(), getCommandInvocationId(), metadata);
            break;
        default:
            throw new IllegalStateException("Unknown operation " + operation);
    }
    command.setInternalMetadata(internalMetadata);
    return command;
}
Also used : RemoveCommand(org.infinispan.commands.write.RemoveCommand) ComputeCommand(org.infinispan.commands.write.ComputeCommand) BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) DataWriteCommand(org.infinispan.commands.write.DataWriteCommand) BiFunction(java.util.function.BiFunction) ReplaceCommand(org.infinispan.commands.write.ReplaceCommand) RemoveExpiredCommand(org.infinispan.commands.write.RemoveExpiredCommand) ComputeIfAbsentCommand(org.infinispan.commands.write.ComputeIfAbsentCommand) IracPutKeyValueCommand(org.infinispan.commands.write.IracPutKeyValueCommand) IracPutKeyValueCommand(org.infinispan.commands.write.IracPutKeyValueCommand) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand)

Example 4 with RemoveCommand

use of org.infinispan.commands.write.RemoveCommand in project infinispan by infinispan.

the class ScatteredDistributionInterceptor method handleWriteOnOriginPrimary.

private Object handleWriteOnOriginPrimary(InvocationContext ctx, DataWriteCommand command, Object rv, RepeatableReadEntry cacheEntry, Object seenValue, EntryVersion seenVersion, CacheTopology cacheTopology, DistributionInfo info) {
    if (!command.isSuccessful()) {
        if (log.isTraceEnabled())
            log.tracef("Skipping the replication of the command as it did not succeed on primary owner (%s).", command);
        return rv;
    }
    // increment the version
    EntryVersion nextVersion = svm.incrementVersion(info.segmentId());
    Metadata metadata = addVersion(cacheEntry.getMetadata(), nextVersion);
    cacheEntry.setMetadata(metadata);
    CompletionStage<Void> stage;
    if (command.loadType() != DONT_LOAD) {
        stage = commitSingleEntryIfNoChange(cacheEntry, ctx, command);
    } else {
        stage = commitSingleEntryIfNewer(cacheEntry, ctx, command);
    }
    // When replicating to backup, we'll add skip ownership check since we're now on primary owner
    // and we have already committed the entry, reading the return value. If we got OTE from remote
    // site and the command would be retried, we could fail to do the retry/return wrong value.
    WriteCommand backupCommand;
    long flags = command.getFlagsBitSet() | FlagBitSets.SKIP_OWNERSHIP_CHECK;
    if (cacheEntry.isRemoved()) {
        backupCommand = cf.buildRemoveCommand(command.getKey(), null, info.segmentId(), flags);
        ((RemoveCommand) backupCommand).setMetadata(cacheEntry.getMetadata());
    } else {
        backupCommand = cf.buildPutKeyValueCommand(command.getKey(), cacheEntry.getValue(), info.segmentId(), cacheEntry.getMetadata(), flags);
    }
    backupCommand.setTopologyId(command.getTopologyId());
    Address backup = getNextMember(cacheTopology);
    if (backup != null) {
        // error responses throw exceptions from JGroupsTransport
        CompletionStage<?> rpcFuture = rpcManager.invokeCommand(backup, backupCommand, SingleResponseCollector.validOnly(), rpcManager.getSyncRpcOptions());
        rpcFuture.thenRun(() -> {
            if (cacheEntry.isCommitted() && !command.hasAnyFlag(FlagBitSets.PUT_FOR_STATE_TRANSFER)) {
                scheduleKeyInvalidation(command.getKey(), cacheEntry.getMetadata().version(), cacheEntry.isRemoved());
            }
        });
        rpcFuture = completeSingleWriteOnPrimaryOriginator(command, backup, rpcFuture);
        // Exception responses are thrown anyway and we don't expect any return values
        return delayedValue(CompletionStages.allOf(stage.toCompletableFuture(), rpcFuture.toCompletableFuture()), rv);
    } else {
        return delayedValue(stage, rv);
    }
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) DataWriteCommand(org.infinispan.commands.write.DataWriteCommand) RemoveCommand(org.infinispan.commands.write.RemoveCommand) EntryVersion(org.infinispan.container.versioning.EntryVersion) Address(org.infinispan.remoting.transport.Address) RemoteMetadata(org.infinispan.container.entries.RemoteMetadata) EmbeddedMetadata(org.infinispan.metadata.EmbeddedMetadata) Metadata(org.infinispan.metadata.Metadata)

Example 5 with RemoveCommand

use of org.infinispan.commands.write.RemoveCommand in project infinispan by infinispan.

the class AbstractGeneralDataRegionTest method testEvict.

@Test
public void testEvict() throws Exception {
    Assume.assumeFalse("Per-key eviction is not supported in 5.3", org.hibernate.Version.getVersionString().startsWith("5.3"));
    withSessionFactoriesAndRegions(2, ((sessionFactories, regions) -> {
        InfinispanBaseRegion localRegion = regions.get(0);
        TestRegion testLocalRegion = TEST_SESSION_ACCESS.fromRegion(localRegion);
        InfinispanBaseRegion remoteRegion = regions.get(1);
        TestRegion testRemoteRegion = TEST_SESSION_ACCESS.fromRegion(remoteRegion);
        Object localSession = sessionFactories.get(0).openSession();
        Object remoteSession = sessionFactories.get(1).openSession();
        AdvancedCache<?, ?> localCache = localRegion.getCache();
        AdvancedCache<?, ?> remoteCache = remoteRegion.getCache();
        try {
            assertNull("local is clean", testLocalRegion.get(localSession, KEY));
            assertNull("remote is clean", testRemoteRegion.get(remoteSession, KEY));
            // If this node is backup owner, it will see the update once as originator and then when getting the value from primary
            boolean isLocalNodeBackupOwner = extractCacheTopology(localCache).getDistribution(KEY).writeOwners().indexOf(localCache.getCacheManager().getAddress()) > 0;
            CountDownLatch insertLatch = new CountDownLatch(isLocalNodeBackupOwner ? 3 : 2);
            ExpectingInterceptor.get(localCache).when((ctx, cmd) -> cmd instanceof PutKeyValueCommand).countDown(insertLatch);
            ExpectingInterceptor.get(remoteCache).when((ctx, cmd) -> cmd instanceof PutKeyValueCommand).countDown(insertLatch);
            Transaction tx = ((SharedSessionContract) localSession).getTransaction();
            tx.begin();
            try {
                testLocalRegion.put(localSession, KEY, VALUE1);
                tx.commit();
            } catch (Exception e) {
                tx.rollback();
                throw e;
            }
            assertTrue(insertLatch.await(2, TimeUnit.SECONDS));
            assertEquals(VALUE1, testLocalRegion.get(localSession, KEY));
            assertEquals(VALUE1, testRemoteRegion.get(remoteSession, KEY));
            CountDownLatch removeLatch = new CountDownLatch(isLocalNodeBackupOwner ? 3 : 2);
            ExpectingInterceptor.get(localCache).when((ctx, cmd) -> cmd instanceof RemoveCommand).countDown(removeLatch);
            ExpectingInterceptor.get(remoteCache).when((ctx, cmd) -> cmd instanceof RemoveCommand).countDown(removeLatch);
            regionEvict(localRegion);
            assertTrue(removeLatch.await(2, TimeUnit.SECONDS));
            assertEquals(null, testLocalRegion.get(localSession, KEY));
            assertEquals(null, testRemoteRegion.get(remoteSession, KEY));
        } finally {
            ((Session) localSession).close();
            ((Session) remoteSession).close();
            ExpectingInterceptor.cleanup(localCache, remoteCache);
        }
    }));
}
Also used : Arrays(java.util.Arrays) AvailableSettings(org.hibernate.cfg.AvailableSettings) TestSessionAccess(org.infinispan.test.hibernate.cache.commons.util.TestSessionAccess) Session(org.hibernate.Session) BatchModeJtaPlatform(org.infinispan.test.hibernate.cache.commons.util.BatchModeJtaPlatform) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) TestRegionFactoryProvider(org.infinispan.test.hibernate.cache.commons.util.TestRegionFactoryProvider) QueryResultsRegion(org.hibernate.cache.spi.QueryResultsRegion) ArrayList(java.util.ArrayList) Transaction(org.hibernate.Transaction) AdvancedCache(org.infinispan.AdvancedCache) CacheTestUtil(org.infinispan.test.hibernate.cache.commons.util.CacheTestUtil) RegionFactory(org.hibernate.cache.spi.RegionFactory) TestingUtil(org.infinispan.test.TestingUtil) AccessType(org.hibernate.cache.spi.access.AccessType) Assume(org.junit.Assume) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) RemoveCommand(org.infinispan.commands.write.RemoveCommand) Properties(java.util.Properties) NoJtaPlatform(org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform) SessionFactory(org.hibernate.SessionFactory) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) Collectors(java.util.stream.Collectors) TestRegion(org.infinispan.test.hibernate.cache.commons.util.TestSessionAccess.TestRegion) MetadataSources(org.hibernate.boot.MetadataSources) TimeUnit(java.util.concurrent.TimeUnit) InfinispanBaseRegion(org.infinispan.hibernate.cache.commons.InfinispanBaseRegion) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) CacheMode(org.infinispan.configuration.cache.CacheMode) TestingUtil.extractCacheTopology(org.infinispan.test.TestingUtil.extractCacheTopology) Assert.assertNull(org.junit.Assert.assertNull) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) ExpectingInterceptor(org.infinispan.test.hibernate.cache.commons.util.ExpectingInterceptor) SharedSessionContract(org.hibernate.SharedSessionContract) TestRegionFactory(org.infinispan.test.hibernate.cache.commons.util.TestRegionFactory) Assert.assertEquals(org.junit.Assert.assertEquals) InfinispanBaseRegion(org.infinispan.hibernate.cache.commons.InfinispanBaseRegion) RemoveCommand(org.infinispan.commands.write.RemoveCommand) Transaction(org.hibernate.Transaction) TestRegion(org.infinispan.test.hibernate.cache.commons.util.TestSessionAccess.TestRegion) AdvancedCache(org.infinispan.AdvancedCache) CountDownLatch(java.util.concurrent.CountDownLatch) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) Test(org.junit.Test)

Aggregations

RemoveCommand (org.infinispan.commands.write.RemoveCommand)13 PutKeyValueCommand (org.infinispan.commands.write.PutKeyValueCommand)5 WriteCommand (org.infinispan.commands.write.WriteCommand)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Set (java.util.Set)2 TimeUnit (java.util.concurrent.TimeUnit)2 AdvancedCache (org.infinispan.AdvancedCache)2 PrepareCommand (org.infinispan.commands.tx.PrepareCommand)2 ClearCommand (org.infinispan.commands.write.ClearCommand)2 ComputeCommand (org.infinispan.commands.write.ComputeCommand)2 DataWriteCommand (org.infinispan.commands.write.DataWriteCommand)2 ReplaceCommand (org.infinispan.commands.write.ReplaceCommand)2 InvocationContext (org.infinispan.context.InvocationContext)2 AsyncInterceptorChain (org.infinispan.interceptors.AsyncInterceptorChain)2 InvocationStage (org.infinispan.interceptors.InvocationStage)2 Metadata (org.infinispan.metadata.Metadata)2 Address (org.infinispan.remoting.transport.Address)2 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1