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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations