Search in sources :

Example 11 with SnapshotReader

use of org.apache.ignite.raft.jraft.storage.snapshot.SnapshotReader in project ignite-3 by apache.

the class LocalSnapshotCopier method filter.

private void filter() throws IOException {
    this.writer = (LocalSnapshotWriter) this.storage.create(!this.filterBeforeCopyRemote);
    if (this.writer == null) {
        setError(RaftError.EIO, "Fail to create snapshot writer");
        return;
    }
    if (this.filterBeforeCopyRemote) {
        final SnapshotReader reader = this.storage.open();
        if (!filterBeforeCopy(this.writer, reader)) {
            LOG.warn("Fail to filter writer before copying, destroy and create a new writer.");
            this.writer.setError(-1, "Fail to filter");
            Utils.closeQuietly(this.writer);
            this.writer = (LocalSnapshotWriter) this.storage.create(true);
        }
        if (reader != null) {
            Utils.closeQuietly(reader);
        }
        if (this.writer == null) {
            setError(RaftError.EIO, "Fail to create snapshot writer");
            return;
        }
    }
    this.writer.saveMeta(this.remoteSnapshot.getMetaTable().getMeta());
    if (!this.writer.sync()) {
        LOG.error("Fail to sync snapshot writer path={}", this.writer.getPath());
        setError(RaftError.EIO, "Fail to sync snapshot writer");
    }
}
Also used : SnapshotReader(org.apache.ignite.raft.jraft.storage.snapshot.SnapshotReader)

Example 12 with SnapshotReader

use of org.apache.ignite.raft.jraft.storage.snapshot.SnapshotReader in project ignite-3 by apache.

the class LocalSnapshotStorage method open.

@Override
public SnapshotReader open() {
    long lsIndex = 0;
    this.lock.lock();
    try {
        if (this.lastSnapshotIndex != 0) {
            lsIndex = this.lastSnapshotIndex;
            ref(lsIndex);
        }
    } finally {
        this.lock.unlock();
    }
    if (lsIndex == 0) {
        LOG.warn("No data for snapshot reader {}.", this.path);
        return null;
    }
    final String snapshotPath = getSnapshotPath(lsIndex);
    final SnapshotReader reader = new LocalSnapshotReader(this, this.snapshotThrottle, this.addr, this.raftOptions, snapshotPath);
    if (!reader.init(null)) {
        LOG.error("Fail to init reader for path {}.", snapshotPath);
        unref(lsIndex);
        return null;
    }
    return reader;
}
Also used : SnapshotReader(org.apache.ignite.raft.jraft.storage.snapshot.SnapshotReader)

Example 13 with SnapshotReader

use of org.apache.ignite.raft.jraft.storage.snapshot.SnapshotReader in project ignite-3 by apache.

the class LocalSnapshotStorage method copyFrom.

@Override
public SnapshotReader copyFrom(final String uri, final SnapshotCopierOptions opts) {
    final SnapshotCopier copier = startToCopyFrom(uri, opts);
    if (copier == null) {
        return null;
    }
    try {
        copier.join();
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        LOG.error("Join on snapshot copier was interrupted.");
        return null;
    }
    final SnapshotReader reader = copier.getReader();
    Utils.closeQuietly(copier);
    return reader;
}
Also used : SnapshotReader(org.apache.ignite.raft.jraft.storage.snapshot.SnapshotReader) SnapshotCopier(org.apache.ignite.raft.jraft.storage.snapshot.SnapshotCopier)

Aggregations

SnapshotReader (org.apache.ignite.raft.jraft.storage.snapshot.SnapshotReader)13 Test (org.junit.jupiter.api.Test)9 Status (org.apache.ignite.raft.jraft.Status)5 Message (org.apache.ignite.raft.jraft.rpc.Message)5 RpcRequests (org.apache.ignite.raft.jraft.rpc.RpcRequests)5 CompletableFuture (java.util.concurrent.CompletableFuture)4 LoadSnapshotClosure (org.apache.ignite.raft.jraft.closure.LoadSnapshotClosure)4 RpcResponseClosure (org.apache.ignite.raft.jraft.rpc.RpcResponseClosure)4 BaseStorageTest (org.apache.ignite.raft.jraft.storage.BaseStorageTest)4 Endpoint (org.apache.ignite.raft.jraft.util.Endpoint)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 RaftOutter (org.apache.ignite.raft.jraft.entity.RaftOutter)3 SnapshotMeta (org.apache.ignite.raft.jraft.entity.RaftOutter.SnapshotMeta)3 ByteString (org.apache.ignite.raft.jraft.util.ByteString)3 ByteBuffer (java.nio.ByteBuffer)2 GetFileRequestBuilder (org.apache.ignite.raft.jraft.rpc.GetFileRequestBuilder)2 RaftMessagesFactory (org.apache.ignite.raft.jraft.RaftMessagesFactory)1 Configuration (org.apache.ignite.raft.jraft.conf.Configuration)1 LogId (org.apache.ignite.raft.jraft.entity.LogId)1 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)1