Search in sources :

Example 21 with MemberId

use of io.atomix.cluster.MemberId in project atomix by atomix.

the class MemberSelectorManager method resetAll.

/**
 * Resets all child selectors.
 *
 * @param leader  The current cluster leader.
 * @param members The collection of all active members.
 */
public void resetAll(MemberId leader, Collection<MemberId> members) {
    MemberId oldLeader = this.leader;
    this.leader = leader;
    this.members = Lists.newLinkedList(members);
    selectors.forEach(s -> s.reset(leader, this.members));
    if (!Objects.equals(oldLeader, leader)) {
        leaderChangeListeners.forEach(l -> l.accept(leader));
    }
}
Also used : MemberId(io.atomix.cluster.MemberId)

Example 22 with MemberId

use of io.atomix.cluster.MemberId in project atomix by atomix.

the class RaftServiceContext method installSnapshot.

/**
 * Installs a snapshot.
 */
public void installSnapshot(SnapshotReader reader) {
    log.debug("Installing snapshot {}", reader.snapshot().index());
    // Skip the service ID
    reader.skip(Bytes.LONG);
    PrimitiveType primitiveType;
    try {
        primitiveType = raft.getPrimitiveTypes().getPrimitiveType(reader.readString());
    } catch (ConfigurationException e) {
        log.error(e.getMessage(), e);
        return;
    }
    String serviceName = reader.readString();
    currentIndex = reader.readLong();
    currentTimestamp = reader.readLong();
    timestampDelta = reader.readLong();
    int sessionCount = reader.readInt();
    for (int i = 0; i < sessionCount; i++) {
        SessionId sessionId = SessionId.from(reader.readLong());
        MemberId node = MemberId.from(reader.readString());
        ReadConsistency readConsistency = ReadConsistency.valueOf(reader.readString());
        long minTimeout = reader.readLong();
        long maxTimeout = reader.readLong();
        long sessionTimestamp = reader.readLong();
        // Only create a new session if one does not already exist. This is necessary to ensure only a single session
        // is ever opened and exposed to the state machine.
        RaftSession session = raft.getSessions().addSession(new RaftSession(sessionId, node, serviceName, primitiveType, readConsistency, minTimeout, maxTimeout, sessionTimestamp, service.serializer(), this, raft, threadContextFactory));
        session.setRequestSequence(reader.readLong());
        session.setCommandSequence(reader.readLong());
        session.setEventIndex(reader.readLong());
        session.setLastCompleted(reader.readLong());
        session.setLastApplied(reader.snapshot().index());
        session.setLastUpdated(sessionTimestamp);
        session.open();
        service.register(sessions.addSession(session));
    }
    service.restore(new DefaultBackupInput(reader, service.serializer()));
}
Also used : ReadConsistency(io.atomix.protocols.raft.ReadConsistency) MemberId(io.atomix.cluster.MemberId) RaftSession(io.atomix.protocols.raft.session.RaftSession) ConfigurationException(io.atomix.utils.config.ConfigurationException) PrimitiveType(io.atomix.primitive.PrimitiveType) SessionId(io.atomix.primitive.session.SessionId) DefaultBackupInput(io.atomix.primitive.service.impl.DefaultBackupInput)

Example 23 with MemberId

use of io.atomix.cluster.MemberId in project atomix by atomix.

the class MemberSelector method next.

@Override
public MemberId next() {
    if (selectionsIterator == null) {
        selectionsIterator = selections.iterator();
    }
    MemberId selection = selectionsIterator.next();
    this.selection = selection;
    return selection;
}
Also used : MemberId(io.atomix.cluster.MemberId)

Example 24 with MemberId

use of io.atomix.cluster.MemberId in project atomix by atomix.

the class SynchronousReplicator method replicate.

@Override
public CompletableFuture<Void> replicate(BackupOperation operation) {
    if (context.backups().isEmpty()) {
        return CompletableFuture.completedFuture(null);
    }
    CompletableFuture<Void> future = new CompletableFuture<>();
    futures.put(operation.index(), future);
    for (MemberId backup : context.backups()) {
        queues.computeIfAbsent(backup, BackupQueue::new).add(operation);
    }
    return future;
}
Also used : MemberId(io.atomix.cluster.MemberId) CompletableFuture(java.util.concurrent.CompletableFuture)

Aggregations

MemberId (io.atomix.cluster.MemberId)24 CompletableFuture (java.util.concurrent.CompletableFuture)10 ArrayList (java.util.ArrayList)9 List (java.util.List)7 Consumer (java.util.function.Consumer)7 Collectors (java.util.stream.Collectors)7 PrimitiveType (io.atomix.primitive.PrimitiveType)6 Futures (io.atomix.utils.concurrent.Futures)6 SessionId (io.atomix.primitive.session.SessionId)5 RaftMember (io.atomix.protocols.raft.cluster.RaftMember)5 Configuration (io.atomix.protocols.raft.storage.system.Configuration)5 Instant (java.time.Instant)5 Collections (java.util.Collections)5 Map (java.util.Map)5 TestClusterMembershipService (io.atomix.cluster.TestClusterMembershipService)4 PrimitiveBuilder (io.atomix.primitive.PrimitiveBuilder)4 PrimitiveManagementService (io.atomix.primitive.PrimitiveManagementService)4 PrimitiveConfig (io.atomix.primitive.config.PrimitiveConfig)4 PartitionId (io.atomix.primitive.partition.PartitionId)4 AbstractPrimitiveService (io.atomix.primitive.service.AbstractPrimitiveService)4