Search in sources :

Example 1 with PrimitiveType

use of io.atomix.primitive.PrimitiveType in project atomix by atomix.

the class RaftServiceManager method installService.

/**
 * Restores the service associated with the given snapshot.
 *
 * @param reader the snapshot reader
 */
private void installService(SnapshotReader reader) {
    PrimitiveId primitiveId = PrimitiveId.from(reader.readLong());
    PrimitiveType primitiveType = raft.getPrimitiveTypes().get(reader.readString());
    String serviceName = reader.readString();
    // Get or create the service associated with the snapshot.
    logger.debug("Installing service {} {}", primitiveId, serviceName);
    RaftServiceContext service = initializeService(primitiveId, primitiveType, serviceName);
    if (service != null) {
        service.installSnapshot(reader);
    }
}
Also used : RaftServiceContext(io.atomix.protocols.raft.service.RaftServiceContext) PrimitiveType(io.atomix.primitive.PrimitiveType) PrimitiveId(io.atomix.primitive.PrimitiveId)

Example 2 with PrimitiveType

use of io.atomix.primitive.PrimitiveType in project atomix by atomix.

the class RaftServiceManager method applyOpenSession.

/**
 * Applies an open session entry to the state machine.
 */
private long applyOpenSession(Indexed<OpenSessionEntry> entry) {
    PrimitiveType primitiveType = raft.getPrimitiveTypes().get(entry.entry().serviceType());
    if (primitiveType == null) {
        throw new RaftException.UnknownService("Unknown service type " + entry.entry().serviceType());
    }
    // Get the state machine executor or create one if it doesn't already exist.
    RaftServiceContext service = getOrInitializeService(PrimitiveId.from(entry.index()), raft.getPrimitiveTypes().get(entry.entry().serviceType()), entry.entry().serviceName());
    if (service == null) {
        throw new RaftException.UnknownService("Unknown service type " + entry.entry().serviceType());
    }
    SessionId sessionId = SessionId.from(entry.index());
    RaftSession session = raft.getSessions().addSession(new RaftSession(sessionId, NodeId.from(entry.entry().memberId()), entry.entry().serviceName(), primitiveType, entry.entry().readConsistency(), entry.entry().minTimeout(), entry.entry().maxTimeout(), entry.entry().timestamp(), service, raft, threadContextFactory));
    return service.openSession(entry.index(), entry.entry().timestamp(), session);
}
Also used : RaftSession(io.atomix.protocols.raft.session.RaftSession) RaftServiceContext(io.atomix.protocols.raft.service.RaftServiceContext) PrimitiveType(io.atomix.primitive.PrimitiveType) SessionId(io.atomix.primitive.session.SessionId)

Example 3 with PrimitiveType

use of io.atomix.primitive.PrimitiveType 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 = raft.getPrimitiveTypes().get(reader.readString());
    String serviceName = reader.readString();
    int sessionCount = reader.readInt();
    for (int i = 0; i < sessionCount; i++) {
        SessionId sessionId = SessionId.from(reader.readLong());
        NodeId node = NodeId.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, 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);
        sessions.openSession(session);
    }
    currentIndex = reader.snapshot().index();
    currentTimestamp = reader.snapshot().timestamp().unixTimestamp();
    service.restore(reader);
}
Also used : ReadConsistency(io.atomix.protocols.raft.ReadConsistency) RaftSession(io.atomix.protocols.raft.session.RaftSession) NodeId(io.atomix.cluster.NodeId) PrimitiveType(io.atomix.primitive.PrimitiveType) SessionId(io.atomix.primitive.session.SessionId)

Aggregations

PrimitiveType (io.atomix.primitive.PrimitiveType)3 SessionId (io.atomix.primitive.session.SessionId)2 RaftServiceContext (io.atomix.protocols.raft.service.RaftServiceContext)2 RaftSession (io.atomix.protocols.raft.session.RaftSession)2 NodeId (io.atomix.cluster.NodeId)1 PrimitiveId (io.atomix.primitive.PrimitiveId)1 ReadConsistency (io.atomix.protocols.raft.ReadConsistency)1