Search in sources :

Example 1 with RestoreOptions

use of org.rocksdb.RestoreOptions in project yamcs by yamcs.

the class RDBFactory method restoreBackup.

public CompletableFuture<Void> restoreBackup(int backupId, String backupDir, String relativePath) {
    CompletableFuture<Void> cf = new CompletableFuture<>();
    executor.execute(() -> {
        try (BackupableDBOptions opt = new BackupableDBOptions(backupDir);
            BackupEngine backupEngine = BackupEngine.open(Env.getDefault(), opt);
            RestoreOptions restoreOpt = new RestoreOptions(false)) {
            String absolutePath = getAbsolutePath(relativePath);
            if (backupId == -1) {
                backupEngine.restoreDbFromLatestBackup(absolutePath, absolutePath, restoreOpt);
            } else {
                backupEngine.restoreDbFromBackup(backupId, absolutePath, absolutePath, restoreOpt);
            }
            cf.complete(null);
        } catch (Exception e) {
            cf.completeExceptionally(e);
        } finally {
        }
    });
    return cf;
}
Also used : BackupEngine(org.rocksdb.BackupEngine) RestoreOptions(org.rocksdb.RestoreOptions) CompletableFuture(java.util.concurrent.CompletableFuture) BackupableDBOptions(org.rocksdb.BackupableDBOptions) IOException(java.io.IOException) RocksDBException(org.rocksdb.RocksDBException)

Example 2 with RestoreOptions

use of org.rocksdb.RestoreOptions in project yamcs by yamcs.

the class RDBFactory method restoreBackup.

public CompletableFuture<Void> restoreBackup(String backupDir, String relativePath) {
    CompletableFuture<Void> cf = new CompletableFuture<>();
    executor.execute(() -> {
        try (BackupableDBOptions opt = new BackupableDBOptions(backupDir);
            BackupEngine backupEngine = BackupEngine.open(Env.getDefault(), opt);
            RestoreOptions restoreOpt = new RestoreOptions(false)) {
            String absolutePath = getAbsolutePath(relativePath);
            backupEngine.restoreDbFromLatestBackup(absolutePath, absolutePath, restoreOpt);
            cf.complete(null);
        } catch (Exception e) {
            cf.completeExceptionally(e);
        } finally {
        }
    });
    return cf;
}
Also used : BackupEngine(org.rocksdb.BackupEngine) RestoreOptions(org.rocksdb.RestoreOptions) CompletableFuture(java.util.concurrent.CompletableFuture) BackupableDBOptions(org.rocksdb.BackupableDBOptions) IOException(java.io.IOException) RocksDBException(org.rocksdb.RocksDBException)

Example 3 with RestoreOptions

use of org.rocksdb.RestoreOptions in project dingo by dingodb.

the class RocksRawKVStore method restoreBackup.

