Search in sources :

Example 1 with ImmortalCacheValue

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

the class GetAllCacheNotFoundResponseTest method test.

public void test() throws InterruptedException, ExecutionException, TimeoutException {
    ControlledRpcManager crm4 = ControlledRpcManager.replaceRpcManager(cache(4));
    crm4.excludeCommands(StateResponseCommand.class);
    MagicKey key1 = new MagicKey(cache(0), cache(1));
    MagicKey key2 = new MagicKey(cache(0), cache(2));
    MagicKey key3 = new MagicKey(cache(2), cache(3));
    // We expect the targets of ClusteredGetAllCommands to be selected in a specific way and for that we need
    // to iterate through the keys in certain order.
    Set<Object> keys = new LinkedHashSet<>(Arrays.asList(key1, key2, key3));
    Future<Map<Object, Object>> future = fork(() -> cache(4).getAdvancedCache().getAll(keys));
    // Wait until the first two ClusteredGetAllCommands are sent
    log.debugf("Expect first get all");
    ControlledRpcManager.BlockedRequests round1 = crm4.expectCommands(ClusteredGetAllCommand.class, address(0), address(2));
    // Provide fake responses for the 1st round
    round1.skipSendAndReceive(address(0), CacheNotFoundResponse.INSTANCE);
    round1.skipSendAndReceiveAsync(address(2), UnsureResponse.INSTANCE);
    // Key retries are independent: will retry key1 on cache1, key2 on cache2, and key3 on cache3
    log.debugf("Expect 1st retry");
    ControlledRpcManager.BlockedRequests round2 = crm4.expectCommands(ClusteredGetAllCommand.class, address(1), address(2), address(3));
    // Provide a response for the retry commands.
    // We simulate that key1 is completely lost due to crashing nodes.
    round2.skipSendAndReceive(address(1), CacheNotFoundResponse.INSTANCE);
    round2.skipSendAndReceive(address(2), SuccessfulResponse.create(new InternalCacheValue[] { new ImmortalCacheValue("value2") }));
    round2.skipSendAndReceiveAsync(address(3), SuccessfulResponse.create(new InternalCacheValue[] { new ImmortalCacheValue("value3") }));
    // After all the owners are lost, we must wait for a new topology in case the key is still available
    crm4.expectNoCommand(10, TimeUnit.MILLISECONDS);
    log.debugf("Increment topology and expect 2nd retry");
    Future<Void> topologyUpdateFuture = simulateTopologyUpdate(cache(4));
    ControlledRpcManager.BlockedRequests round3 = crm4.expectCommands(ClusteredGetAllCommand.class, address(0));
    // Provide a response for the 2nd retry
    // Because we only simulated the loss of cache0, the primary owner is the same
    round3.skipSendAndReceive(address(0), SuccessfulResponse.create(new InternalCacheValue[] { null }));
    log.debugf("Expect final result");
    topologyUpdateFuture.get(10, TimeUnit.SECONDS);
    Map<Object, Object> values = future.get(10, TimeUnit.SECONDS);
    // assertEquals is more verbose than assertNull in case of failure
    assertEquals(null, values.get(key1));
    assertEquals("value2", values.get(key2));
    assertEquals("value3", values.get(key3));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue) ControlledRpcManager(org.infinispan.util.ControlledRpcManager) MagicKey(org.infinispan.distribution.MagicKey) Map(java.util.Map) ImmortalCacheValue(org.infinispan.container.entries.ImmortalCacheValue)

Example 2 with ImmortalCacheValue

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

the class VersionAwareMarshallerTest method testInternalCacheValueMarshalling.

