Search in sources :

Example 1 with VectorClock

use of com.hazelcast.cluster.impl.VectorClock in project hazelcast by hazelcast.

the class ClusterDataSerializerHook method createFactory.

@Override
public DataSerializableFactory createFactory() {
    ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructors = new ConstructorFunction[LEN];
    constructors[AUTH_FAILURE] = arg -> new AuthenticationFailureOp();
    constructors[ADDRESS] = arg -> new Address();
    constructors[MEMBER] = arg -> new MemberImpl();
    constructors[HEARTBEAT] = arg -> new HeartbeatOp();
    constructors[CONFIG_CHECK] = arg -> new ConfigCheck();
    constructors[MEMBER_HANDSHAKE] = arg -> new MemberHandshake();
    constructors[MEMBER_INFO_UPDATE] = arg -> new MembersUpdateOp();
    constructors[FINALIZE_JOIN] = arg -> new FinalizeJoinOp();
    constructors[BEFORE_JOIN_CHECK_FAILURE] = arg -> new BeforeJoinCheckFailureOp();
    constructors[CHANGE_CLUSTER_STATE] = arg -> new CommitClusterStateOp();
    constructors[CONFIG_MISMATCH] = arg -> new ConfigMismatchOp();
    constructors[CLUSTER_MISMATCH] = arg -> new ClusterMismatchOp();
    constructors[SPLIT_BRAIN_MERGE_VALIDATION] = arg -> new SplitBrainMergeValidationOp();
    constructors[JOIN_REQUEST_OP] = arg -> new JoinRequestOp();
    constructors[LOCK_CLUSTER_STATE] = arg -> new LockClusterStateOp();
    constructors[MASTER_CLAIM] = arg -> new JoinMastershipClaimOp();
    constructors[WHOIS_MASTER] = arg -> new WhoisMasterOp();
    constructors[MERGE_CLUSTERS] = arg -> new MergeClustersOp();
    constructors[POST_JOIN] = arg -> new OnJoinOp();
    constructors[ROLLBACK_CLUSTER_STATE] = arg -> new RollbackClusterStateOp();
    constructors[MASTER_RESPONSE] = arg -> new MasterResponseOp();
    constructors[SHUTDOWN_NODE] = arg -> new ShutdownNodeOp();
    constructors[TRIGGER_MEMBER_LIST_PUBLISH] = arg -> new TriggerMemberListPublishOp();
    constructors[CLUSTER_STATE_TRANSACTION_LOG_RECORD] = arg -> new ClusterStateTransactionLogRecord();
    constructors[MEMBER_INFO] = arg -> new MemberInfo();
    constructors[JOIN_MESSAGE] = arg -> new JoinMessage();
    constructors[JOIN_REQUEST] = arg -> new JoinRequest();
    constructors[MIGRATION_INFO] = arg -> new MigrationInfo();
    constructors[MEMBER_VERSION] = arg -> new MemberVersion();
    constructors[CLUSTER_STATE_CHANGE] = arg -> new ClusterStateChange();
    constructors[SPLIT_BRAIN_JOIN_MESSAGE] = arg -> new SplitBrainJoinMessage();
    constructors[VERSION] = arg -> new Version();
    constructors[FETCH_MEMBER_LIST_STATE] = arg -> new FetchMembersViewOp();
    constructors[EXPLICIT_SUSPICION] = arg -> new ExplicitSuspicionOp();
    constructors[MEMBERS_VIEW] = arg -> new MembersView();
    constructors[TRIGGER_EXPLICIT_SUSPICION] = arg -> new TriggerExplicitSuspicionOp();
    constructors[MEMBERS_VIEW_METADATA] = arg -> new MembersViewMetadata();
    constructors[HEARTBEAT_COMPLAINT] = arg -> new HeartbeatComplaintOp();
    constructors[PROMOTE_LITE_MEMBER] = arg -> new PromoteLiteMemberOp();
    constructors[VECTOR_CLOCK] = arg -> new VectorClock();
    constructors[ENDPOINT_QUALIFIER] = arg -> new EndpointQualifier();
    return new ArrayDataSerializableFactory(constructors);
}
Also used : MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) MergeClustersOp(com.hazelcast.internal.cluster.impl.operations.MergeClustersOp) Address(com.hazelcast.cluster.Address) MembersUpdateOp(com.hazelcast.internal.cluster.impl.operations.MembersUpdateOp) SplitBrainMergeValidationOp(com.hazelcast.internal.cluster.impl.operations.SplitBrainMergeValidationOp) RollbackClusterStateOp(com.hazelcast.internal.cluster.impl.operations.RollbackClusterStateOp) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) TriggerMemberListPublishOp(com.hazelcast.internal.cluster.impl.operations.TriggerMemberListPublishOp) MemberVersion(com.hazelcast.version.MemberVersion) HeartbeatComplaintOp(com.hazelcast.internal.cluster.impl.operations.HeartbeatComplaintOp) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Version(com.hazelcast.version.Version) MemberVersion(com.hazelcast.version.MemberVersion) ShutdownNodeOp(com.hazelcast.internal.cluster.impl.operations.ShutdownNodeOp) HeartbeatOp(com.hazelcast.internal.cluster.impl.operations.HeartbeatOp) TriggerExplicitSuspicionOp(com.hazelcast.internal.cluster.impl.operations.TriggerExplicitSuspicionOp) BeforeJoinCheckFailureOp(com.hazelcast.internal.cluster.impl.operations.BeforeJoinCheckFailureOp) MasterResponseOp(com.hazelcast.internal.cluster.impl.operations.MasterResponseOp) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) LockClusterStateOp(com.hazelcast.internal.cluster.impl.operations.LockClusterStateOp) ExplicitSuspicionOp(com.hazelcast.internal.cluster.impl.operations.ExplicitSuspicionOp) TriggerExplicitSuspicionOp(com.hazelcast.internal.cluster.impl.operations.TriggerExplicitSuspicionOp) VectorClock(com.hazelcast.cluster.impl.VectorClock) AuthenticationFailureOp(com.hazelcast.internal.cluster.impl.operations.AuthenticationFailureOp) ClusterMismatchOp(com.hazelcast.internal.cluster.impl.operations.ClusterMismatchOp) PromoteLiteMemberOp(com.hazelcast.internal.cluster.impl.operations.PromoteLiteMemberOp) FinalizeJoinOp(com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOp) ConstructorFunction(com.hazelcast.internal.util.ConstructorFunction) ConfigMismatchOp(com.hazelcast.internal.cluster.impl.operations.ConfigMismatchOp) CommitClusterStateOp(com.hazelcast.internal.cluster.impl.operations.CommitClusterStateOp) WhoisMasterOp(com.hazelcast.internal.cluster.impl.operations.WhoisMasterOp) OnJoinOp(com.hazelcast.internal.cluster.impl.operations.OnJoinOp) JoinRequestOp(com.hazelcast.internal.cluster.impl.operations.JoinRequestOp) FetchMembersViewOp(com.hazelcast.internal.cluster.impl.operations.FetchMembersViewOp) ArrayDataSerializableFactory(com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory) JoinMastershipClaimOp(com.hazelcast.internal.cluster.impl.operations.JoinMastershipClaimOp)

