use of org.rocksdb.BackupInfo in project sofa-jraft by sofastack.
the class RocksRawKVStore method backupDB.
RocksDBBackupInfo backupDB(final String backupDBPath) throws IOException {
final Timer.Context timeCtx = getTimeContext("BACKUP_DB");
FileUtils.forceMkdir(new File(backupDBPath));
final Lock writeLock = this.readWriteLock.writeLock();
writeLock.lock();
try (final BackupableDBOptions backupOpts = createBackupDBOptions(backupDBPath);
final BackupEngine backupEngine = BackupEngine.open(this.options.getEnv(), backupOpts)) {
backupEngine.createNewBackup(this.db, true);
final List<BackupInfo> backupInfoList = backupEngine.getBackupInfo();
if (backupInfoList.isEmpty()) {
LOG.warn("Fail to backup at {}, empty backup info.", backupDBPath);
return null;
}
// chose the backupInfo who has max backupId
final BackupInfo backupInfo = Collections.max(backupInfoList, Comparator.comparingInt(BackupInfo::backupId));
final RocksDBBackupInfo rocksBackupInfo = new RocksDBBackupInfo(backupInfo);
LOG.info("Backup rocksDB into {} with backupInfo {}.", backupDBPath, rocksBackupInfo);
return rocksBackupInfo;
} catch (final RocksDBException e) {
throw new StorageException("Fail to backup at path: " + backupDBPath, e);
} finally {
writeLock.unlock();
timeCtx.stop();
}
}
use of org.rocksdb.BackupInfo in project dingo by dingodb.
the class RocksRawKVStore method backupDB.
public RocksDBBackupInfo backupDB(final String backupDBPath) throws IOException {
final Timer.Context timeCtx = getTimeContext("BACKUP_DB");
FileUtils.forceMkdir(new File(backupDBPath));
final Lock writeLock = this.readWriteLock.writeLock();
writeLock.lock();
try (final BackupableDBOptions backupOpts = createBackupDBOptions(backupDBPath);
final BackupEngine backupEngine = BackupEngine.open(this.options.getEnv(), backupOpts)) {
backupEngine.createNewBackup(this.db, true);
final List<BackupInfo> backupInfoList = backupEngine.getBackupInfo();
if (backupInfoList.isEmpty()) {
LOG.warn("Fail to backup at {}, empty backup info.", backupDBPath);
return null;
}
// chose the backupInfo who has max backupId
final BackupInfo backupInfo = Collections.max(backupInfoList, Comparator.comparingInt(BackupInfo::backupId));
final RocksDBBackupInfo rocksBackupInfo = new RocksDBBackupInfo(backupInfo);
LOG.info("Backup rocksDB into {} with backupInfo {}.", backupDBPath, rocksBackupInfo);
return rocksBackupInfo;
} catch (final RocksDBException e) {
throw new StorageException("Fail to backup at path: " + backupDBPath, e);
} finally {
writeLock.unlock();
timeCtx.stop();
}
}
Aggregations