public void testInternalCacheValueMarshalling() throws Exception {
    ImmortalCacheValue value1 = (ImmortalCacheValue) TestInternalCacheEntryFactory.createValue("value", System.currentTimeMillis() - 1000, -1, System.currentTimeMillis(), -1);
    byte[] bytes = marshaller.objectToByteBuffer(value1);
    ImmortalCacheValue rvalue1 = (ImmortalCacheValue) marshaller.objectFromByteBuffer(bytes);
    assert rvalue1.getValue().equals(value1.getValue()) : "Writen[" + rvalue1.getValue() + "] and read[" + value1.getValue() + "] objects should be the same";
    MortalCacheValue value2 = (MortalCacheValue) TestInternalCacheEntryFactory.createValue("value", System.currentTimeMillis() - 1000, 200000, System.currentTimeMillis(), -1);
    bytes = marshaller.objectToByteBuffer(value2);
    MortalCacheValue rvalue2 = (MortalCacheValue) marshaller.objectFromByteBuffer(bytes);
    assert rvalue2.getValue().equals(value2.getValue()) : "Writen[" + rvalue2.getValue() + "] and read[" + value2.getValue() + "] objects should be the same";
    TransientCacheValue value3 = (TransientCacheValue) TestInternalCacheEntryFactory.createValue("value", System.currentTimeMillis() - 1000, -1, System.currentTimeMillis(), 4000000);
    bytes = marshaller.objectToByteBuffer(value3);
    TransientCacheValue rvalue3 = (TransientCacheValue) marshaller.objectFromByteBuffer(bytes);
    assert rvalue3.getValue().equals(value3.getValue()) : "Writen[" + rvalue3.getValue() + "] and read[" + value3.getValue() + "] objects should be the same";
    TransientMortalCacheValue value4 = (TransientMortalCacheValue) TestInternalCacheEntryFactory.createValue("value", System.currentTimeMillis() - 1000, 200000, System.currentTimeMillis(), 4000000);
    bytes = marshaller.objectToByteBuffer(value4);
    TransientMortalCacheValue rvalue4 = (TransientMortalCacheValue) marshaller.objectFromByteBuffer(bytes);
    assert rvalue4.getValue().equals(value4.getValue()) : "Writen[" + rvalue4.getValue() + "] and read[" + value4.getValue() + "] objects should be the same";
}
Also used : TransientMortalCacheValue(org.infinispan.container.entries.TransientMortalCacheValue) TransientCacheValue(org.infinispan.container.entries.TransientCacheValue) TransientMortalCacheValue(org.infinispan.container.entries.TransientMortalCacheValue) MortalCacheValue(org.infinispan.container.entries.MortalCacheValue) ImmortalCacheValue(org.infinispan.container.entries.ImmortalCacheValue)

Example 3 with ImmortalCacheValue

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

the class RemoteGetFailureTest method testOneOwnerSuspectedNoFilter.

public void testOneOwnerSuspectedNoFilter(Method m) throws ExecutionException, InterruptedException {
    initAndCheck(m);
    CountDownLatch arrival = new CountDownLatch(2);
    CountDownLatch release1 = new CountDownLatch(1);
    CountDownLatch release2 = new CountDownLatch(1);
    cache(1).getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new DelayingInterceptor(arrival, release1), 0);
    cache(2).getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new DelayingInterceptor(arrival, release2), 0);
    Address address1 = address(1);
    Address address2 = address(2);
    List<Address> owners = Arrays.asList(address1, address2);
    ClusteredGetCommand clusteredGet = new ClusteredGetCommand(key, ByteString.fromString(cache(0).getName()), TestingUtil.getSegmentForKey(key, cache(1)), 0);
    final int timeout = 15;
    RpcOptions rpcOptions = new RpcOptions(DeliverOrder.NONE, timeout, TimeUnit.SECONDS);
    RpcManager rpcManager = cache(0).getAdvancedCache().getRpcManager();
    clusteredGet.setTopologyId(rpcManager.getTopologyId());
    CompletableFuture<Map<Address, Response>> future = rpcManager.invokeCommand(owners, clusteredGet, MapResponseCollector.ignoreLeavers(), rpcOptions).toCompletableFuture();
    assertTrue(arrival.await(10, TimeUnit.SECONDS));
    installNewView(cache(0), cache(0), cache(1));
    // RequestCorrelator processes the view asynchronously, so we need to wait a bit for node 2 to be suspected
    Thread.sleep(100);
    // suspection should not fail the operation
    assertFalse(future.isDone());
    long requestAllowed = System.nanoTime();
    release1.countDown();
    Map<Address, Response> responses = future.get();
    long requestCompleted = System.nanoTime();
    long requestSeconds = TimeUnit.NANOSECONDS.toSeconds(requestCompleted - requestAllowed);
    assertTrue("Request took too long: " + requestSeconds, requestSeconds < timeout / 2);
    assertEquals(SuccessfulResponse.create(new ImmortalCacheValue(m.getName())), responses.get(address1));
    assertEquals(CacheNotFoundResponse.INSTANCE, responses.get(address2));
    release2.countDown();
}
Also used : JGroupsAddress(org.infinispan.remoting.transport.jgroups.JGroupsAddress) Address(org.infinispan.remoting.transport.Address) RpcManager(org.infinispan.remoting.rpc.RpcManager) CountDownLatch(java.util.concurrent.CountDownLatch) ClusteredGetCommand(org.infinispan.commands.remote.ClusteredGetCommand) CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) Response(org.infinispan.remoting.responses.Response) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) Map(java.util.Map) ImmortalCacheValue(org.infinispan.container.entries.ImmortalCacheValue)

Example 4 with ImmortalCacheValue

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

the class InternalEntryFactoryImpl method createValue.

