Search in sources :

Example 1 with ProtoBufFile

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);
    }
}
Also used : StablePBMeta(io.dingodb.raft.entity.LocalStorageOutter.StablePBMeta) ProtoBufFile(io.dingodb.raft.storage.io.ProtoBufFile) RaftException(io.dingodb.raft.error.RaftException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with ProtoBufFile

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());
}
Also used : LocalSnapshotPbMeta(io.dingodb.raft.entity.LocalStorageOutter.LocalSnapshotPbMeta) LocalFileMeta(io.dingodb.raft.entity.LocalFileMetaOutter.LocalFileMeta) HashMap(java.util.HashMap) Map(java.util.Map) File(io.dingodb.raft.entity.LocalStorageOutter.LocalSnapshotPbMeta.File) ProtoBufFile(io.dingodb.raft.storage.io.ProtoBufFile) ProtoBufFile(io.dingodb.raft.storage.io.ProtoBufFile)

Example 3 with ProtoBufFile

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);
}
Also used : LocalFileMeta(io.dingodb.raft.entity.LocalFileMetaOutter.LocalFileMeta) ProtoBufFile(io.dingodb.raft.storage.io.ProtoBufFile)

Example 4 with ProtoBufFile

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;
}
Also used : LocalFileMeta(io.dingodb.raft.entity.LocalFileMetaOutter.LocalFileMeta) ProtoBufFile(io.dingodb.raft.storage.io.ProtoBufFile)

Example 5 with ProtoBufFile

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);
}
Also used : LocalSnapshotPbMeta(io.dingodb.raft.entity.LocalStorageOutter.LocalSnapshotPbMeta) ProtoBufFile(io.dingodb.raft.storage.io.ProtoBufFile)

Aggregations

ProtoBufFile (io.dingodb.raft.storage.io.ProtoBufFile)5 LocalFileMeta (io.dingodb.raft.entity.LocalFileMetaOutter.LocalFileMeta)3 LocalSnapshotPbMeta (io.dingodb.raft.entity.LocalStorageOutter.LocalSnapshotPbMeta)2 File (io.dingodb.raft.entity.LocalStorageOutter.LocalSnapshotPbMeta.File)1 StablePBMeta (io.dingodb.raft.entity.LocalStorageOutter.StablePBMeta)1 RaftException (io.dingodb.raft.error.RaftException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1