use of io.dingodb.raft.storage.snapshot.remote.Session in project dingo by dingodb.
the class LocalSnapshotCopier method loadMetaTable.
private void loadMetaTable() throws InterruptedException {
final ByteBufferCollector metaBuf = ByteBufferCollector.allocate(0);
Session session = null;
try {
this.lock.lock();
try {
if (this.cancelled) {
if (isOk()) {
setError(RaftError.ECANCELED, "ECANCELED");
}
return;
}
session = this.copier.startCopy2IoBuffer(Snapshot.JRAFT_SNAPSHOT_META_FILE, metaBuf, null);
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()) {
LOG.warn("Fail to copy meta file: {}", session.status());
setError(session.status().getCode(), session.status().getErrorMsg());
return;
}
if (!this.remoteSnapshot.getMetaTable().loadFromIoBufferAsRemote(metaBuf.getBuffer())) {
LOG.warn("Bad meta_table format");
setError(-1, "Bad meta_table format from remote");
return;
}
Requires.requireTrue(this.remoteSnapshot.getMetaTable().hasMeta(), "Invalid remote snapshot meta:%s", this.remoteSnapshot.getMetaTable().getMeta());
} finally {
if (session != null) {
Utils.closeQuietly(session);
}
}
}
use of io.dingodb.raft.storage.snapshot.remote.Session 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);
}
}
}
Aggregations