Search in sources :

Example 16 with CRC64

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;
}
Also used : CRC64(com.alipay.sofa.jraft.util.CRC64) Checksum(java.util.zip.Checksum) LocalFileMeta(org.monkey.mmq.core.consistency.snapshot.LocalFileMeta)

Example 17 with CRC64

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);
        }
    }
}
Also used : CRC64(com.alipay.sofa.jraft.util.CRC64) Checksum(java.util.zip.Checksum) ByteString(com.google.protobuf.ByteString) LocalFileMeta(com.alipay.sofa.jraft.entity.LocalFileMetaOutter.LocalFileMeta) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with CRC64

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));
    }
}
Also used : CRC64(com.alipay.sofa.jraft.util.CRC64) Checksum(java.util.zip.Checksum) File(java.io.File) Test(org.junit.Test)

Example 19 with CRC64

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));
    }
}
Also used : CRC64(com.alipay.sofa.jraft.util.CRC64) Checksum(java.util.zip.Checksum) File(java.io.File) Test(org.junit.Test)

Aggregations

CRC64 (com.alipay.sofa.jraft.util.CRC64)19 Checksum (java.util.zip.Checksum)18 LocalFileMeta (com.alibaba.nacos.consistency.snapshot.LocalFileMeta)6 File (java.io.File)5 Test (org.junit.Test)5 ByteString (com.google.protobuf.ByteString)4 LocalFileMeta (com.alipay.sofa.jraft.entity.LocalFileMetaOutter.LocalFileMeta)3 Path (java.nio.file.Path)3 Lock (java.util.concurrent.locks.Lock)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 LocalFileMeta (org.monkey.mmq.core.consistency.snapshot.LocalFileMeta)2 Status (com.alipay.sofa.jraft.Status)1 RocksRawKVStore (com.alipay.sofa.jraft.rhea.storage.RocksRawKVStore)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1