Search in sources :

Example 1 with InternalCacheValue

use of org.infinispan.container.entries.InternalCacheValue in project infinispan by infinispan.

the class ScatteredStateConsumerImpl method backupEntries.

private void backupEntries(List<InternalCacheEntry<?, ?>> entries) {
    long incrementedCounter = chunkCounter.incrementAndGet();
    if (log.isTraceEnabled())
        log.tracef("Backing up entries, chunk counter is %d", incrementedCounter);
    Map<Object, InternalCacheValue<?>> map = new HashMap<>();
    for (InternalCacheEntry<?, ?> entry : entries) {
        map.put(entry.getKey(), entry.toInternalCacheValue());
    }
    PutMapCommand putMapCommand = commandsFactory.buildPutMapCommand(map, null, STATE_TRANSFER_FLAGS);
    putMapCommand.setTopologyId(rpcManager.getTopologyId());
    rpcManager.invokeCommand(backupAddress, putMapCommand, SingleResponseCollector.validOnly(), rpcManager.getSyncRpcOptions()).whenComplete(((response, throwable) -> {
        try {
            if (throwable != null) {
                log.failedOutBoundTransferExecution(throwable);
            }
        } finally {
            long decrementedCounter = chunkCounter.decrementAndGet();
            if (log.isTraceEnabled())
                log.tracef("Backed up entries, chunk counter is %d", decrementedCounter);
            if (decrementedCounter == 0) {
                notifyEndOfStateTransferIfNeeded();
            }
        }
    }));
}
Also used : IntSets(org.infinispan.commons.util.IntSets) LogFactory(org.infinispan.util.logging.LogFactory) EntryVersion(org.infinispan.container.versioning.EntryVersion) RemoteMetadata(org.infinispan.container.entries.RemoteMetadata) ClusteredGetAllCommand(org.infinispan.commands.remote.ClusteredGetAllCommand) CONTAINER(org.infinispan.util.logging.Log.CONTAINER) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) Map(java.util.Map) PERSISTENCE(org.infinispan.util.logging.Log.PERSISTENCE) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BlockingQueue(java.util.concurrent.BlockingQueue) CacheTopology(org.infinispan.topology.CacheTopology) ComponentStatus(org.infinispan.lifecycle.ComponentStatus) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) IntSet(org.infinispan.commons.util.IntSet) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) InboundTransferTask(org.infinispan.statetransfer.InboundTransferTask) GuardedBy(net.jcip.annotations.GuardedBy) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue) InvalidateVersionsCommand(org.infinispan.commands.write.InvalidateVersionsCommand) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) HashMap(java.util.HashMap) Metadata(org.infinispan.metadata.Metadata) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector) FlagBitSets(org.infinispan.context.impl.FlagBitSets) InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl) Configurations(org.infinispan.configuration.cache.Configurations) SingleResponseCollector(org.infinispan.remoting.transport.impl.SingleResponseCollector) Log(org.infinispan.util.logging.Log) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) Address(org.infinispan.remoting.transport.Address) Response(org.infinispan.remoting.responses.Response) InternalEntryFactory(org.infinispan.container.impl.InternalEntryFactory) CacheException(org.infinispan.commons.CacheException) Flowable(io.reactivex.rxjava3.core.Flowable) Iterator(java.util.Iterator) Publisher(org.reactivestreams.Publisher) PutMapCommand(org.infinispan.commands.write.PutMapCommand) SimpleClusteredVersion(org.infinispan.container.versioning.SimpleClusteredVersion) Inject(org.infinispan.factories.annotations.Inject) StateConsumerImpl(org.infinispan.statetransfer.StateConsumerImpl) PrimitiveIterator(java.util.PrimitiveIterator) AtomicLong(java.util.concurrent.atomic.AtomicLong) CacheRpcCommand(org.infinispan.commands.remote.CacheRpcCommand) Collections(java.util.Collections) ScatteredVersionManager(org.infinispan.scattered.ScatteredVersionManager) SuspectException(org.infinispan.remoting.transport.jgroups.SuspectException) PutMapCommand(org.infinispan.commands.write.PutMapCommand) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue)

Example 2 with InternalCacheValue

use of org.infinispan.container.entries.InternalCacheValue in project infinispan by infinispan.

the class ConflictManagerTest method testGetAllVersionsDuringStateTransfer.

public void testGetAllVersionsDuringStateTransfer() throws Exception {
    final int key = 1;
    final int value = 1;
    createCluster();
    getCache(2).put(key, value);
    splitCluster();
    RehashListener listener = new RehashListener();
    getCache(0).addListener(listener);
    CountDownLatch latch = new CountDownLatch(1);
    delayStateTransferCompletion(latch);
    // Trigger the merge and wait for state transfer to begin
    Future<?> mergeFuture = fork(() -> partition(0).merge(partition(1)));
    assertTrue(listener.latch.await(10, TimeUnit.SECONDS));
    Future<Map<Address, InternalCacheValue<Object>>> versionFuture = fork(() -> getAllVersions(0, key));
    // Check that getAllVersions doesn't return while state transfer is in progress
    TestingUtil.assertNotDone(versionFuture);
    // Allow and wait for state transfer to finish
    latch.countDown();
    mergeFuture.get(30, TimeUnit.SECONDS);
    // Check the results
    Map<Address, InternalCacheValue<Object>> versionMap = versionFuture.get(60, TimeUnit.SECONDS);
    assertTrue(versionMap != null);
    assertTrue(!versionMap.isEmpty());
    // mergepolicy == null, so no conflict resolution occurs therefore it's possible that versionMap may contain null entries
    assertEquals(String.format("Returned versionMap %s", versionMap), 2, versionMap.size());
}
Also used : Address(org.infinispan.remoting.transport.Address) CountDownLatch(java.util.concurrent.CountDownLatch) Map(java.util.Map) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue)

