use of io.dingodb.raft.entity.LocalFileMetaOutter.LocalFileMeta in project dingo by dingodb.
the class LocalSnapshotCopier method copyFile.
void copyFile(final String fileName) throws IOException, InterruptedException {
if (this.writer.getFileMeta(fileName) != null) {
LOG.info("Skipped downloading {}", fileName);
return;
}
if (!checkFile(fileName)) {
return;
}
final String filePath = this.writer.getPath() + File.separator + fileName;
final Path subPath = Paths.get(filePath);
if (!subPath.equals(subPath.getParent()) && !subPath.getParent().getFileName().toString().equals(".")) {
final File parentDir = subPath.getParent().toFile();
if (!parentDir.exists() && !parentDir.mkdirs()) {
LOG.error("Fail to create directory for {}", filePath);
setError(RaftError.EIO, "Fail to create directory");
return;
}
}
final LocalFileMeta meta = (LocalFileMeta) this.remoteSnapshot.getFileMeta(fileName);
Session session = null;
try {
this.lock.lock();
try {
if (this.cancelled) {
if (isOk()) {
setError(RaftError.ECANCELED, "ECANCELED");
}
return;
}
session = this.copier.startCopyToFile(fileName, filePath, null);
if (session == null) {
LOG.error("Fail to copy {}", fileName);
setError(-1, "Fail to copy %s", fileName);
return;
}
this.curSession = session;
} finally {
this.lock.unlock();
}
// join out of lock
session.join();
this.lock.lock();
try {
this.curSession = null;
} finally {
this.lock.unlock();
}
if (!session.status().isOk() && isOk()) {
setError(session.status().getCode(), session.status().getErrorMsg());
return;
}
if (!this.writer.addFile(fileName, meta)) {
setError(RaftError.EIO, "Fail to add file to writer");
return;
}
if (!this.writer.sync()) {
setError(RaftError.EIO, "Fail to sync writer");
}
} finally {
if (session != null) {
Utils.closeQuietly(session);
}
}
}
use of io.dingodb.raft.entity.LocalFileMetaOutter.LocalFileMeta 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.entity.LocalFileMetaOutter.LocalFileMeta in project dingo by dingodb.
the class AbstractKVStoreSnapshotFile method load.
@Override
public boolean load(final SnapshotReader reader, final Region region) {
final LocalFileMeta meta = (LocalFileMeta) reader.getFileMeta(SNAPSHOT_ARCHIVE);
final String readerPath = reader.getPath();
if (meta == null) {
LOG.error("Can't find kv snapshot file, path={}.", readerPath);
return false;
}
final String snapshotPath = Paths.get(readerPath, SNAPSHOT_DIR).toString();
try {
decompressSnapshot(readerPath, meta);
doSnapshotLoad(snapshotPath, meta, region);
final File tmp = new File(snapshotPath);
// to the log information.
if (tmp.exists()) {
FileUtils.forceDelete(new File(snapshotPath));
}
return true;
} catch (final Throwable t) {
LOG.error("Fail to load snapshot, path={}, file list={}, {}.", readerPath, reader.listFiles(), StackTraceUtil.stackTrace(t));
return false;
}
}
use of io.dingodb.raft.entity.LocalFileMetaOutter.LocalFileMeta in project dingo by dingodb.
the class CoordinatorStateSnapshot method load.
public boolean load(final SnapshotReader reader) {
final LocalFileMeta meta = (LocalFileMeta) reader.getFileMeta(SNAPSHOT_ARCHIVE);
final String readerPath = reader.getPath();
if (meta == null) {
log.error("Can't find kv snapshot file, path={}.", readerPath);
return false;
}
final String snapshotPath = Paths.get(readerPath, SNAPSHOT_DIR).toString();
try {
decompressSnapshot(readerPath, meta);
loadSnapshot(snapshotPath);
final File tmp = new File(snapshotPath);
// to the log information.
if (tmp.exists()) {
FileUtils.forceDelete(new File(snapshotPath));
}
return true;
} catch (final Throwable t) {
log.error("Fail to load snapshot, path={}, file list={}, {}.", readerPath, reader.listFiles(), StackTraceUtil.stackTrace(t));
return false;
}
}
use of io.dingodb.raft.entity.LocalFileMetaOutter.LocalFileMeta 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);
}
Aggregations