All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.rocksdb.BackupableDB Maven / Gradle / Ivy

Go to download

RocksDB fat jar to use with Apache Flink that contains .so files for linux32 and linux64, jnilib files for Mac OSX, and a .dll for Windows x64.

There is a newer version: 5.17.2-artisans-2.0
Show newest version
// Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.

package org.rocksdb;

import java.util.List;

/**
 * 

A subclass of RocksDB which supports * backup-related operations.

* * @see org.rocksdb.BackupableDBOptions */ public class BackupableDB extends RocksDB { /** *

Open a {@code BackupableDB} under the specified path. * Note that the backup path should be set properly in the * input BackupableDBOptions.

* * @param opt {@link org.rocksdb.Options} to set for the database. * @param bopt {@link org.rocksdb.BackupableDBOptions} to use. * @param db_path Path to store data to. The path for storing the backup * should be specified in the {@link org.rocksdb.BackupableDBOptions}. * * @return {@link BackupableDB} reference to the opened database. * * @throws RocksDBException thrown if error happens in underlying * native library. */ public static BackupableDB open( final Options opt, final BackupableDBOptions bopt, final String db_path) throws RocksDBException { final RocksDB db = RocksDB.open(opt, db_path); final BackupableDB bdb = new BackupableDB(open(db.nativeHandle_, bopt.nativeHandle_)); // Prevent the RocksDB object from attempting to delete // the underly C++ DB object. db.disOwnNativeHandle(); return bdb; } /** *

Captures the state of the database in the latest backup. * Note that this function is not thread-safe.

* * @param flushBeforeBackup if true, then all data will be flushed * before creating backup. * * @throws RocksDBException thrown if error happens in underlying * native library. */ public void createNewBackup(final boolean flushBeforeBackup) throws RocksDBException { assert(isOwningHandle()); createNewBackup(nativeHandle_, flushBeforeBackup); } /** *

Deletes old backups, keeping latest numBackupsToKeep alive.

* * @param numBackupsToKeep Number of latest backups to keep. * * @throws RocksDBException thrown if error happens in underlying * native library. */ public void purgeOldBackups(final int numBackupsToKeep) throws RocksDBException { assert(isOwningHandle()); purgeOldBackups(nativeHandle_, numBackupsToKeep); } /** *

Deletes a specific backup.

* * @param backupId of backup to delete. * * @throws RocksDBException thrown if error happens in underlying * native library. */ public void deleteBackup(final int backupId) throws RocksDBException { assert(isOwningHandle()); deleteBackup0(nativeHandle_, backupId); } /** *

Returns a list of {@link BackupInfo} instances, which describe * already made backups.

* * @return List of {@link BackupInfo} instances. */ public List getBackupInfos() { assert(isOwningHandle()); return getBackupInfo(nativeHandle_); } /** *

Returns a list of corrupted backup ids. If there * is no corrupted backup the method will return an * empty list.

* * @return array of backup ids as int ids. */ public int[] getCorruptedBackups() { assert(isOwningHandle()); return getCorruptedBackups(nativeHandle_); } /** *

Will delete all the files we don't need anymore. It will * do the full scan of the files/ directory and delete all the * files that are not referenced.

* * @throws RocksDBException thrown if error happens in underlying * native library. */ public void garbageCollect() throws RocksDBException { assert(isOwningHandle()); garbageCollect(nativeHandle_); } /** *

Close the BackupableDB instance and release resource.

* *

Internally, {@link BackupableDB} owns the {@code rocksdb::DB} * pointer to its associated {@link org.rocksdb.RocksDB}. * The release of that RocksDB pointer is handled in the destructor * of the c++ {@code rocksdb::BackupableDB} and should be transparent * to Java developers.

*/ @Override public void close() { super.close(); } /** *

A protected construction that will be used in the static * factory method {@link #open(Options, BackupableDBOptions, String)}. *

* * @param nativeHandle The native handle of the C++ BackupableDB object */ protected BackupableDB(final long nativeHandle) { super(nativeHandle); } @Override protected void finalize() throws Throwable { close(); super.finalize(); } protected native static long open(final long rocksDBHandle, final long backupDBOptionsHandle); protected native void createNewBackup(long handle, boolean flag) throws RocksDBException; protected native void purgeOldBackups(long handle, int numBackupsToKeep) throws RocksDBException; private native void deleteBackup0(long nativeHandle, int backupId) throws RocksDBException; protected native List getBackupInfo(long handle); private native int[] getCorruptedBackups(long handle); private native void garbageCollect(long handle) throws RocksDBException; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy