use of io.dingodb.raft.storage.io.ProtoBufFile in project dingo by dingodb.
the class LocalRaftMetaStorage method save.
private boolean save() {
final long start = Utils.monotonicMs();
final StablePBMeta meta = //
StablePBMeta.newBuilder().setTerm(//
this.term).setVotedfor(//
this.votedFor.toString()).build();
final ProtoBufFile pbFile = newPbFile();
try {
if (!pbFile.save(meta, this.raftOptions.isSyncMeta())) {
reportIOError();
return false;
}
return true;
} catch (final Exception e) {
LOG.error("Fail to save raft meta", e);
reportIOError();
return false;
} finally {
final long cost = Utils.monotonicMs() - start;
if (this.nodeMetrics != null) {
this.nodeMetrics.recordLatency("save-raft-meta", cost);
}
LOG.info("Save raft meta, path={}, term={}, votedFor={}, cost time={} ms", this.path, this.term, this.votedFor, cost);
}
}
use of io.dingodb.raft.storage.io.ProtoBufFile in project dingo by dingodb.
the class LocalSnapshotMetaTable method saveToFile.
/**
* Save metadata infos into file by path.
*/
public boolean saveToFile(String path) throws IOException {
LocalSnapshotPbMeta.Builder pbMeta = LocalSnapshotPbMeta.newBuilder();
if (hasMeta()) {
pbMeta.setMeta(this.meta);
}
for (Map.Entry<String, LocalFileMeta> entry : this.fileMap.entrySet()) {
File f = File.newBuilder().setName(entry.getKey()).setMeta(entry.getValue()).build();
pbMeta.addFiles(f);
}
ProtoBufFile pbFile = new ProtoBufFile(path);
return pbFile.save(pbMeta.build(), this.raftOptions.isSyncMeta());
}
use of io.dingodb.raft.storage.io.ProtoBufFile in project dingo by dingodb.
the class CheckpointFile method save.
public synchronized boolean save(final Checkpoint checkpoint) throws IOException {
final ProtoBufFile file = new ProtoBufFile(this.path);
final byte[] data = checkpoint.encode();
final LocalFileMeta meta = //
LocalFileMeta.newBuilder().setUserMeta(//
ZeroByteStringHelper.wrap(data)).build();
return file.save(meta, true);
}
use of io.dingodb.raft.storage.io.ProtoBufFile in project dingo by dingodb.
the class CheckpointFile method load.
public Checkpoint load() throws IOException {
final ProtoBufFile file = new ProtoBufFile(this.path);
final LocalFileMeta meta = file.load();
if (meta != null) {
final byte[] data = meta.getUserMeta().toByteArray();
Checkpoint checkpoint = new Checkpoint(null, -1);
if (checkpoint.decode(data)) {
return checkpoint;
}
}
return null;
}
use of io.dingodb.raft.storage.io.ProtoBufFile in project dingo by dingodb.
the class LocalSnapshotMetaTable method loadFromFile.
/**
* Load metadata infos from a file by path.
*/
public boolean loadFromFile(String path) throws IOException {
ProtoBufFile pbFile = new ProtoBufFile(path);
LocalSnapshotPbMeta pbMeta = pbFile.load();
if (pbMeta == null) {
LOG.error("Fail to load meta from {}.", path);
return false;
}
return loadFromPbMeta(pbMeta);
}
Aggregations