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; } // Since there is only one backup, backup operation is sent to only one node. // If backup operation is converted to `Data`, there will be these operations as below: // - a temporary memory allocation (byte[]) for `Data` // - serialize backup operation to allocated memory // - copy the temporary allocated memory (backup operation data) to output while serializing `Backup` // In this flow, there are two redundant operations (allocating temporary memory and copying it to output). // So in this case (there is only one backup), we don't convert backup operation to `Data` as temporary // before `Backup` is serialized but backup operation is already serialized directly into output // 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; }
if (skipSendingBackupToTarget(partition, target)) { continue;