Search in sources :

Example 1 with LocalFileMeta

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);
        }
    }
}
Also used : Path(java.nio.file.Path) LocalFileMeta(io.dingodb.raft.entity.LocalFileMetaOutter.LocalFileMeta) File(java.io.File) Session(io.dingodb.raft.storage.snapshot.remote.Session)

Example 2 with LocalFileMeta

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());
}
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 LocalFileMeta

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;
    }
}
Also used : ByteString(com.google.protobuf.ByteString) LocalFileMeta(io.dingodb.raft.entity.LocalFileMetaOutter.LocalFileMeta) File(java.io.File)

Example 4 with LocalFileMeta

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;
    }
}
Also used : ByteString(com.google.protobuf.ByteString) LocalFileMeta(io.dingodb.raft.entity.LocalFileMetaOutter.LocalFileMeta) File(java.io.File)

Example 5 with LocalFileMeta

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

Aggregations

LocalFileMeta (io.dingodb.raft.entity.LocalFileMetaOutter.LocalFileMeta)9 File (java.io.File)4 ProtoBufFile (io.dingodb.raft.storage.io.ProtoBufFile)3 ByteString (com.google.protobuf.ByteString)2 Builder (io.dingodb.raft.entity.LocalFileMetaOutter.LocalFileMeta.Builder)1 LocalSnapshotPbMeta (io.dingodb.raft.entity.LocalStorageOutter.LocalSnapshotPbMeta)1 File (io.dingodb.raft.entity.LocalStorageOutter.LocalSnapshotPbMeta.File)1 RetryAgainException (io.dingodb.raft.error.RetryAgainException)1 Session (io.dingodb.raft.storage.snapshot.remote.Session)1 ArrayDeque (io.dingodb.raft.util.ArrayDeque)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1