Example 2 with VectorClock

use of com.hazelcast.cluster.impl.VectorClock in project hazelcast by hazelcast.

the class CRDTReplicationTask method replicate.

/**
 * Performs replication of a {@link CRDTReplicationAwareService} to the
 * given target. The service may optimise the returned operation based on
 * the target member and the previous successful replication operations.
 *
 * @param service the service to replicate
 * @param target  the target to replicate to
 * @see CRDTReplicationAwareService
 */
private void replicate(CRDTReplicationAwareService service, Member target) {
    if (Thread.currentThread().isInterrupted()) {
        return;
    }
    final int targetIndex = getDataMemberListIndex(target);
    final Map<String, VectorClock> lastSuccessfullyReplicatedClocks = replicationMigrationService.getReplicatedVectorClocks(service.getName(), target.getUuid());
    final OperationService operationService = nodeEngine.getOperationService();
    final CRDTReplicationContainer replicationOperation = service.prepareReplicationOperation(lastSuccessfullyReplicatedClocks, targetIndex);
    if (replicationOperation == null) {
        logger.finest("Skipping replication of " + service.getName() + " for target " + target);
        return;
    }
    try {
        logger.finest("Replicating " + service.getName() + " to " + target);
        operationService.invokeOnTarget(null, replicationOperation.getOperation(), target.getAddress()).joinInternal();
        replicationMigrationService.setReplicatedVectorClocks(service.getName(), target.getUuid(), replicationOperation.getVectorClocks());
    } catch (Exception e) {
        if (logger.isFineEnabled()) {
            logger.fine("Failed replication of " + service.getName() + " for target " + target, e);
        } else {
            logger.info("Failed replication of " + service.getName() + " for target " + target);
        }
    }
}
Also used : VectorClock(com.hazelcast.cluster.impl.VectorClock) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 3 with VectorClock

use of com.hazelcast.cluster.impl.VectorClock in project hazelcast by hazelcast.

the class PNCounterService method prepareMigrationOperation.

