use of com.alipay.sofa.jraft.util.CRC64 in project mmqtt by MrHKing.
the class MmqSnapshotOperation method readSnapshot.
@Override
protected boolean readSnapshot(Reader reader) throws Exception {
final String readerPath = reader.getPath();
final String sourceFile = Paths.get(readerPath, snapshotArchive).toString();
final Checksum checksum = new CRC64();
DiskUtils.decompress(sourceFile, readerPath, checksum);
LocalFileMeta fileMeta = reader.getFileMeta(snapshotArchive);
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");
}
}
final String loadPath = Paths.get(readerPath, snapshotDir).toString();
storage.snapshotLoad(loadPath);
Loggers.RAFT.info("snapshot load from : {}", loadPath);
DiskUtils.deleteDirectory(loadPath);
return true;
}
use of com.alipay.sofa.jraft.util.CRC64 in project incubator-hugegraph by apache.
the class StoreSnapshotFile method compressSnapshotDir.
private void compressSnapshotDir(SnapshotWriter writer, Map<String, String> snapshotDirMaps) {
String writerPath = writer.getPath();
for (Map.Entry<String, String> entry : snapshotDirMaps.entrySet()) {
String snapshotDir = entry.getKey();
String diskTableKey = entry.getValue();
String snapshotDirTar = Paths.get(snapshotDir).getFileName().toString() + TAR;
String outputFile = Paths.get(writerPath, snapshotDirTar).toString();
Checksum checksum = new CRC64();
try {
CompressUtil.compressTar(snapshotDir, outputFile, checksum);
} catch (Throwable e) {
throw new RaftException("Failed to compress snapshot, path=%s, files=%s", e, writerPath, snapshotDirMaps.keySet());
}
LocalFileMeta.Builder metaBuilder = LocalFileMeta.newBuilder();
metaBuilder.setChecksum(Long.toHexString(checksum.getValue()));
/*
* snapshot_rocksdb-data.tar -> general
* snapshot_rocksdb-vertex.tar -> g/VERTEX
*/
metaBuilder.setUserMeta(ByteString.copyFromUtf8(diskTableKey));
if (!writer.addFile(snapshotDirTar, metaBuilder.build())) {
throw new RaftException("Failed to add snapshot file: '%s'", snapshotDirTar);
}
}
}
use of com.alipay.sofa.jraft.util.CRC64 in project incubator-hugegraph by apache.
the class CompressUtilTest method testTarCompress.
@Test
public void testTarCompress() throws IOException {
String rootDir = "temp";
// temp/ss
String sourceDir = rootDir + "/ss";
String tarFile = "output.tar";
String output = "output";
try {
prepareFiles(sourceDir);
Checksum checksum = new CRC64();
CompressUtil.compressTar(sourceDir, tarFile, checksum);
CompressUtil.decompressTar(tarFile, output, checksum);
assertDirEquals(rootDir, output);
} finally {
FileUtils.deleteQuietly(new File(rootDir));
FileUtils.deleteQuietly(new File(tarFile));
FileUtils.deleteQuietly(new File(output));
}
}
use of com.alipay.sofa.jraft.util.CRC64 in project incubator-hugegraph by apache.
the class CompressUtilTest method testZipCompress.
@Test
public void testZipCompress() throws IOException {
String rootDir = "temp";
// temp/ss
String sourceDir = "ss";
String zipFile = "output.zip";
String output = "output";
try {
prepareFiles(Paths.get(rootDir, sourceDir).toString());
Checksum checksum = new CRC64();
CompressUtil.compressZip(rootDir, sourceDir, zipFile, checksum);
CompressUtil.decompressZip(zipFile, output, checksum);
assertDirEquals(rootDir, output);
} finally {
FileUtils.deleteQuietly(new File(rootDir));
FileUtils.deleteQuietly(new File(zipFile));
FileUtils.deleteQuietly(new File(output));
}
}
Aggregations