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);
}
}
});
}
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);
}
}
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();
}
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;
}
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();
}
});
}
Aggregations