Search in sources :

Example 1 with SimpleClusteredVersion

use of org.infinispan.container.versioning.SimpleClusteredVersion in project infinispan by infinispan.

the class ScatteredStateProviderImpl method invalidateChunks.

private void invalidateChunks(Collection<StateChunk> stateChunks, Set<Address> otherMembers, AtomicInteger outboundInvalidations, CompletableFuture<Void> invalidationFuture, CacheTopology cacheTopology) {
    int numEntries = stateChunks.stream().mapToInt(chunk -> chunk.getCacheEntries().size()).sum();
    if (numEntries == 0) {
        log.tracef("Nothing to invalidate");
        return;
    }
    Object[] keys = new Object[numEntries];
    int[] topologyIds = new int[numEntries];
    long[] versions = new long[numEntries];
    int i = 0;
    for (StateChunk chunk : stateChunks) {
        for (InternalCacheEntry entry : chunk.getCacheEntries()) {
            // we have replicated the non-versioned entries but we won't invalidate them elsewhere
            if (entry.getMetadata() != null && entry.getMetadata().version() != null) {
                keys[i] = entry.getKey();
                SimpleClusteredVersion version = (SimpleClusteredVersion) entry.getMetadata().version();
                topologyIds[i] = version.getTopologyId();
                versions[i] = version.getVersion();
                ++i;
            }
        }
    }
    if (log.isTraceEnabled()) {
        log.tracef("Invalidating %d entries from segments %s", numEntries, stateChunks.stream().map(StateChunk::getSegmentId).collect(Collectors.toList()));
    }
    outboundInvalidations.incrementAndGet();
    rpcManager.invokeCommand(otherMembers, commandsFactory.buildInvalidateVersionsCommand(cacheTopology.getTopologyId(), keys, topologyIds, versions, true), MapResponseCollector.ignoreLeavers(otherMembers.size()), rpcManager.getSyncRpcOptions()).whenComplete((r, t) -> {
        try {
            if (t != null) {
                log.failedInvalidatingRemoteCache(t);
            }
        } finally {
            if (outboundInvalidations.decrementAndGet() == 0) {
                invalidationFuture.complete(null);
            }
        }
    });
}
Also used : InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) IntSets(org.infinispan.commons.util.IntSets) LogFactory(org.infinispan.util.logging.LogFactory) RemoteMetadata(org.infinispan.container.entries.RemoteMetadata) CompletableFuture(java.util.concurrent.CompletableFuture) StateProviderImpl(org.infinispan.statetransfer.StateProviderImpl) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector) HashSet(java.util.HashSet) StateChunk(org.infinispan.statetransfer.StateChunk) Configurations(org.infinispan.configuration.cache.Configurations) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Log(org.infinispan.util.logging.Log) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) Address(org.infinispan.remoting.transport.Address) Flowable(io.reactivex.rxjava3.core.Flowable) Iterator(java.util.Iterator) Collection(java.util.Collection) Publisher(org.reactivestreams.Publisher) ScatteredStateProvider(org.infinispan.scattered.ScatteredStateProvider) Set(java.util.Set) CacheTopology(org.infinispan.topology.CacheTopology) SimpleClusteredVersion(org.infinispan.container.versioning.SimpleClusteredVersion) Collectors(java.util.stream.Collectors) Inject(org.infinispan.factories.annotations.Inject) IntSet(org.infinispan.commons.util.IntSet) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) OutboundTransferTask(org.infinispan.statetransfer.OutboundTransferTask) ScatteredVersionManager(org.infinispan.scattered.ScatteredVersionManager) SimpleClusteredVersion(org.infinispan.container.versioning.SimpleClusteredVersion) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) StateChunk(org.infinispan.statetransfer.StateChunk)

Example 2 with SimpleClusteredVersion

use of org.infinispan.container.versioning.SimpleClusteredVersion in project infinispan by infinispan.

the class ScatteredPreloadManager method initTopologyId.

