Search in sources :

Example 1 with BackupInfo

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();
    }
}
Also used : BackupInfo(org.rocksdb.BackupInfo) BackupEngine(org.rocksdb.BackupEngine) RocksDBException(org.rocksdb.RocksDBException) Timer(com.codahale.metrics.Timer) BackupableDBOptions(org.rocksdb.BackupableDBOptions) File(java.io.File) 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 2 with BackupInfo

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();
    }
}
Also used : BackupInfo(org.rocksdb.BackupInfo) BackupEngine(org.rocksdb.BackupEngine) RocksDBException(org.rocksdb.RocksDBException) Timer(com.codahale.metrics.Timer) BackupableDBOptions(org.rocksdb.BackupableDBOptions) File(java.io.File) 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)

Aggregations

Timer (com.codahale.metrics.Timer)2 File (java.io.File)2 Lock (java.util.concurrent.locks.Lock)2 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 BackupEngine (org.rocksdb.BackupEngine)2 BackupInfo (org.rocksdb.BackupInfo)2 BackupableDBOptions (org.rocksdb.BackupableDBOptions)2 RocksDBException (org.rocksdb.RocksDBException)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