use of com.hazelcast.spi.impl.operationservice.BackupAwareOperation in project hazelcast by hazelcast.
the class OperationBackupHandler method newBackup.
private static Backup newBackup(BackupAwareOperation backupAwareOp, Object backupOp, long[] replicaVersions, int replicaIndex, boolean respondBack) {
Operation op = (Operation) backupAwareOp;
Backup backup;
if (backupOp instanceof Operation) {
backup = new Backup((Operation) backupOp, op.getCallerAddress(), replicaVersions, respondBack, op.getClientCallId());
} else if (backupOp instanceof Data) {
backup = new Backup((Data) backupOp, op.getCallerAddress(), replicaVersions, respondBack, op.getClientCallId());
} else {
throw new IllegalArgumentException("Only 'Data' or 'Operation' typed backup operation is supported!");
}
backup.setPartitionId(op.getPartitionId()).setReplicaIndex(replicaIndex).setCallerUuid(op.getCallerUuid());
if (hasActiveInvocation(op)) {
setCallId(backup, op.getCallId());
}
return backup;
}
use of com.hazelcast.spi.impl.operationservice.BackupAwareOperation in project hazelcast by hazelcast.
the class OperationBackupHandler method sendBackups0.
int sendBackups0(BackupAwareOperation backupAwareOp) {
int requestedSyncBackups = requestedSyncBackups(backupAwareOp);
int requestedAsyncBackups = requestedAsyncBackups(backupAwareOp);
int requestedTotalBackups = requestedTotalBackups(backupAwareOp);
if (requestedTotalBackups == 0) {
return 0;
}
Operation op = (Operation) backupAwareOp;
PartitionReplicaVersionManager versionManager = node.getPartitionService().getPartitionReplicaVersionManager();
ServiceNamespace namespace = versionManager.getServiceNamespace(op);
long[] replicaVersions = versionManager.incrementPartitionReplicaVersions(op.getPartitionId(), namespace, requestedTotalBackups);
boolean syncForced = backpressureRegulator.isSyncForced(backupAwareOp);
int syncBackups = syncBackups(requestedSyncBackups, requestedAsyncBackups, syncForced);
int asyncBackups = asyncBackups(requestedSyncBackups, requestedAsyncBackups, syncForced);
// TODO: This could cause a problem with back pressure
if (!op.returnsResponse()) {
asyncBackups += syncBackups;
syncBackups = 0;
}
if (syncBackups + asyncBackups == 0) {
return 0;
}
return makeBackups(backupAwareOp, op.getPartitionId(), replicaVersions, syncBackups, asyncBackups);
}
use of com.hazelcast.spi.impl.operationservice.BackupAwareOperation in project hazelcast by hazelcast.
the class OperationBackupHandler method checkServiceNamespaces.
private void checkServiceNamespaces(BackupAwareOperation backupAwareOp, Operation backupOp) {
Operation op = (Operation) backupAwareOp;
Object service;
try {
service = op.getService();
} catch (Exception ignored) {
// operation doesn't know its service name
return;
}
if (service instanceof FragmentedMigrationAwareService) {
assert backupAwareOp instanceof ServiceNamespaceAware : service + " is instance of FragmentedMigrationAwareService, " + backupAwareOp + " should implement ServiceNamespaceAware!";
assert backupOp instanceof ServiceNamespaceAware : service + " is instance of FragmentedMigrationAwareService, " + backupOp + " should implement ServiceNamespaceAware!";
} else {
assert !(backupAwareOp instanceof ServiceNamespaceAware) : service + " is NOT instance of FragmentedMigrationAwareService, " + backupAwareOp + " should NOT implement ServiceNamespaceAware!";
assert !(backupOp instanceof ServiceNamespaceAware) : service + " is NOT instance of FragmentedMigrationAwareService, " + backupOp + " should NOT implement ServiceNamespaceAware!";
}
}
use of com.hazelcast.spi.impl.operationservice.BackupAwareOperation in project hazelcast by hazelcast.
the class OperationBackupHandler method sendSingleBackup.
private int sendSingleBackup(BackupAwareOperation backupAwareOp, InternalPartition partition, long[] replicaVersions, int syncBackups, int replica) {
Operation backupOp = getBackupOperation(backupAwareOp);
PartitionReplica target = partition.getReplica(replica);
if (target != null) {
if (skipSendingBackupToTarget(partition, target)) {
return 0;
}
// without any unnecessary memory allocation and copy when it is used as object inside `Backup`.
if (backupOp instanceof TargetAware) {
((TargetAware) backupOp).setTarget(target.address());
}
boolean isSyncBackup = syncBackups == 1;
Backup backup = newBackup(backupAwareOp, backupOp, replicaVersions, 1, isSyncBackup);
outboundOperationHandler.send(backup, target.address());
if (isSyncBackup) {
return 1;
}
}
return 0;
}
use of com.hazelcast.spi.impl.operationservice.BackupAwareOperation in project hazelcast by hazelcast.
the class BackpressureRegulatorTest method isSyncForced_whenPartitionSpecific.
@Test
public void isSyncForced_whenPartitionSpecific() {
BackpressureRegulator regulator = newEnabledBackPressureService();
BackupAwareOperation op = new PartitionSpecificOperation(10);
for (int iteration = 0; iteration < 10; iteration++) {
int initialSyncDelay = regulator.syncCountDown();
int remainingSyncDelay = initialSyncDelay - 1;
for (int k = 0; k < initialSyncDelay - 1; k++) {
boolean result = regulator.isSyncForced(op);
assertFalse("no sync force expected", result);
int syncDelay = regulator.syncCountDown();
assertEquals(remainingSyncDelay, syncDelay);
remainingSyncDelay--;
}
boolean result = regulator.isSyncForced(op);
assertTrue("sync force expected", result);
int syncDelay = regulator.syncCountDown();
assertValidSyncDelay(syncDelay);
}
}
Aggregations