use of com.alipay.sofa.jraft.util.CRC64 in project sofa-jraft by sofastack.
the class ZipUtilTest method zipTest.
@Test
public void zipTest() throws IOException {
final String rootPath = this.sourceDir.toPath().toAbsolutePath().getParent().toString();
final Path outPath = Paths.get(rootPath, "kv.zip");
final Checksum c1 = new CRC64();
ZipUtil.compress(rootPath, "zip_test", outPath.toString(), c1);
System.out.println(Long.toHexString(c1.getValue()));
final Checksum c2 = new CRC64();
ZipUtil.decompress(Paths.get(rootPath, "kv.zip").toString(), rootPath, c2);
Assert.assertEquals(c1.getValue(), c2.getValue());
FileUtils.forceDelete(outPath.toFile());
}
use of com.alipay.sofa.jraft.util.CRC64 in project sofa-jraft by sofastack.
the class SnapshotBenchmark method doCompressSnapshot.
private void doCompressSnapshot(final String path, final LocalFileMeta.Builder metaBuilder) {
final String outputFile = Paths.get(path, SNAPSHOT_ARCHIVE).toString();
try {
final Checksum checksum = new CRC64();
ZipUtil.compress(path, SNAPSHOT_DIR, outputFile, checksum);
metaBuilder.setChecksum(Long.toHexString(checksum.getValue()));
} catch (final Throwable t) {
t.printStackTrace();
}
}
use of com.alipay.sofa.jraft.util.CRC64 in project sofa-jraft by sofastack.
the class SnapshotBenchmark method snapshot.
public void snapshot(final boolean isSstSnapshot, final boolean isFastSnapshot) throws IOException {
final File backupDir = new File("backup");
if (backupDir.exists()) {
FileUtils.deleteDirectory(backupDir);
}
FileUtils.forceMkdir(backupDir);
final LocalFileMeta meta = doSnapshotSave(backupDir.getAbsolutePath(), isSstSnapshot, isFastSnapshot);
this.kvStore.shutdown();
FileUtils.deleteDirectory(new File(this.tempPath));
FileUtils.forceMkdir(new File(this.tempPath));
this.kvStore = new RocksRawKVStore();
this.kvStore.init(this.dbOptions);
final String name;
if (isSstSnapshot) {
name = "sst";
} else {
if (isFastSnapshot) {
name = "fast";
} else {
name = "slow";
}
}
final long decompressStart = System.nanoTime();
final String sourceFile = Paths.get(backupDir.getAbsolutePath(), SNAPSHOT_ARCHIVE).toString();
ZipUtil.decompress(sourceFile, backupDir.getAbsolutePath(), new CRC64());
System.out.println(name + " decompress time cost: " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - decompressStart));
final long loadStart = System.nanoTime();
doSnapshotLoad(backupDir.getAbsolutePath(), meta, isFastSnapshot);
System.out.println(name + " load snapshot time cost: " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - loadStart));
FileUtils.deleteDirectory(backupDir);
}
use of com.alipay.sofa.jraft.util.CRC64 in project sofa-jraft by sofastack.
the class AbstractKVStoreSnapshotFile method compressSnapshot.
protected void compressSnapshot(final SnapshotWriter writer, final LocalFileMeta.Builder metaBuilder, final Closure done) {
final String writerPath = writer.getPath();
final String outputFile = Paths.get(writerPath, SNAPSHOT_ARCHIVE).toString();
try {
final Checksum checksum = new CRC64();
ZipStrategyManager.getDefault().compress(writerPath, SNAPSHOT_DIR, outputFile, checksum);
metaBuilder.setChecksum(Long.toHexString(checksum.getValue()));
if (writer.addFile(SNAPSHOT_ARCHIVE, metaBuilder.build())) {
done.run(Status.OK());
} else {
done.run(new Status(RaftError.EIO, "Fail to add snapshot file: %s", writerPath));
}
} catch (final Throwable t) {
LOG.error("Fail to compress snapshot, path={}, file list={}, {}.", writerPath, writer.listFiles(), StackTraceUtil.stackTrace(t));
done.run(new Status(RaftError.EIO, "Fail to compress snapshot at %s, error is %s", writerPath, t.getMessage()));
}
}
use of com.alipay.sofa.jraft.util.CRC64 in project mmqtt by MrHKing.
the class MmqSnapshotOperation method writeSnapshot.
@Override
protected boolean writeSnapshot(Writer writer) throws Exception {
final String writePath = writer.getPath();
final String parentPath = Paths.get(writePath, snapshotDir).toString();
DiskUtils.deleteDirectory(parentPath);
DiskUtils.forceMkdir(parentPath);
storage.doSnapshot(parentPath);
final String outputFile = Paths.get(writePath, snapshotArchive).toString();
final Checksum checksum = new CRC64();
DiskUtils.compress(writePath, snapshotDir, outputFile, checksum);
DiskUtils.deleteDirectory(parentPath);
final LocalFileMeta meta = new LocalFileMeta();
meta.append(CHECK_SUM_KEY, Long.toHexString(checksum.getValue()));
return writer.addFile(snapshotArchive, meta);
}
Aggregations