Search in sources :

Example 1 with ClusterRecord

use of tezc.core.record.ClusterRecord in project tezcRaft by tezc.

the class Cluster method readMeta.

/**
 * Read metadata of the cluster
 * @return             true if config is found
 * @throws IOException on any IO error
 */
private boolean readMeta() throws IOException {
    Path configPath = Paths.get(this.path + "/" + "cluster" + ".conf");
    Path configTmpPath = Paths.get(this.path + "/" + "cluster" + ".conf.tmp");
    Path path = null;
    if (Files.exists(configPath)) {
        path = configPath;
    } else if (Files.exists(configTmpPath)) {
        path = configTmpPath;
    } else {
        worker.logInfo("Cannot find a config file");
        return false;
    }
    Set<StandardOpenOption> options = EnumSet.of(StandardOpenOption.READ);
    FileChannel channel = FileChannel.open(path, options);
    if (channel.size() > Integer.MAX_VALUE) {
        channel.close();
        worker.logInfo("Config file size " + "is beyond the limit : " + channel.size());
        return false;
    }
    if (channel.size() > configBuf.cap()) {
        configBuf = new Buffer(ByteBuffer.allocateDirect((int) channel.size()));
    }
    int read = 0;
    configBuf.clear();
    while (configBuf.hasRemaining() && read != -1) {
        read = channel.read(configBuf.backend());
    }
    configBuf.flip();
    nodeId = configBuf.getInt();
    started = configBuf.getBoolean();
    currentTerm = configBuf.getLong();
    votedFor = configBuf.getInt();
    clusterRecord = new ClusterRecord(configBuf);
    channel.close();
    return true;
}
Also used : Path(java.nio.file.Path) ByteBuffer(java.nio.ByteBuffer) Buffer(tezc.base.common.Buffer) ClusterRecord(tezc.core.record.ClusterRecord) StandardOpenOption(java.nio.file.StandardOpenOption) FileChannel(java.nio.channels.FileChannel)

Example 2 with ClusterRecord

use of tezc.core.record.ClusterRecord in project tezcRaft by tezc.

the class RaftState method loadState.

/**
 * Deserialize state from an inputstream
 *
 * @param in             inputstream
 * @throws IOException   on any IO error
 */
@Override
public void loadState(InputStream in) throws IOException {
    int len = Util.readVarInt(in);
    Buffer buf = new Buffer(len);
    in.read(buf.array(), 0, len);
    buf.position(len);
    buf.flip();
    int count = buf.getVarInt();
    for (int i = 0; i < count; i++) {
        Session session = new Session(buf);
        sessions.put(session.getName(), session);
    }
    record = new ClusterRecord(buf);
}
Also used : Buffer(tezc.base.common.Buffer) ByteBuffer(java.nio.ByteBuffer) ClusterRecord(tezc.core.record.ClusterRecord) Session(tezc.core.cluster.Session)

Example 3 with ClusterRecord

use of tezc.core.record.ClusterRecord in project tezcRaft by tezc.

the class ConnectResp method decode.

/**
 * Decode message
 */
@Override
public void decode() {
    cluster = new ClusterRecord(rawMsg);
    id = rawMsg.getVarInt();
    sequence = rawMsg.getVarLong();
    result = rawMsg.getBoolean();
    rawMsg.rewind();
    rawReady = true;
}
Also used : ClusterRecord(tezc.core.record.ClusterRecord)

Example 4 with ClusterRecord

use of tezc.core.record.ClusterRecord in project tezcRaft by tezc.

the class JoinReq method decode.

/**
 * Decode JoinReq
 */
@Override
public void decode() {
    record = new ClusterRecord(rawMsg);
    rawMsg.rewind();
    rawReady = true;
}
Also used : ClusterRecord(tezc.core.record.ClusterRecord)

Example 5 with ClusterRecord

use of tezc.core.record.ClusterRecord in project tezcRaft by tezc.

the class JoinResp method decode.

/**
 * Decode JoinResp
 */
@Override
public void decode() {
    record = new ClusterRecord(rawMsg);
    result = rawMsg.getBoolean();
    rawMsg.rewind();
    rawReady = true;
}
Also used : ClusterRecord(tezc.core.record.ClusterRecord)

Aggregations

ClusterRecord (tezc.core.record.ClusterRecord)5 ByteBuffer (java.nio.ByteBuffer)2 Buffer (tezc.base.common.Buffer)2 FileChannel (java.nio.channels.FileChannel)1 Path (java.nio.file.Path)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 Session (tezc.core.cluster.Session)1