private void initTopologyId() {
    int preloadedTopologyId = scatteredVersionManager.getPreloadedTopologyId();
    if (isFullyPreloaded()) {
        // We don't have to do the preload, already done
        if (preloadedTopologyId > 0) {
            clusterTopologyManager.setInitialCacheTopologyId(cache.wired().getName(), preloadedTopologyId + 1);
        }
        return;
    }
    // An alternative (not implemented) approach is storing the max versions as a part of the persisted global state
    // in ScatteredConsistentHash, but that works only for the orderly shutdown.
    // TODO: implement start after shutdown
    AtomicInteger maxTopologyId = new AtomicInteger(preloadedTopologyId);
    Publisher<MarshallableEntry<Object, Object>> publisher = persistenceManager.publishEntries(false, true);
    CompletionStage<Void> stage = Flowable.fromPublisher(publisher).doOnNext(me -> {
        Metadata metadata = me.getMetadata();
        EntryVersion entryVersion = metadata.version();
        if (entryVersion instanceof SimpleClusteredVersion) {
            int entryTopologyId = ((SimpleClusteredVersion) entryVersion).getTopologyId();
            if (maxTopologyId.get() < entryTopologyId) {
                maxTopologyId.updateAndGet(current -> Math.max(current, entryTopologyId));
            }
        }
    }).ignoreElements().toCompletionStage(null);
    CompletionStages.join(stage);
    if (maxTopologyId.get() > 0) {
        clusterTopologyManager.setInitialCacheTopologyId(cache.wired().getName(), maxTopologyId.get() + 1);
    }
}
Also used : SimpleClusteredVersion(org.infinispan.container.versioning.SimpleClusteredVersion) EntryVersion(org.infinispan.container.versioning.EntryVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Metadata(org.infinispan.metadata.Metadata) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry)

Example 3 with SimpleClusteredVersion

use of org.infinispan.container.versioning.SimpleClusteredVersion 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 4 with SimpleClusteredVersion

use of org.infinispan.container.versioning.SimpleClusteredVersion in project infinispan by infinispan.

the class MetadataUtils method extractVersion.

public static long extractVersion(CacheEntry ce) {
    if (ce == null)
        return -1;
    EntryVersion entryVersion = ce.getMetadata().version();
    long version = 0;
    if (entryVersion != null) {
        if (entryVersion instanceof NumericVersion) {
            version = NumericVersion.class.cast(entryVersion).getVersion();
        }
        if (entryVersion instanceof SimpleClusteredVersion) {
            version = SimpleClusteredVersion.class.cast(entryVersion).getVersion();
        }
    }
    return version;
}
Also used : NumericVersion(org.infinispan.container.versioning.NumericVersion) SimpleClusteredVersion(org.infinispan.container.versioning.SimpleClusteredVersion) EntryVersion(org.infinispan.container.versioning.EntryVersion)

Example 5 with SimpleClusteredVersion

use of org.infinispan.container.versioning.SimpleClusteredVersion in project infinispan by infinispan.

the class ScatteredStateConsumerImpl method invalidate.

private void invalidate(List<KeyAndVersion> list, Address member) {
    Object[] keys = new Object[list.size()];
    int[] topologyIds = new int[list.size()];
    long[] versions = new long[list.size()];
    int i = 0;
    for (KeyAndVersion pair : list) {
        keys[i] = pair.key;
        SimpleClusteredVersion version = (SimpleClusteredVersion) pair.version;
        topologyIds[i] = version.getTopologyId();
        versions[i] = version.getVersion();
        ++i;
    }
    // Theoretically we can just send these invalidations asynchronously, but we'd prefer to have old copies
    // removed when state transfer completes.
    long incrementedCounter = chunkCounter.incrementAndGet();
    if (log.isTraceEnabled())
        log.tracef("Invalidating versions on %s, chunk counter incremented to %d", member, incrementedCounter);
    InvalidateVersionsCommand ivc = commandsFactory.buildInvalidateVersionsCommand(cacheTopology.getTopologyId(), keys, topologyIds, versions, true);
    rpcManager.invokeCommand(member, ivc, SingleResponseCollector.validOnly(), rpcManager.getSyncRpcOptions()).whenComplete((response, t) -> {
        if (t != null) {
            log.failedInvalidatingRemoteCache(t);
        }
        long decrementedCounter = chunkCounter.decrementAndGet();
        if (log.isTraceEnabled())
            log.tracef("Versions invalidated on %s, chunk counter decremented to %d", member, decrementedCounter);
        if (decrementedCounter == 0) {
            notifyEndOfStateTransferIfNeeded();
        }
    });
}
Also used : SimpleClusteredVersion(org.infinispan.container.versioning.SimpleClusteredVersion) InvalidateVersionsCommand(org.infinispan.commands.write.InvalidateVersionsCommand)

Aggregations

SimpleClusteredVersion (org.infinispan.container.versioning.SimpleClusteredVersion)6 CompletionStage (java.util.concurrent.CompletionStage)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 EntryVersion (org.infinispan.container.versioning.EntryVersion)2 MarshallableEntry (org.infinispan.persistence.spi.MarshallableEntry)2 CompletableFutures (org.infinispan.util.concurrent.CompletableFutures)2 Log (org.infinispan.util.logging.Log)2 LogFactory (org.infinispan.util.logging.LogFactory)2 Flowable (io.reactivex.rxjava3.core.Flowable)1 IOException (java.io.IOException)1 ObjectInput (java.io.ObjectInput)1 ObjectOutput (java.io.ObjectOutput)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors (java.util.stream.Collectors)1 VisitableCommand (org.infinispan.commands.VisitableCommand)1