Search in sources :

Example 1 with LogicalTimestamp

use of io.atomix.utils.time.LogicalTimestamp in project atomix by atomix.

the class DefaultClusterMetadataService method handleAdvertisement.

/**
 * Handles an anti-entropy advertisement.
 */
private byte[] handleAdvertisement(Endpoint endpoint, byte[] payload) {
    LogicalTimestamp timestamp = clock.increment();
    ClusterMetadataAdvertisement advertisement = SERIALIZER.decode(payload);
    Set<NodeId> staleNodes = nodes.values().stream().map(node -> {
        NodeDigest digest = advertisement.digest(node.id());
        if (digest == null || node.isNewerThan(digest.timestamp())) {
            sendUpdate(endpoint, new NodeUpdate(node, timestamp));
        } else if (digest.isNewerThan(node.timestamp())) {
            if (digest.tombstone()) {
                if (!node.tombstone()) {
                    nodes.put(node.id(), new ReplicatedNode(node.id(), node.type(), node.endpoint(), node.zone(), node.rack(), node.host(), digest.timestamp(), true));
                    post(new ClusterMetadataEvent(ClusterMetadataEvent.Type.METADATA_CHANGED, getMetadata()));
                }
            } else {
                return node.id();
            }
        }
        return null;
    }).filter(Objects::nonNull).collect(Collectors.toSet());
    return SERIALIZER.encode(Sets.newHashSet(Sets.union(Sets.difference(advertisement.digests(), nodes.keySet()), staleNodes)));
}
Also used : LogicalTimestamp(io.atomix.utils.time.LogicalTimestamp) ClusterMetadataEvent(io.atomix.cluster.ClusterMetadataEvent) NodeId(io.atomix.cluster.NodeId)

Example 2 with LogicalTimestamp

use of io.atomix.utils.time.LogicalTimestamp in project atomix by atomix.

the class DefaultClusterMetadataService method addNode.

@Override
public void addNode(Node node) {
    if (node.type() != Node.Type.CLIENT) {
        ReplicatedNode replicatedNode = nodes.get(node.id());
        if (replicatedNode == null) {
            LogicalTimestamp timestamp = clock.increment();
            replicatedNode = new ReplicatedNode(node.id(), node.type(), node.endpoint(), node.zone(), node.rack(), node.host(), timestamp, false);
            nodes.put(replicatedNode.id(), replicatedNode);
            broadcastUpdate(new NodeUpdate(replicatedNode, timestamp));
            post(new ClusterMetadataEvent(ClusterMetadataEvent.Type.METADATA_CHANGED, getMetadata()));
        }
    }
}
Also used : LogicalTimestamp(io.atomix.utils.time.LogicalTimestamp) ClusterMetadataEvent(io.atomix.cluster.ClusterMetadataEvent)

Example 3 with LogicalTimestamp

use of io.atomix.utils.time.LogicalTimestamp in project atomix by atomix.

the class DefaultClusterMetadataService method removeNode.

@Override
public void removeNode(Node node) {
    ReplicatedNode replicatedNode = nodes.get(node.id());
    if (replicatedNode != null) {
        LogicalTimestamp timestamp = clock.increment();
        replicatedNode = new ReplicatedNode(node.id(), node.type(), node.endpoint(), node.zone(), node.rack(), node.host(), timestamp, true);
        nodes.put(replicatedNode.id(), replicatedNode);
        broadcastUpdate(new NodeUpdate(replicatedNode, timestamp));
        post(new ClusterMetadataEvent(ClusterMetadataEvent.Type.METADATA_CHANGED, getMetadata()));
    }
}
Also used : LogicalTimestamp(io.atomix.utils.time.LogicalTimestamp) ClusterMetadataEvent(io.atomix.cluster.ClusterMetadataEvent)

Aggregations

ClusterMetadataEvent (io.atomix.cluster.ClusterMetadataEvent)3 LogicalTimestamp (io.atomix.utils.time.LogicalTimestamp)3 NodeId (io.atomix.cluster.NodeId)1