Search in sources :

Example 1 with BackupAwareOperation

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;
}
Also used : Backup(com.hazelcast.spi.impl.operationservice.impl.operations.Backup) Data(com.hazelcast.internal.serialization.Data) BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 2 with BackupAwareOperation

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);
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) PartitionReplicaVersionManager(com.hazelcast.internal.partition.PartitionReplicaVersionManager)

Example 3 with BackupAwareOperation

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!";
    }
}
Also used : ServiceNamespaceAware(com.hazelcast.internal.services.ServiceNamespaceAware) BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) FragmentedMigrationAwareService(com.hazelcast.internal.partition.FragmentedMigrationAwareService)

Example 4 with BackupAwareOperation

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;
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) Backup(com.hazelcast.spi.impl.operationservice.impl.operations.Backup) TargetAware(com.hazelcast.spi.impl.operationservice.TargetAware) BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 5 with BackupAwareOperation

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);
    }
}
Also used : BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

BackupAwareOperation (com.hazelcast.spi.impl.operationservice.BackupAwareOperation)13 Operation (com.hazelcast.spi.impl.operationservice.Operation)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 Backup (com.hazelcast.spi.impl.operationservice.impl.operations.Backup)3 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)2 Data (com.hazelcast.internal.serialization.Data)2 TargetAware (com.hazelcast.spi.impl.operationservice.TargetAware)2 FragmentedMigrationAwareService (com.hazelcast.internal.partition.FragmentedMigrationAwareService)1 PartitionReplicaVersionManager (com.hazelcast.internal.partition.PartitionReplicaVersionManager)1 ServiceNamespace (com.hazelcast.internal.services.ServiceNamespace)1 ServiceNamespaceAware (com.hazelcast.internal.services.ServiceNamespaceAware)1