use of org.infinispan.commands.irac.IracTombstonePrimaryCheckCommand in project infinispan by infinispan.
the class DefaultIracTombstoneManager method performCleanup.
private CompletionStage<Void> performCleanup() {
if (stopped) {
return CompletableFutures.completedNull();
}
scheduler.onTaskStarted(tombstoneMap.size());
try {
AggregateCompletionStage<Void> stage = CompletionStages.aggregateCompletionStage();
RpcOptions rpcOptions = rpcManager.getSyncRpcOptions();
Map<Address, BackPressure<IracTombstonePrimaryCheckCommand, Void>> staleTombstones = new HashMap<>(tombstoneMap.size());
for (IracTombstoneInfo tombstone : tombstoneMap.values()) {
DistributionInfo info = distributionManager.getCacheTopology().getSegmentDistribution(tombstone.getSegment());
if (!info.isWriteOwner()) {
// topology changed, no longer an owner
removeTombstone(tombstone);
continue;
}
// it means the primary owner hasn't sent the update to the remote site.
if (iracManager.running().containsKey(tombstone.getKey())) {
continue;
}
if (!info.isPrimary()) {
BackPressure<IracTombstonePrimaryCheckCommand, Void> backPressure = staleTombstones.get(info.primary());
if (backPressure == null) {
backPressure = new BackPressure<>(commandsFactory.buildIracTombstonePrimaryCheckCommand(batchSize), null);
staleTombstones.put(info.primary(), backPressure);
}
if (backPressure.element.addTombstone(tombstone) == batchSize) {
CompletionStage<Void> rsp;
if (backPressure.delay == null) {
rsp = rpcManager.invokeCommand(info.primary(), backPressure.element, ignoreLeavers(), rpcOptions);
} else {
ReplicableCommand rCmd = backPressure.element;
rsp = backPressure.delay.thenComposeAsync(unused -> rpcManager.invokeCommand(info.primary(), rCmd, ignoreLeavers(), rpcOptions), blockingExecutor);
}
staleTombstones.put(info.primary(), new BackPressure<>(commandsFactory.buildIracTombstonePrimaryCheckCommand(batchSize), rsp));
}
continue;
}
stage.dependsOn(new CleanupTask(tombstone).checkRemoteSites());
}
// sending any pending stale tombstones
for (Map.Entry<Address, BackPressure<IracTombstonePrimaryCheckCommand, Void>> entry : staleTombstones.entrySet()) {
BackPressure<IracTombstonePrimaryCheckCommand, Void> backPressure = entry.getValue();
if (backPressure.element.isEmpty()) {
continue;
}
if (backPressure.delay == null) {
rpcManager.sendTo(entry.getKey(), backPressure.element, DeliverOrder.NONE);
} else {
backPressure.delay.thenRunAsync(() -> rpcManager.sendTo(entry.getKey(), backPressure.element, DeliverOrder.NONE), blockingExecutor);
}
}
return stage.freeze().whenComplete(scheduler);
} catch (Throwable t) {
log.debug("Unexpected exception", t);
scheduler.scheduleWithCurrentDelay();
return CompletableFutures.completedNull();
}
}
use of org.infinispan.commands.irac.IracTombstonePrimaryCheckCommand in project infinispan by infinispan.
the class IracTombstoneCleanupTest method testBackupOwnerRoundCleanupDoNotCleanupPrimary.
public void testBackupOwnerRoundCleanupDoNotCleanupPrimary(Method method) {
String key = k(method);
int segment = getSegment(key);
Cache<String, String> pCache = findPrimaryOwner(segment);
Cache<String, String> bCache = findBackupOwner(segment);
IracMetadata metadata = dummyMetadata(2);
tombstoneManager(pCache).storeTombstone(segment, key, metadata);
tombstoneManager(bCache).storeTombstone(segment, key, metadata);
assertEquals(1, tombstoneManager(pCache).size());
assertEquals(1, tombstoneManager(bCache).size());
RecordingRpcManager pRpcManager = recordingRpcManager(pCache);
RecordingRpcManager bRpcManager = recordingRpcManager(bCache);
pRpcManager.startRecording();
bRpcManager.startRecording();
tombstoneManager(bCache).runCleanupAndWait();
IracTombstonePrimaryCheckCommand cmd = bRpcManager.findSingleCommand(IracTombstonePrimaryCheckCommand.class);
assertNotNull(cmd);
assertEquals(1, cmd.getTombstoneToCheck().size());
IracTombstoneInfo tombstoneInfo = cmd.getTombstoneToCheck().iterator().next();
assertEquals(segment, tombstoneInfo.getSegment());
assertEquals(key, tombstoneInfo.getKey());
assertEquals(metadata, tombstoneInfo.getMetadata());
assertFalse(pRpcManager.isCommandSent(IracTombstoneCleanupCommand.class));
// check if nothing is removed... should we sleep here?
assertEquals(1, tombstoneManager(pCache).size());
assertEquals(1, tombstoneManager(bCache).size());
// remove tombstone to avoid messing up with other tests
tombstoneManager(pCache).removeTombstone(key);
tombstoneManager(bCache).removeTombstone(key);
}
Aggregations