public void restoreBackup(final String backupDBPath, final RocksDBBackupInfo rocksBackupInfo) {
    final Timer.Context timeCtx = getTimeContext("RESTORE_BACKUP");
    final Lock writeLock = this.readWriteLock.writeLock();
    writeLock.lock();
    closeRocksDB();
    try (final BackupableDBOptions backupOpts = createBackupDBOptions(backupDBPath);
        final BackupEngine backupEngine = BackupEngine.open(this.options.getEnv(), backupOpts);
        final RestoreOptions restoreOpts = new RestoreOptions(false)) {
        final String dbPath = this.opts.getDataPath();
        backupEngine.restoreDbFromBackup(rocksBackupInfo.getBackupId(), dbPath, dbPath, restoreOpts);
        LOG.info("Restored rocksDB from {} with {}.", backupDBPath, rocksBackupInfo);
        // reopen the db
        openRocksDB(this.opts);
    } catch (final RocksDBException e) {
        throw new StorageException("Fail to restore from path: " + backupDBPath, e);
    } finally {
        writeLock.unlock();
        timeCtx.stop();
    }
}
Also used : BackupEngine(org.rocksdb.BackupEngine) RestoreOptions(org.rocksdb.RestoreOptions) RocksDBException(org.rocksdb.RocksDBException) Timer(com.codahale.metrics.Timer) BackupableDBOptions(org.rocksdb.BackupableDBOptions) StorageException(io.dingodb.store.row.errors.StorageException) DistributedLock(io.dingodb.store.row.util.concurrent.DistributedLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 4 with RestoreOptions

use of org.rocksdb.RestoreOptions in project sofa-jraft by sofastack.

the class RocksRawKVStore method restoreBackup.

void restoreBackup(final String backupDBPath, final RocksDBBackupInfo rocksBackupInfo) {
    final Timer.Context timeCtx = getTimeContext("RESTORE_BACKUP");
    final Lock writeLock = this.readWriteLock.writeLock();
    writeLock.lock();
    closeRocksDB();
    try (final BackupableDBOptions backupOpts = createBackupDBOptions(backupDBPath);
        final BackupEngine backupEngine = BackupEngine.open(this.options.getEnv(), backupOpts);
        final RestoreOptions restoreOpts = new RestoreOptions(false)) {
        final String dbPath = this.opts.getDbPath();
        backupEngine.restoreDbFromBackup(rocksBackupInfo.getBackupId(), dbPath, dbPath, restoreOpts);
        LOG.info("Restored rocksDB from {} with {}.", backupDBPath, rocksBackupInfo);
        // reopen the db
        openRocksDB(this.opts);
    } catch (final RocksDBException e) {
        throw new StorageException("Fail to restore from path: " + backupDBPath, e);
    } finally {
        writeLock.unlock();
        timeCtx.stop();
    }
}
Also used : BackupEngine(org.rocksdb.BackupEngine) RestoreOptions(org.rocksdb.RestoreOptions) RocksDBException(org.rocksdb.RocksDBException) Timer(com.codahale.metrics.Timer) BackupableDBOptions(org.rocksdb.BackupableDBOptions) StorageException(com.alipay.sofa.jraft.rhea.errors.StorageException) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) DistributedLock(com.alipay.sofa.jraft.rhea.util.concurrent.DistributedLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 5 with RestoreOptions

use of org.rocksdb.RestoreOptions in project xdagj by XDagger.

the class RocksdbKVSource method init.

@Override
public void init() {
    resetDbLock.writeLock().lock();
    try {
        log.debug("~> RocksdbKVSource.init(): " + name);
        if (isAlive()) {
            return;
        }
        if (name == null) {
            throw new NullPointerException("no name set to the db");
        }
        try (Options options = new Options()) {
            // most of these options are suggested by
            // https://github.com/facebook/rocksdb/wiki/Set-Up-Options
            // general options
            options.setCreateIfMissing(true);
            options.setCompressionType(CompressionType.LZ4_COMPRESSION);
            options.setBottommostCompressionType(CompressionType.LZ4_COMPRESSION);
            options.setLevelCompactionDynamicLevelBytes(true);
            options.setMaxOpenFiles(config.getNodeSpec().getStoreMaxOpenFiles());
            options.setIncreaseParallelism(config.getNodeSpec().getStoreMaxThreads());
            // key prefix for state node lookups
            options.useFixedLengthPrefixExtractor(prefixSeekLength);
            // table options
            final BlockBasedTableConfig tableCfg;
            options.setTableFormatConfig(tableCfg = new BlockBasedTableConfig());
            tableCfg.setBlockSize(16 * 1024);
            tableCfg.setBlockCache(new LRUCache(32 * 1024 * 1024));
            tableCfg.setCacheIndexAndFilterBlocks(true);
            tableCfg.setPinL0FilterAndIndexBlocksInCache(true);
            tableCfg.setFilter(new BloomFilter(10, false));
            // read options
            readOpts = new ReadOptions();
            readOpts = readOpts.setPrefixSameAsStart(true).setVerifyChecksums(false);
            try {
                log.info("Opening database");
                final Path dbPath = getPath();
                if (!Files.isSymbolicLink(dbPath.getParent())) {
                    Files.createDirectories(dbPath.getParent());
                }
                if (config.getNodeSpec().isStoreFromBackup() && backupPath().toFile().canWrite()) {
                    log.debug("Restoring database from backup: '{}'", name);
                    try (BackupableDBOptions backupOptions = new BackupableDBOptions(backupPath().toString());
                        RestoreOptions restoreOptions = new RestoreOptions(false);
                        BackupEngine backups = BackupEngine.open(Env.getDefault(), backupOptions)) {
                        if (!backups.getBackupInfo().isEmpty()) {
                            backups.restoreDbFromLatestBackup(getPath().toString(), getPath().toString(), restoreOptions);
                        }
                    } catch (RocksDBException e) {
                        log.error("Failed to restore database '{}' from backup", name, e);
                    }
                }
                log.debug("Initializing new or existing database: '{}'", name);
                try {
                    db = RocksDB.open(options, dbPath.toString());
                } catch (RocksDBException e) {
                    log.error(e.getMessage(), e);
                    throw new RuntimeException("Failed to initialize database", e);
                }
                alive = true;
            } catch (IOException ioe) {
                log.error(ioe.getMessage(), ioe);
                throw new RuntimeException("Failed to initialize database", ioe);
            }
            log.debug("<~ RocksdbKVSource.init(): " + name);
        }
    } finally {
        resetDbLock.writeLock().unlock();
    }
}
Also used : Path(java.nio.file.Path) ReadOptions(org.rocksdb.ReadOptions) BackupableDBOptions(org.rocksdb.BackupableDBOptions) RestoreOptions(org.rocksdb.RestoreOptions) Options(org.rocksdb.Options) RestoreOptions(org.rocksdb.RestoreOptions) RocksDBException(org.rocksdb.RocksDBException) BackupableDBOptions(org.rocksdb.BackupableDBOptions) BlockBasedTableConfig(org.rocksdb.BlockBasedTableConfig) IOException(java.io.IOException) BloomFilter(org.rocksdb.BloomFilter) BackupEngine(org.rocksdb.BackupEngine) LRUCache(org.rocksdb.LRUCache) ReadOptions(org.rocksdb.ReadOptions)

Aggregations

BackupEngine (org.rocksdb.BackupEngine)5 BackupableDBOptions (org.rocksdb.BackupableDBOptions)5 RestoreOptions (org.rocksdb.RestoreOptions)5 RocksDBException (org.rocksdb.RocksDBException)5 IOException (java.io.IOException)3 Timer (com.codahale.metrics.Timer)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Lock (java.util.concurrent.locks.Lock)2 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 StorageException (com.alipay.sofa.jraft.rhea.errors.StorageException)1 DistributedLock (com.alipay.sofa.jraft.rhea.util.concurrent.DistributedLock)1 StorageException (io.dingodb.store.row.errors.StorageException)1 DistributedLock (io.dingodb.store.row.util.concurrent.DistributedLock)1 Path (java.nio.file.Path)1 BlockBasedTableConfig (org.rocksdb.BlockBasedTableConfig)1 BloomFilter (org.rocksdb.BloomFilter)1 LRUCache (org.rocksdb.LRUCache)1 Options (org.rocksdb.Options)1 ReadOptions (org.rocksdb.ReadOptions)1