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;
}
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;
}
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();
}
}
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();
}
}
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();
}
}
Aggregations