}
private int sendBackups(BackupAwareOperation backupAwareOp) throws Exception {
Operation op = (Operation) backupAwareOp;
boolean returnsResponse = op.returnsResponse();
InternalPartitionService partitionService = nodeEngine.getPartitionService();
int maxBackupCount = InternalPartition.MAX_BACKUP_COUNT;
int maxPossibleBackupCount = Math.min(partitionService.getMemberGroupsSize() - 1, maxBackupCount);
int requestedSyncBackupCount = backupAwareOp.getSyncBackupCount() > 0
? Math.min(maxBackupCount, backupAwareOp.getSyncBackupCount()) : 0;
int requestedAsyncBackupCount = backupAwareOp.getAsyncBackupCount() > 0
? Math.min(maxBackupCount - requestedSyncBackupCount, backupAwareOp.getAsyncBackupCount()) : 0;
int totalRequestedBackupCount = requestedSyncBackupCount + requestedAsyncBackupCount;
if (totalRequestedBackupCount == 0) {
return 0;
}
int partitionId = op.getPartitionId();
long[] replicaVersions = partitionService.incrementPartitionReplicaVersions(partitionId, totalRequestedBackupCount);
int syncBackupCount = Math.min(maxPossibleBackupCount, requestedSyncBackupCount);
int asyncBackupCount = Math.min(maxPossibleBackupCount - syncBackupCount, requestedAsyncBackupCount);
if (!returnsResponse) {
asyncBackupCount += syncBackupCount;
syncBackupCount = 0;
}
int totalBackupCount = syncBackupCount + asyncBackupCount;
if (totalBackupCount == 0) {
return 0;
}
int sentSyncBackupCount = 0;
String serviceName = op.getServiceName();
InternalPartition partition = partitionService.getPartition(partitionId);
for (int replicaIndex = 1; replicaIndex <= totalBackupCount; replicaIndex++) {
Address target = partition.getReplicaAddress(replicaIndex);
if (target != null) {
if (target.equals(node.getThisAddress())) {