Search in sources :

Example 1 with IracEntryVersion

use of org.infinispan.container.versioning.irac.IracEntryVersion in project infinispan by infinispan.

the class SingleFileStore method generateMissingInternalMetadata.

// Initialise missing internal metadata state for corrupt data
private PrivateMetadata generateMissingInternalMetadata() {
    // Optimistic Transactions
    AdvancedCache<?, ?> cache = ctx.getCache().getAdvancedCache();
    Configuration config = cache.getCacheConfiguration();
    TransactionConfiguration txConfig = config.transaction();
    PrivateMetadata.Builder builder = new PrivateMetadata.Builder();
    if (txConfig.transactionMode() == TransactionMode.TRANSACTIONAL && txConfig.lockingMode() == LockingMode.OPTIMISTIC) {
        builder.entryVersion(new SimpleClusteredVersion(1, 1));
    }
    // Async XSite
    if (config.sites().hasAsyncEnabledBackups()) {
        String siteName = cache.getRpcManager().getTransport().localSiteName();
        IracEntryVersion version = IracEntryVersion.newVersion(XSiteNamedCache.cachedByteString(siteName), TopologyIracVersion.newVersion(1));
        builder.iracMetadata(new IracMetadata(siteName, version));
    }
    return builder.build();
}
Also used : TransactionConfiguration(org.infinispan.configuration.cache.TransactionConfiguration) SimpleClusteredVersion(org.infinispan.container.versioning.SimpleClusteredVersion) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) SingleFileStoreConfiguration(org.infinispan.configuration.cache.SingleFileStoreConfiguration) AbstractSegmentedStoreConfiguration(org.infinispan.configuration.cache.AbstractSegmentedStoreConfiguration) TransactionConfiguration(org.infinispan.configuration.cache.TransactionConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) IracEntryVersion(org.infinispan.container.versioning.irac.IracEntryVersion) IracMetadata(org.infinispan.metadata.impl.IracMetadata) PrivateMetadata(org.infinispan.metadata.impl.PrivateMetadata)

Example 2 with IracEntryVersion

use of org.infinispan.container.versioning.irac.IracEntryVersion in project infinispan by infinispan.

the class PessimisticTxIracLocalInterceptor method requestNewMetadata.

private CompletionStage<IracMetadata> requestNewMetadata(int segment, CacheEntry<?, ?> cacheEntry) {
    LocalizedCacheTopology cacheTopology = getCacheTopology();
    DistributionInfo dInfo = cacheTopology.getSegmentDistribution(segment);
    if (dInfo.isPrimary()) {
        IracEntryVersion versionSeen = getIracVersionFromCacheEntry(cacheEntry);
        return CompletableFuture.completedFuture(iracVersionGenerator.generateNewMetadata(segment, versionSeen));
    } else {
        return requestNewMetadataFromPrimaryOwner(dInfo, cacheTopology.getTopologyId(), cacheEntry);
    }
}
Also used : IracEntryVersion(org.infinispan.container.versioning.irac.IracEntryVersion) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) DistributionInfo(org.infinispan.distribution.DistributionInfo)

Example 3 with IracEntryVersion

use of org.infinispan.container.versioning.irac.IracEntryVersion in project infinispan by infinispan.

the class OptimisticTxIracLocalSiteInterceptor method afterRemoteTwoPhasePrepare.

private Object afterRemoteTwoPhasePrepare(InvocationContext ctx, PrepareCommand command, Object rv) {
    if (isTraceEnabled()) {
        getLog().tracef("[IRAC] After successful remote prepare for tx %s. Return Value: %s", command.getGlobalTransaction(), rv);
    }
    PrepareResponse rsp = PrepareResponse.asPrepareResponse(rv);
    Iterator<StreamData> iterator = streamKeysFromModifications(command.getModifications()).filter(this::isPrimaryOwner).distinct().iterator();
    Map<Integer, IracEntryVersion> maxVersionSeen = new HashMap<>();
    while (iterator.hasNext()) {
        StreamData data = iterator.next();
        IracEntryVersion versionSeen = getIracVersionFromCacheEntry(ctx.lookupEntry(data.key));
        if (versionSeen != null) {
            maxVersionSeen.merge(data.segment, versionSeen, IracEntryVersion::merge);
        } else {
            maxVersionSeen.putIfAbsent(data.segment, null);
        }
    }
    Map<Integer, IracMetadata> segmentMetadata = new HashMap<>();
    maxVersionSeen.forEach((segment, version) -> segmentMetadata.put(segment, iracVersionGenerator.generateNewMetadata(segment, version)));
    rsp.setNewIracMetadata(segmentMetadata);
    if (isTraceEnabled()) {
        getLog().tracef("[IRAC] After successful remote prepare for tx %s. New Return Value: %s", command.getGlobalTransaction(), rsp);
    }
    return rsp;
}
Also used : PrepareResponse.asPrepareResponse(org.infinispan.remoting.responses.PrepareResponse.asPrepareResponse) PrepareResponse(org.infinispan.remoting.responses.PrepareResponse) IracEntryVersion(org.infinispan.container.versioning.irac.IracEntryVersion) HashMap(java.util.HashMap) IracMetadata(org.infinispan.metadata.impl.IracMetadata)