@Override
public InternalCacheValue createValue(CacheEntry cacheEntry) {
    Metadata metadata = cacheEntry.getMetadata();
    long lifespan = cacheEntry.getLifespan();
    long maxIdle = cacheEntry.getMaxIdle();
    if (!isStoreMetadata(metadata, null)) {
        if (lifespan < 0 && maxIdle < 0)
            return new ImmortalCacheValue(cacheEntry.getValue());
        if (lifespan > -1 && maxIdle < 0)
            return new MortalCacheValue(cacheEntry.getValue(), cacheEntry.getCreated(), lifespan);
        if (lifespan < 0 && maxIdle > -1)
            return new TransientCacheValue(cacheEntry.getValue(), maxIdle, cacheEntry.getLastUsed());
        return new TransientMortalCacheValue(cacheEntry.getValue(), cacheEntry.getCreated(), lifespan, maxIdle, cacheEntry.getLastUsed());
    } else {
        if (lifespan < 0 && maxIdle < 0)
            return new MetadataImmortalCacheValue(cacheEntry.getValue(), cacheEntry.getMetadata());
        if (lifespan > -1 && maxIdle < 0)
            return new MetadataMortalCacheValue(cacheEntry.getValue(), cacheEntry.getMetadata(), cacheEntry.getCreated());
        if (lifespan < 0 && maxIdle > -1)
            return new MetadataTransientCacheValue(cacheEntry.getValue(), cacheEntry.getMetadata(), cacheEntry.getLastUsed());
        return new MetadataTransientMortalCacheValue(cacheEntry.getValue(), cacheEntry.getMetadata(), cacheEntry.getCreated(), cacheEntry.getLastUsed());
    }
}
Also used : MetadataImmortalCacheValue(org.infinispan.container.entries.metadata.MetadataImmortalCacheValue) MetadataMortalCacheValue(org.infinispan.container.entries.metadata.MetadataMortalCacheValue) TransientMortalCacheValue(org.infinispan.container.entries.TransientMortalCacheValue) MetadataTransientMortalCacheValue(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheValue) MetadataTransientMortalCacheValue(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheValue) MetadataTransientCacheValue(org.infinispan.container.entries.metadata.MetadataTransientCacheValue) TransientCacheValue(org.infinispan.container.entries.TransientCacheValue) Metadata(org.infinispan.metadata.Metadata) PrivateMetadata(org.infinispan.metadata.impl.PrivateMetadata) EmbeddedMetadata(org.infinispan.metadata.EmbeddedMetadata) TransientMortalCacheValue(org.infinispan.container.entries.TransientMortalCacheValue) MetadataTransientMortalCacheValue(org.infinispan.container.entries.metadata.MetadataTransientMortalCacheValue) MetadataMortalCacheValue(org.infinispan.container.entries.metadata.MetadataMortalCacheValue) MortalCacheValue(org.infinispan.container.entries.MortalCacheValue) MetadataTransientCacheValue(org.infinispan.container.entries.metadata.MetadataTransientCacheValue) MetadataImmortalCacheValue(org.infinispan.container.entries.metadata.MetadataImmortalCacheValue) ImmortalCacheValue(org.infinispan.container.entries.ImmortalCacheValue)

Aggregations

ImmortalCacheValue (org.infinispan.container.entries.ImmortalCacheValue)4 Map (java.util.Map)2 MortalCacheValue (org.infinispan.container.entries.MortalCacheValue)2 TransientCacheValue (org.infinispan.container.entries.TransientCacheValue)2 TransientMortalCacheValue (org.infinispan.container.entries.TransientMortalCacheValue)2 LinkedHashSet (java.util.LinkedHashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ClusteredGetCommand (org.infinispan.commands.remote.ClusteredGetCommand)1 InternalCacheValue (org.infinispan.container.entries.InternalCacheValue)1 MetadataImmortalCacheValue (org.infinispan.container.entries.metadata.MetadataImmortalCacheValue)1 MetadataMortalCacheValue (org.infinispan.container.entries.metadata.MetadataMortalCacheValue)1 MetadataTransientCacheValue (org.infinispan.container.entries.metadata.MetadataTransientCacheValue)1 MetadataTransientMortalCacheValue (org.infinispan.container.entries.metadata.MetadataTransientMortalCacheValue)1 MagicKey (org.infinispan.distribution.MagicKey)1 EmbeddedMetadata (org.infinispan.metadata.EmbeddedMetadata)1 Metadata (org.infinispan.metadata.Metadata)1 PrivateMetadata (org.infinispan.metadata.impl.PrivateMetadata)1 CacheNotFoundResponse (org.infinispan.remoting.responses.CacheNotFoundResponse)1 Response (org.infinispan.remoting.responses.Response)1 SuccessfulResponse (org.infinispan.remoting.responses.SuccessfulResponse)1