CompletableFuture<Void> writeSstSnapshot(final String snapshotPath, final Region region, final ExecutorService executor) {
        final Timer.Context timeCtx = getTimeContext("WRITE_SST_SNAPSHOT");
        final Lock readLock = this.readWriteLock.readLock();
        readLock.lock();
        try {
            final String tempPath = snapshotPath + "_temp";
            final File tempFile = new File(tempPath);
            FileUtils.deleteDirectory(tempFile);
            FileUtils.forceMkdir(tempFile);

            final EnumMap<SstColumnFamily, File> sstFileTable = getSstFileTable(tempPath);
            final CompletableFuture<Void> snapshotFuture = new CompletableFuture<>();
            final CompletableFuture<Void> sstFuture = createSstFiles(sstFileTable, region.getStartKey(),
                region.getEndKey(), executor);
            sstFuture.whenComplete((aVoid, throwable) -> {
                if (throwable == null) {
                    try {
                        final File snapshotFile = new File(snapshotPath);
                        FileUtils.deleteDirectory(snapshotFile);
                        if (!Utils.atomicMoveFile(tempFile, snapshotFile, true)) {
                            throw new StorageException("Fail to rename [" + tempPath + "] to [" + snapshotPath + "].");
                        }
                        snapshotFuture.complete(null);
                    } catch (final Throwable t) {
                        snapshotFuture.completeExceptionally(t);
                    }
                } else {
                    snapshotFuture.completeExceptionally(throwable);
                }
            });
            return snapshotFuture;
        } catch (final Exception e) {
            throw new StorageException("Fail to do read sst snapshot at path: " + snapshotPath, e);
        } finally {
            readLock.unlock();
            timeCtx.stop();
        }
    }
Local KV store based on RocksDB

@author dennis
@author jiachun.fjc
jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/storage/RocksRawKVStore.java