Example 4 with IracEntryVersion

use of org.infinispan.container.versioning.irac.IracEntryVersion in project infinispan by infinispan.

the class IracRestartWithoutGlobalStateTest method assertVersions.

private <K> void assertVersions(Map<K, IracEntryVersion> v1, Map<K, IracEntryVersion> v2, InequalVersionComparisonResult expected) {
    assertEquals(v1.size(), v2.size());
    Iterator<K> iterator = Stream.concat(v1.keySet().stream(), v2.keySet().stream()).distinct().iterator();
    while (iterator.hasNext()) {
        K key = iterator.next();
        IracEntryVersion version1 = v1.get(key);
        IracEntryVersion version2 = v2.get(key);
        assertNotNull(format("'%s' version is null for Map 1", key), version1);
        assertNotNull(format("'%s' version is null for Map 2", key), version2);
        InequalVersionComparisonResult result = version1.compareTo(version2);
        assertEquals(format("'%s' version mismatch: %s and %s", key, version1, version2), expected, result);
    }
}
Also used : IracEntryVersion(org.infinispan.container.versioning.irac.IracEntryVersion) InequalVersionComparisonResult(org.infinispan.container.versioning.InequalVersionComparisonResult)

Example 5 with IracEntryVersion

use of org.infinispan.container.versioning.irac.IracEntryVersion in project infinispan by infinispan.

the class IracWriteSkewTest method checkKey.

private void checkKey(String key, String value) {
    // irac version is the same in all nodes & sites. extract it from one site and check everywhere.
    IracEntryVersion iracVersion = extractIracEntryVersion(key);
    assertNotNull(iracVersion);
    assertIracEntryVersion(key, value, iracVersion);
    // NYC has the EntryVersion for write-skew check
    IncrementableEntryVersion entryVersion = extractEntryVersion(key);
    assertNotNull(entryVersion);
    assertIracEntryVersion(key, value, iracVersion, entryVersion);
}
Also used : IracEntryVersion(org.infinispan.container.versioning.irac.IracEntryVersion) IncrementableEntryVersion(org.infinispan.container.versioning.IncrementableEntryVersion)

Aggregations

IracEntryVersion (org.infinispan.container.versioning.irac.IracEntryVersion)14 HashMap (java.util.HashMap)5 IracMetadata (org.infinispan.metadata.impl.IracMetadata)5 LocalizedCacheTopology (org.infinispan.distribution.LocalizedCacheTopology)4 DistributionInfo (org.infinispan.distribution.DistributionInfo)3 InequalVersionComparisonResult (org.infinispan.container.versioning.InequalVersionComparisonResult)2 PrepareResponse (org.infinispan.remoting.responses.PrepareResponse)2 PrepareResponse.asPrepareResponse (org.infinispan.remoting.responses.PrepareResponse.asPrepareResponse)2 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Stream (java.util.stream.Stream)1 IracMetadataRequestCommand (org.infinispan.commands.irac.IracMetadataRequestCommand)1 CommitCommand (org.infinispan.commands.tx.CommitCommand)1 PrepareCommand (org.infinispan.commands.tx.PrepareCommand)1 RollbackCommand (org.infinispan.commands.tx.RollbackCommand)1 PutKeyValueCommand (org.infinispan.commands.write.PutKeyValueCommand)1 RemoveExpiredCommand (org.infinispan.commands.write.RemoveExpiredCommand)1 WriteCommand (org.infinispan.commands.write.WriteCommand)1 AbstractSegmentedStoreConfiguration (org.infinispan.configuration.cache.AbstractSegmentedStoreConfiguration)1