@Override
public CRDTReplicationContainer prepareMigrationOperation(int maxConfiguredReplicaCount) {
    final HashMap<String, VectorClock> currentVectorClocks = new HashMap<>();
    final HashMap<String, PNCounterImpl> counters = new HashMap<>();
    final Config config = nodeEngine.getConfig();
    for (Entry<String, PNCounterImpl> counterEntry : this.counters.entrySet()) {
        final String counterName = counterEntry.getKey();
        final PNCounterImpl counter = counterEntry.getValue();
        if (config.findPNCounterConfig(counterName).getReplicaCount() >= maxConfiguredReplicaCount) {
            continue;
        }
        counters.put(counterName, counter);
        currentVectorClocks.put(counterName, counter.getCurrentVectorClock());
    }
    return counters.isEmpty() ? null : new CRDTReplicationContainer(new PNCounterReplicationOperation(counters), currentVectorClocks);
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PNCounterConfig(com.hazelcast.config.PNCounterConfig) Config(com.hazelcast.config.Config) VectorClock(com.hazelcast.cluster.impl.VectorClock) CRDTReplicationContainer(com.hazelcast.internal.crdt.CRDTReplicationContainer)

Example 4 with VectorClock

use of com.hazelcast.cluster.impl.VectorClock in project hazelcast by hazelcast.

the class PNCounterService method prepareReplicationOperation.

@Override
public CRDTReplicationContainer prepareReplicationOperation(Map<String, VectorClock> previouslyReplicatedVectorClocks, int targetIndex) {
    final HashMap<String, VectorClock> currentVectorClocks = new HashMap<String, VectorClock>();
    final HashMap<String, PNCounterImpl> counters = new HashMap<String, PNCounterImpl>();
    final Config config = nodeEngine.getConfig();
    for (Entry<String, PNCounterImpl> counterEntry : this.counters.entrySet()) {
        final String counterName = counterEntry.getKey();
        final PNCounterImpl counter = counterEntry.getValue();
        if (targetIndex >= config.findPNCounterConfig(counterName).getReplicaCount()) {
            continue;
        }
        final VectorClock counterCurrentVectorClock = counter.getCurrentVectorClock();
        final VectorClock counterPreviousVectorClock = previouslyReplicatedVectorClocks.get(counterName);
        if (counterPreviousVectorClock == null || counterCurrentVectorClock.isAfter(counterPreviousVectorClock)) {
            counters.put(counterName, counter);
        }
        currentVectorClocks.put(counterName, counterCurrentVectorClock);
    }
    return counters.isEmpty() ? null : new CRDTReplicationContainer(new PNCounterReplicationOperation(counters), currentVectorClocks);
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PNCounterConfig(com.hazelcast.config.PNCounterConfig) Config(com.hazelcast.config.Config) VectorClock(com.hazelcast.cluster.impl.VectorClock) CRDTReplicationContainer(com.hazelcast.internal.crdt.CRDTReplicationContainer)

Example 5 with VectorClock

use of com.hazelcast.cluster.impl.VectorClock in project hazelcast by hazelcast.

the class PNCounterImpl method get.

/**
 * Returns the current value of the counter.
 * <p>
 * The method can throw a {@link ConsistencyLostException} when the state
 * of this CRDT is not causally related to the observed timestamps. This
 * means that it cannot provide the session guarantees of RYW (read your
 * writes) and monotonic read.
 *
 * @param observedTimestamps the vector clock last observed by the client of
 *                           this counter
 * @return the current counter value with the current counter vector clock
 * @throws ConsistencyLostException if this replica cannot provide the
 *                                  session guarantees
 */
public CRDTTimestampedLong get(VectorClock observedTimestamps) {
    checkSessionConsistency(observedTimestamps);
    stateReadLock.lock();
    try {
        long value = 0;
        for (long[] pnValue : state.values()) {
            value += pnValue[0];
            value -= pnValue[1];
        }
        return new CRDTTimestampedLong(value, new VectorClock(stateVectorClock));
    } finally {
        stateReadLock.unlock();
    }
}
Also used : VectorClock(com.hazelcast.cluster.impl.VectorClock) CRDTTimestampedLong(com.hazelcast.internal.crdt.pncounter.operations.CRDTTimestampedLong)

Aggregations

VectorClock (com.hazelcast.cluster.impl.VectorClock)7 HashMap (java.util.HashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Config (com.hazelcast.config.Config)2 PNCounterConfig (com.hazelcast.config.PNCounterConfig)2 CRDTReplicationContainer (com.hazelcast.internal.crdt.CRDTReplicationContainer)2 Address (com.hazelcast.cluster.Address)1 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)1 EndpointQualifier (com.hazelcast.instance.EndpointQualifier)1 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)1 AuthenticationFailureOp (com.hazelcast.internal.cluster.impl.operations.AuthenticationFailureOp)1 BeforeJoinCheckFailureOp (com.hazelcast.internal.cluster.impl.operations.BeforeJoinCheckFailureOp)1 ClusterMismatchOp (com.hazelcast.internal.cluster.impl.operations.ClusterMismatchOp)1 CommitClusterStateOp (com.hazelcast.internal.cluster.impl.operations.CommitClusterStateOp)1 ConfigMismatchOp (com.hazelcast.internal.cluster.impl.operations.ConfigMismatchOp)1 ExplicitSuspicionOp (com.hazelcast.internal.cluster.impl.operations.ExplicitSuspicionOp)1 FetchMembersViewOp (com.hazelcast.internal.cluster.impl.operations.FetchMembersViewOp)1 FinalizeJoinOp (com.hazelcast.internal.cluster.impl.operations.FinalizeJoinOp)1 HeartbeatComplaintOp (com.hazelcast.internal.cluster.impl.operations.HeartbeatComplaintOp)1 HeartbeatOp (com.hazelcast.internal.cluster.impl.operations.HeartbeatOp)1