use of org.infinispan.container.versioning.InequalVersionComparisonResult in project infinispan by infinispan.
the class ScatteredDistributionInterceptor method updateEntryIfNoChange.
private boolean updateEntryIfNoChange(RepeatableReadEntry entry) {
// We cannot delegate the dataContainer.compute() to entry.commit() as we need to reliably
// retrieve previous value and metadata, but the entry API does not provide these.
dataContainer.compute(entry.getKey(), (key, oldEntry, factory) -> {
// newMetadata is null in case of local-mode write on non-primary owners
Metadata newMetadata = entry.getMetadata();
if (oldEntry == null) {
if (entry.getOldValue() != null) {
if (log.isTraceEnabled()) {
log.trace("Non-null value in context, not committing");
}
throw new ConcurrentChangeException();
}
if (entry.getValue() == null && newMetadata == null) {
if (log.isTraceEnabled()) {
log.trace("No previous record and this is a removal, not committing anything.");
}
return null;
} else {
if (log.isTraceEnabled()) {
log.trace("Committing new entry " + entry);
}
entry.setCommitted();
return factory.create(entry);
}
}
Metadata oldMetadata = oldEntry.getMetadata();
EntryVersion oldVersion = oldMetadata == null ? null : oldMetadata.version();
Metadata seenMetadata = entry.getOldMetadata();
EntryVersion seenVersion = seenMetadata == null ? null : seenMetadata.version();
if (oldVersion == null) {
if (seenVersion != null) {
if (log.isTraceEnabled()) {
log.tracef("Current version is null but seen version is %s, throwing", seenVersion);
}
throw new ConcurrentChangeException();
}
} else if (seenVersion == null) {
if (oldEntry.canExpire() && oldEntry.isExpired(timeService.wallClockTime())) {
if (log.isTraceEnabled()) {
log.trace("Current entry is expired and therefore we haven't seen it");
}
} else {
if (log.isTraceEnabled()) {
log.tracef("Current version is %s but seen version is null, throwing", oldVersion);
}
throw new ConcurrentChangeException();
}
} else if (seenVersion.compareTo(oldVersion) != InequalVersionComparisonResult.EQUAL) {
if (log.isTraceEnabled()) {
log.tracef("Current version is %s but seen version is %s, throwing", oldVersion, seenVersion);
}
throw new ConcurrentChangeException();
}
InequalVersionComparisonResult comparisonResult;
if (oldVersion == null || newMetadata == null || newMetadata.version() == null || (comparisonResult = oldMetadata.version().compareTo(newMetadata.version())) == InequalVersionComparisonResult.BEFORE || (oldMetadata instanceof RemoteMetadata && comparisonResult == InequalVersionComparisonResult.EQUAL)) {
if (log.isTraceEnabled()) {
log.tracef("Committing entry %s, replaced %s", entry, oldEntry);
}
entry.setCommitted();
if (entry.getValue() != null || newMetadata != null) {
return factory.create(entry);
} else {
return null;
}
} else {
if (log.isTraceEnabled()) {
log.tracef("Not committing %s, current entry is %s", entry, oldEntry);
}
return oldEntry;
}
});
return entry.isCommitted();
}
use of org.infinispan.container.versioning.InequalVersionComparisonResult in project infinispan by infinispan.
the class ScatteredDistributionInterceptor method updateEntryIfNewer.
private boolean updateEntryIfNewer(RepeatableReadEntry entry) {
// We cannot delegate the dataContainer.compute() to entry.commit() as we need to reliably
// retrieve previous value and metadata, but the entry API does not provide these.
dataContainer.compute(entry.getKey(), (key, oldEntry, factory) -> {
// newMetadata is null in case of local-mode write
Metadata newMetadata = entry.getMetadata();
if (oldEntry == null) {
if (entry.getValue() == null && newMetadata == null) {
if (log.isTraceEnabled()) {
log.trace("No previous record and this is a removal, not committing anything.");
}
return null;
} else {
if (log.isTraceEnabled()) {
log.trace("Committing new entry " + entry);
}
entry.setCommitted();
return factory.create(entry);
}
}
Metadata oldMetadata = oldEntry.getMetadata();
InequalVersionComparisonResult comparisonResult;
if (oldMetadata == null || oldMetadata.version() == null || newMetadata == null || newMetadata.version() == null || (comparisonResult = oldMetadata.version().compareTo(newMetadata.version())) == InequalVersionComparisonResult.BEFORE || (oldMetadata instanceof RemoteMetadata && comparisonResult == InequalVersionComparisonResult.EQUAL)) {
if (log.isTraceEnabled()) {
log.tracef("Committing entry %s, replaced %s", entry, oldEntry);
}
entry.setCommitted();
if (entry.getValue() != null || newMetadata != null) {
return factory.create(entry);
} else {
return null;
}
} else {
if (log.isTraceEnabled()) {
log.tracef("Not committing %s, current entry is %s", entry, oldEntry);
}
return oldEntry;
}
});
return entry.isCommitted();
}
use of org.infinispan.container.versioning.InequalVersionComparisonResult 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);
}
}
use of org.infinispan.container.versioning.InequalVersionComparisonResult in project infinispan by infinispan.
the class IracRestartWithGlobalStateTest method assertVersions.
private static <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);
}
}
use of org.infinispan.container.versioning.InequalVersionComparisonResult in project infinispan by infinispan.
the class InvalidateVersionsCommand method invokeAsync.
@Override
public CompletionStage<?> invokeAsync(ComponentRegistry componentRegistry) {
StateTransferLock stateTransferLock = componentRegistry.getStateTransferLock();
if (stateTransferLock != null) {
stateTransferLock.acquireSharedTopologyLock();
}
try {
DistributionManager distributionManager = componentRegistry.getDistributionManager();
if (topologyId >= 0 && distributionManager != null) {
int currentTopologyId = distributionManager.getCacheTopology().getTopologyId();
if (topologyId > currentTopologyId) {
if (log.isTraceEnabled()) {
log.tracef("Delaying command %s, current topology id %d", this, currentTopologyId);
}
return stateTransferLock.topologyFuture(topologyId).thenCompose(nil -> invokeAsync(componentRegistry));
} else if (topologyId < currentTopologyId) {
log.ignoringInvalidateVersionsFromOldTopology(this.topologyId, currentTopologyId);
if (log.isTraceEnabled()) {
log.tracef("Ignored command is %s", this);
}
return CompletableFutures.completedNull();
}
}
for (int i = 0; i < keys.length; ++i) {
Object key = keys[i];
if (key == null)
break;
SimpleClusteredVersion version = new SimpleClusteredVersion(topologyIds[i], versions[i]);
BiasManager biasManager = componentRegistry.getBiasManager().running();
if (biasManager != null) {
biasManager.revokeLocalBias(key);
}
DataContainer dataContainer = componentRegistry.getInternalDataContainer().running();
dataContainer.compute(key, (k, oldEntry, factory) -> {
if (oldEntry == null) {
return null;
}
SimpleClusteredVersion localVersion = (SimpleClusteredVersion) oldEntry.getMetadata().version();
InequalVersionComparisonResult result = localVersion.compareTo(version);
if (result == InequalVersionComparisonResult.BEFORE || (removed && result == InequalVersionComparisonResult.EQUAL)) {
return null;
} else {
return oldEntry;
}
});
}
} finally {
if (stateTransferLock != null) {
stateTransferLock.releaseSharedTopologyLock();
}
}
OrderedUpdatesManager orderedUpdatesManager = componentRegistry.getOrderedUpdatesManager().running();
return orderedUpdatesManager.invalidate(keys).thenApply(nil -> null).toCompletableFuture();
}
Aggregations