Example 3 with InternalCacheValue

use of org.infinispan.container.entries.InternalCacheValue in project infinispan by infinispan.

the class CrashedNodeDuringConflictResolutionTest method afterConflictResolutionAndMerge.

@Override
protected void afterConflictResolutionAndMerge() {
    ConflictManager cm = conflictManager(0);
    assertFalse(cm.isConflictResolutionInProgress());
    for (String key : ALL_KEYS) {
        Map<Address, InternalCacheValue> versionMap = cm.getAllVersions(key);
        assertNotNull(versionMap);
        assertEquals("Versions: " + versionMap, numberOfOwners, versionMap.size());
        String message = String.format("Key=%s. VersionMap: %s", key, versionMap);
        for (InternalCacheValue icv : versionMap.values()) {
            assertNotNull(message, icv);
            assertNotNull(message, icv.getValue());
            assertEquals(message, valueAfterMerge, icv.getValue());
        }
    }
    assertEquals(0, cm.getConflicts().peek(m -> log.errorf("Conflict: " + m)).count());
}
Also used : Address(org.infinispan.remoting.transport.Address) ConflictManager(org.infinispan.conflict.ConflictManager) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue)

Example 4 with InternalCacheValue

use of org.infinispan.container.entries.InternalCacheValue in project infinispan by infinispan.

the class BaseStoreTest method testLoadAndStoreWithLifespanAndIdle.

public void testLoadAndStoreWithLifespanAndIdle() throws Exception {
    assertIsEmpty();
    long lifespan = 200000;
    long idle = 120000;
    InternalCacheEntry se = internalCacheEntry("k", "v", lifespan, idle);
    InternalCacheValue icv = se.toInternalCacheValue();
    assertEquals(se.getCreated(), icv.getCreated());
    assertEquals(se.getLastUsed(), icv.getLastUsed());
    assertExpired(se, false);
    cl.write(marshalledEntry(se));
    assertContains("k", true);
    assertCorrectExpiry(cl.loadEntry("k"), "v", lifespan, idle, false);
    assertCorrectExpiry(TestingUtil.allEntries(cl).iterator().next(), "v", lifespan, idle, false);
    timeService.advance(idle + 1);
    idle = 1000;
    lifespan = 4000;
    se = internalCacheEntry("k", "v", lifespan, idle);
    assertExpired(se, false);
    cl.write(marshalledEntry(se));
    timeService.advance(idle + 1);
    purgeExpired("k");
    // expired by idle
    assertExpired(se, true);
    assertEventuallyExpires("k");
    assertContains("k", false);
    assertIsEmpty();
}
Also used : InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue)

Example 5 with InternalCacheValue

use of org.infinispan.container.entries.InternalCacheValue in project infinispan by infinispan.

the class WriteSkewCacheLoaderFunctionalTest method assertInCacheAndStore.

private void assertInCacheAndStore(Cache cache, DummyInMemoryStore store, Object key, Object value, long lifespanMillis) throws PersistenceException {
    InternalCacheValue icv = cache.getAdvancedCache().getDataContainer().peek(key).toInternalCacheValue();
    assertStoredEntry(icv.getValue(), value, icv.getLifespan(), lifespanMillis, "Cache", key);
    assertNotNull("For :" + icv, icv.getInternalMetadata().entryVersion());
    MarshallableEntry<?, ?> load = store.loadEntry(key);
    assertStoredEntry(load.getValue(), value, load.getMetadata().lifespan(), lifespanMillis, "Store", key);
    assertNotNull("For :" + load, load.getInternalMetadata().entryVersion());
}
Also used : InternalCacheValue(org.infinispan.container.entries.InternalCacheValue)

Aggregations

InternalCacheValue (org.infinispan.container.entries.InternalCacheValue)21 Map (java.util.Map)11 InternalCacheEntry (org.infinispan.container.entries.InternalCacheEntry)10 Address (org.infinispan.remoting.transport.Address)9 HashMap (java.util.HashMap)7 Response (org.infinispan.remoting.responses.Response)7 SuccessfulResponse (org.infinispan.remoting.responses.SuccessfulResponse)7 CacheException (org.infinispan.commons.CacheException)6 CacheEntry (org.infinispan.container.entries.CacheEntry)6 ClusteredGetCommand (org.infinispan.commands.remote.ClusteredGetCommand)5 NullCacheEntry (org.infinispan.container.entries.NullCacheEntry)5 RemoteMetadata (org.infinispan.container.entries.RemoteMetadata)5 DistributionInfo (org.infinispan.distribution.DistributionInfo)5 LocalizedCacheTopology (org.infinispan.distribution.LocalizedCacheTopology)5 Metadata (org.infinispan.metadata.Metadata)5 CompletionStage (java.util.concurrent.CompletionStage)4 UnsureResponse (org.infinispan.remoting.responses.UnsureResponse)4 Collection (java.util.Collection)3 Collections (java.util.Collections)3 Iterator (java.util.Iterator)3