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");
}
}
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;
}
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;
}
Aggregations