use of com.alipay.sofa.jraft.util.CRC64 in project sofa-jraft by sofastack.
the class JDKZipStrategyTest method zipTest.
@Test
public void zipTest() throws Throwable {
final String rootPath = this.sourceDir.toPath().toAbsolutePath().getParent().toString();
final Path outPath = Paths.get(rootPath, "kv.zip");
final Checksum c1 = new CRC64();
zipStrategy.compress(rootPath, "zip_test", outPath.toString(), c1);
System.out.println(Long.toHexString(c1.getValue()));
final Checksum c2 = new CRC64();
zipStrategy.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 ParallelZipStrategyTest method zipTest.
@Test
public void zipTest() throws Throwable {
final String rootPath = this.sourceDir.toPath().toAbsolutePath().getParent().toString();
final Path outPath = Paths.get(rootPath, "kv.zip");
final Checksum c1 = new CRC64();
zipStrategy.compress(rootPath, "zip_test", outPath.toString(), c1);
System.out.println(Long.toHexString(c1.getValue()));
final Checksum c2 = new CRC64();
zipStrategy.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 AbstractKVStoreSnapshotFile method decompressSnapshot.
protected void decompressSnapshot(final String readerPath, final LocalFileMeta meta) throws Throwable {
final String sourceFile = Paths.get(readerPath, SNAPSHOT_ARCHIVE).toString();
final Checksum checksum = new CRC64();
ZipStrategyManager.getDefault().deCompress(sourceFile, readerPath, checksum);
if (meta.hasChecksum()) {
Requires.requireTrue(meta.getChecksum().equals(Long.toHexString(checksum.getValue())), "Snapshot checksum failed");
}
}
use of com.alipay.sofa.jraft.util.CRC64 in project incubator-hugegraph by apache.
the class StoreSnapshotFile method decompressSnapshot.
private String decompressSnapshot(SnapshotReader reader, String snapshotDirTar) throws IOException {
LocalFileMeta meta = (LocalFileMeta) reader.getFileMeta(snapshotDirTar);
if (meta == null) {
throw new IOException("Can't find snapshot archive file, path=" + snapshotDirTar);
}
String diskTableKey = meta.getUserMeta().toStringUtf8();
E.checkArgument(this.dataDisks.containsKey(diskTableKey), "The data path for '%s' should be exist", diskTableKey);
String dataPath = this.dataDisks.get(diskTableKey);
String parentPath = Paths.get(dataPath).getParent().toString();
String snapshotDir = Paths.get(parentPath, StringUtils.removeEnd(snapshotDirTar, TAR)).toString();
FileUtils.deleteDirectory(new File(snapshotDir));
LOG.info("Delete stale snapshot dir {}", snapshotDir);
Checksum checksum = new CRC64();
String archiveFile = Paths.get(reader.getPath(), snapshotDirTar).toString();
CompressUtil.decompressTar(archiveFile, parentPath, checksum);
if (meta.hasChecksum()) {
String expected = meta.getChecksum();
String actual = Long.toHexString(checksum.getValue());
E.checkArgument(expected.equals(actual), "Snapshot checksum error: '%s' != '%s'", actual, expected);
}
return snapshotDir;
}
use of com.alipay.sofa.jraft.util.CRC64 in project nacos by alibaba.
the class AbstractMetadataSnapshotOperation method readSnapshot.
@Override
protected boolean readSnapshot(Reader reader) throws Exception {
final String readerPath = reader.getPath();
final String sourceFile = Paths.get(readerPath, getSnapshotArchive()).toString();
final Checksum checksum = new CRC64();
byte[] snapshotBytes = DiskUtils.decompress(sourceFile, checksum);
LocalFileMeta fileMeta = reader.getFileMeta(getSnapshotArchive());
if (fileMeta.getFileMeta().containsKey(CHECK_SUM_KEY)) {
if (!Objects.equals(Long.toHexString(checksum.getValue()), fileMeta.get(CHECK_SUM_KEY))) {
throw new IllegalArgumentException("Snapshot checksum failed");
}
}
loadSnapshot(snapshotBytes);
return true;
}
Aggregations