Search in sources :

Example 1 with SafeStateCheckOperation

use of com.hazelcast.internal.partition.operation.SafeStateCheckOperation in project hazelcast by hazelcast.

the class PartitionDataSerializerHook method createFactory.

@Override
public DataSerializableFactory createFactory() {
    ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructors = new ConstructorFunction[LEN];
    constructors[PARTITION_RUNTIME_STATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new PartitionRuntimeState();
        }
    };
    constructors[ASSIGN_PARTITIONS] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new AssignPartitions();
        }
    };
    constructors[CHECK_REPLICA_VERSION] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new CheckReplicaVersion();
        }
    };
    constructors[FETCH_PARTITION_STATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new FetchPartitionStateOperation();
        }
    };
    constructors[HAS_ONGOING_MIGRATION] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new HasOngoingMigration();
        }
    };
    constructors[MIGRATION_COMMIT] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new MigrationCommitOperation();
        }
    };
    constructors[MIGRATION] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new MigrationOperation();
        }
    };
    constructors[MIGRATION_REQUEST] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new MigrationRequestOperation();
        }
    };
    constructors[PARTITION_STATE_OP] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new PartitionStateOperation();
        }
    };
    constructors[PROMOTION_COMMIT] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new PromotionCommitOperation();
        }
    };
    constructors[REPLICA_SYNC_REQUEST] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new ReplicaSyncRequest();
        }
    };
    constructors[REPLICA_SYNC_RESPONSE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new ReplicaSyncResponse();
        }
    };
    constructors[REPLICA_SYNC_RETRY_RESPONSE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new ReplicaSyncRetryResponse();
        }
    };
    constructors[SAFE_STATE_CHECK] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new SafeStateCheckOperation();
        }
    };
    constructors[SHUTDOWN_REQUEST] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new ShutdownRequestOperation();
        }
    };
    constructors[SHUTDOWN_RESPONSE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new ShutdownResponseOperation();
        }
    };
    return new ArrayDataSerializableFactory(constructors);
}
Also used : IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) HasOngoingMigration(com.hazelcast.internal.partition.operation.HasOngoingMigration) ShutdownResponseOperation(com.hazelcast.internal.partition.operation.ShutdownResponseOperation) MigrationOperation(com.hazelcast.internal.partition.operation.MigrationOperation) MigrationRequestOperation(com.hazelcast.internal.partition.operation.MigrationRequestOperation) AssignPartitions(com.hazelcast.internal.partition.operation.AssignPartitions) CheckReplicaVersion(com.hazelcast.internal.partition.operation.CheckReplicaVersion) FetchPartitionStateOperation(com.hazelcast.internal.partition.operation.FetchPartitionStateOperation) PartitionStateOperation(com.hazelcast.internal.partition.operation.PartitionStateOperation) ConstructorFunction(com.hazelcast.util.ConstructorFunction) ReplicaSyncRequest(com.hazelcast.internal.partition.operation.ReplicaSyncRequest) MigrationCommitOperation(com.hazelcast.internal.partition.operation.MigrationCommitOperation) PromotionCommitOperation(com.hazelcast.internal.partition.operation.PromotionCommitOperation) ReplicaSyncRetryResponse(com.hazelcast.internal.partition.operation.ReplicaSyncRetryResponse) SafeStateCheckOperation(com.hazelcast.internal.partition.operation.SafeStateCheckOperation) PartitionRuntimeState(com.hazelcast.internal.partition.PartitionRuntimeState) ReplicaSyncResponse(com.hazelcast.internal.partition.operation.ReplicaSyncResponse) ArrayDataSerializableFactory(com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory) ShutdownRequestOperation(com.hazelcast.internal.partition.operation.ShutdownRequestOperation) FetchPartitionStateOperation(com.hazelcast.internal.partition.operation.FetchPartitionStateOperation)

Example 2 with SafeStateCheckOperation

use of com.hazelcast.internal.partition.operation.SafeStateCheckOperation in project hazelcast by hazelcast.

the class PartitionServiceProxy method isClusterSafe.

