Search in sources :

Example 1 with InvalidateVersionsCommand

use of org.infinispan.commands.write.InvalidateVersionsCommand in project infinispan by infinispan.

the class ScatteredVersionManagerImpl method tryRegularInvalidations.

private void tryRegularInvalidations(boolean force) {
    ConcurrentMap<K, InvalidationInfo> scheduledKeys;
    long stamp = scheduledKeysLock.writeLock();
    try {
        scheduledKeys = this.scheduledKeys;
        this.scheduledKeys = new ConcurrentHashMap<>(invalidationBatchSize);
    } finally {
        scheduledKeysLock.unlockWrite(stamp);
    }
    // we'll invalidate all keys in one run
    // we don't have to keep any topology lock, because the versions increase monotonically
    int numKeys = scheduledKeys.size();
    Object[] keys = new Object[numKeys];
    int[] topologyIds = new int[numKeys];
    long[] versions = new long[numKeys];
    boolean[] isRemoved = new boolean[numKeys];
    int numRemoved = 0;
    int i = 0;
    for (Map.Entry<K, InvalidationInfo> entry : scheduledKeys.entrySet()) {
        keys[i] = entry.getKey();
        topologyIds[i] = entry.getValue().topologyId;
        versions[i] = entry.getValue().version;
        if (isRemoved[i] = entry.getValue().removal) {
            // intentional assignment
            numRemoved++;
        }
        ++i;
    }
    InvalidateVersionsCommand command = commandsFactory.buildInvalidateVersionsCommand(-1, keys, topologyIds, versions, false);
    sendRegularInvalidations(command, keys, topologyIds, versions, numRemoved, isRemoved, force);
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InvalidateVersionsCommand(org.infinispan.commands.write.InvalidateVersionsCommand)

Example 2 with InvalidateVersionsCommand

use of org.infinispan.commands.write.InvalidateVersionsCommand in project infinispan by infinispan.

the class ScatteredVersionManagerImpl method tryRemovedInvalidations.

private void tryRemovedInvalidations() {
    final ConcurrentMap<K, InvalidationInfo> removedKeys;
    long stamp = removedKeysLock.writeLock();
    try {
        removedKeys = this.removedKeys;
        this.removedKeys = new ConcurrentHashMap<>(invalidationBatchSize);
    } finally {
        removedKeysLock.unlockWrite(stamp);
    }
    int numKeys = removedKeys.size();
    Object[] keys = new Object[numKeys];
    int[] topologyIds = new int[numKeys];
    long[] versions = new long[numKeys];
    int i = 0;
    for (Map.Entry<K, InvalidationInfo> entry : removedKeys.entrySet()) {
        keys[i] = entry.getKey();
        topologyIds[i] = entry.getValue().topologyId;
        versions[i] = entry.getValue().version;
    }
    InvalidateVersionsCommand removeCommand = commandsFactory.buildInvalidateVersionsCommand(-1, keys, topologyIds, versions, true);
    sendRemoveInvalidations(removeCommand);
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InvalidateVersionsCommand(org.infinispan.commands.write.InvalidateVersionsCommand)

Example 3 with InvalidateVersionsCommand

use of org.infinispan.commands.write.InvalidateVersionsCommand 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

InvalidateVersionsCommand (org.infinispan.commands.write.InvalidateVersionsCommand)3 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 SimpleClusteredVersion (org.infinispan.container.versioning.SimpleClusteredVersion)1