@Override
public boolean isClusterSafe() {
    Collection<Member> members = nodeEngine.getClusterService().getMembers();
    if (members == null || members.isEmpty()) {
        return true;
    }
    final Collection<Future<Boolean>> futures = new ArrayList<Future<Boolean>>(members.size());
    for (Member member : members) {
        final Address target = member.getAddress();
        final Operation operation = new SafeStateCheckOperation();
        final Future<Boolean> future = nodeEngine.getOperationService().invokeOnTarget(InternalPartitionService.SERVICE_NAME, operation, target);
        futures.add(future);
    }
    // todo this max wait is appropriate?
    final int maxWaitTime = getMaxWaitTime();
    Collection<Boolean> results = FutureUtil.returnWithDeadline(futures, maxWaitTime, TimeUnit.SECONDS, exceptionHandler);
    if (results.size() != futures.size()) {
        return false;
    }
    for (Boolean result : results) {
        if (!result) {
            return false;
        }
    }
    return true;
}
Also used : Address(com.hazelcast.nio.Address) SafeStateCheckOperation(com.hazelcast.internal.partition.operation.SafeStateCheckOperation) ArrayList(java.util.ArrayList) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Future(java.util.concurrent.Future) Operation(com.hazelcast.spi.Operation) SafeStateCheckOperation(com.hazelcast.internal.partition.operation.SafeStateCheckOperation) Member(com.hazelcast.core.Member)

Example 3 with SafeStateCheckOperation

use of com.hazelcast.internal.partition.operation.SafeStateCheckOperation in project hazelcast by hazelcast.

the class PartitionServiceProxy method isMemberSafe.

@Override
public boolean isMemberSafe(Member member) {
    if (member == null) {
        throw new NullPointerException("Parameter member should not be null");
    }
    final Member localMember = nodeEngine.getLocalMember();
    if (localMember.equals(member)) {
        return isLocalMemberSafe();
    }
    final Address target = member.getAddress();
    final Operation operation = new SafeStateCheckOperation();
    final InternalCompletableFuture future = nodeEngine.getOperationService().invokeOnTarget(InternalPartitionService.SERVICE_NAME, operation, target);
    boolean safe;
    try {
        final Object result = future.get(10, TimeUnit.SECONDS);
        safe = (Boolean) result;
    } catch (Throwable t) {
        safe = false;
        logger.warning("Error while querying member's safe state [" + member + "]", t);
    }
    return safe;
}
Also used : Address(com.hazelcast.nio.Address) SafeStateCheckOperation(com.hazelcast.internal.partition.operation.SafeStateCheckOperation) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Operation(com.hazelcast.spi.Operation) SafeStateCheckOperation(com.hazelcast.internal.partition.operation.SafeStateCheckOperation) Member(com.hazelcast.core.Member)

Aggregations

SafeStateCheckOperation (com.hazelcast.internal.partition.operation.SafeStateCheckOperation)3 Member (com.hazelcast.core.Member)2 Address (com.hazelcast.nio.Address)2 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)2 Operation (com.hazelcast.spi.Operation)2 PartitionRuntimeState (com.hazelcast.internal.partition.PartitionRuntimeState)1 AssignPartitions (com.hazelcast.internal.partition.operation.AssignPartitions)1 CheckReplicaVersion (com.hazelcast.internal.partition.operation.CheckReplicaVersion)1 FetchPartitionStateOperation (com.hazelcast.internal.partition.operation.FetchPartitionStateOperation)1 HasOngoingMigration (com.hazelcast.internal.partition.operation.HasOngoingMigration)1 MigrationCommitOperation (com.hazelcast.internal.partition.operation.MigrationCommitOperation)1 MigrationOperation (com.hazelcast.internal.partition.operation.MigrationOperation)1 MigrationRequestOperation (com.hazelcast.internal.partition.operation.MigrationRequestOperation)1 PartitionStateOperation (com.hazelcast.internal.partition.operation.PartitionStateOperation)1 PromotionCommitOperation (com.hazelcast.internal.partition.operation.PromotionCommitOperation)1 ReplicaSyncRequest (com.hazelcast.internal.partition.operation.ReplicaSyncRequest)1 ReplicaSyncResponse (com.hazelcast.internal.partition.operation.ReplicaSyncResponse)1 ReplicaSyncRetryResponse (com.hazelcast.internal.partition.operation.ReplicaSyncRetryResponse)1 ShutdownRequestOperation (com.hazelcast.internal.partition.operation.ShutdownRequestOperation)1 ShutdownResponseOperation (com.hazelcast.internal.partition.operation.ShutdownResponseOperation)1