|
|
@ -329,10 +329,61 @@ public class RocksDB extends RocksObject { |
|
|
|
throws RocksDBException { |
|
|
|
throws RocksDBException { |
|
|
|
// This allows to use the rocksjni default Options instead of
|
|
|
|
// This allows to use the rocksjni default Options instead of
|
|
|
|
// the c++ one.
|
|
|
|
// the c++ one.
|
|
|
|
Options options = new Options(); |
|
|
|
final Options options = new Options(); |
|
|
|
return openReadOnly(options, path); |
|
|
|
return openReadOnly(options, path); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* The factory constructor of RocksDB that opens a RocksDB instance in |
|
|
|
|
|
|
|
* Read-Only mode given the path to the database using the specified |
|
|
|
|
|
|
|
* options and db path. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* Options instance *should* not be disposed before all DBs using this options |
|
|
|
|
|
|
|
* instance have been closed. If user doesn't call options dispose explicitly, |
|
|
|
|
|
|
|
* then this options instance will be GC'd automatically. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param options {@link Options} instance. |
|
|
|
|
|
|
|
* @param path the path to the RocksDB. |
|
|
|
|
|
|
|
* @return a {@link RocksDB} instance on success, null if the specified |
|
|
|
|
|
|
|
* {@link RocksDB} can not be opened. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @throws RocksDBException thrown if error happens in underlying |
|
|
|
|
|
|
|
* native library. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static RocksDB openReadOnly(final Options options, final String path) |
|
|
|
|
|
|
|
throws RocksDBException { |
|
|
|
|
|
|
|
return openReadOnly(options, path, false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* The factory constructor of RocksDB that opens a RocksDB instance in |
|
|
|
|
|
|
|
* Read-Only mode given the path to the database using the specified |
|
|
|
|
|
|
|
* options and db path. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* Options instance *should* not be disposed before all DBs using this options |
|
|
|
|
|
|
|
* instance have been closed. If user doesn't call options dispose explicitly, |
|
|
|
|
|
|
|
* then this options instance will be GC'd automatically. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param options {@link Options} instance. |
|
|
|
|
|
|
|
* @param path the path to the RocksDB. |
|
|
|
|
|
|
|
* @param errorIfWalFileExists true to raise an error when opening the db |
|
|
|
|
|
|
|
* if a Write Ahead Log file exists, false otherwise. |
|
|
|
|
|
|
|
* @return a {@link RocksDB} instance on success, null if the specified |
|
|
|
|
|
|
|
* {@link RocksDB} can not be opened. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @throws RocksDBException thrown if error happens in underlying |
|
|
|
|
|
|
|
* native library. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static RocksDB openReadOnly(final Options options, final String path, |
|
|
|
|
|
|
|
final boolean errorIfWalFileExists) throws RocksDBException { |
|
|
|
|
|
|
|
// when non-default Options is used, keeping an Options reference
|
|
|
|
|
|
|
|
// in RocksDB can prevent Java to GC during the life-time of
|
|
|
|
|
|
|
|
// the currently-created RocksDB.
|
|
|
|
|
|
|
|
final RocksDB db = new RocksDB(openROnly(options.nativeHandle_, path, errorIfWalFileExists)); |
|
|
|
|
|
|
|
db.storeOptionsInstance(options); |
|
|
|
|
|
|
|
return db; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The factory constructor of RocksDB that opens a RocksDB instance in |
|
|
|
* The factory constructor of RocksDB that opens a RocksDB instance in |
|
|
|
* Read-Only mode given the path to the database using the default |
|
|
|
* Read-Only mode given the path to the database using the default |
|
|
@ -355,8 +406,7 @@ public class RocksDB extends RocksObject { |
|
|
|
// This allows to use the rocksjni default Options instead of
|
|
|
|
// This allows to use the rocksjni default Options instead of
|
|
|
|
// the c++ one.
|
|
|
|
// the c++ one.
|
|
|
|
final DBOptions options = new DBOptions(); |
|
|
|
final DBOptions options = new DBOptions(); |
|
|
|
return openReadOnly(options, path, columnFamilyDescriptors, |
|
|
|
return openReadOnly(options, path, columnFamilyDescriptors, columnFamilyHandles, false); |
|
|
|
columnFamilyHandles); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -364,26 +414,27 @@ public class RocksDB extends RocksObject { |
|
|
|
* Read-Only mode given the path to the database using the specified |
|
|
|
* Read-Only mode given the path to the database using the specified |
|
|
|
* options and db path. |
|
|
|
* options and db path. |
|
|
|
* |
|
|
|
* |
|
|
|
* Options instance *should* not be disposed before all DBs using this options |
|
|
|
* <p>This open method allows to open RocksDB using a subset of available |
|
|
|
* instance have been closed. If user doesn't call options dispose explicitly, |
|
|
|
* column families</p> |
|
|
|
* then this options instance will be GC'd automatically. |
|
|
|
* <p>Options instance *should* not be disposed before all DBs using this |
|
|
|
|
|
|
|
* options instance have been closed. If user doesn't call options dispose |
|
|
|
|
|
|
|
* explicitly,then this options instance will be GC'd automatically.</p> |
|
|
|
* |
|
|
|
* |
|
|
|
* @param options {@link Options} instance. |
|
|
|
* @param options {@link DBOptions} instance. |
|
|
|
* @param path the path to the RocksDB. |
|
|
|
* @param path the path to the RocksDB. |
|
|
|
|
|
|
|
* @param columnFamilyDescriptors list of column family descriptors |
|
|
|
|
|
|
|
* @param columnFamilyHandles will be filled with ColumnFamilyHandle instances |
|
|
|
|
|
|
|
* on open. |
|
|
|
* @return a {@link RocksDB} instance on success, null if the specified |
|
|
|
* @return a {@link RocksDB} instance on success, null if the specified |
|
|
|
* {@link RocksDB} can not be opened. |
|
|
|
* {@link RocksDB} can not be opened. |
|
|
|
* |
|
|
|
* |
|
|
|
* @throws RocksDBException thrown if error happens in underlying |
|
|
|
* @throws RocksDBException thrown if error happens in underlying |
|
|
|
* native library. |
|
|
|
* native library. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static RocksDB openReadOnly(final Options options, final String path) |
|
|
|
public static RocksDB openReadOnly(final DBOptions options, final String path, |
|
|
|
throws RocksDBException { |
|
|
|
final List<ColumnFamilyDescriptor> columnFamilyDescriptors, |
|
|
|
// when non-default Options is used, keeping an Options reference
|
|
|
|
final List<ColumnFamilyHandle> columnFamilyHandles) throws RocksDBException { |
|
|
|
// in RocksDB can prevent Java to GC during the life-time of
|
|
|
|
return openReadOnly(options, path, columnFamilyDescriptors, columnFamilyHandles, false); |
|
|
|
// the currently-created RocksDB.
|
|
|
|
|
|
|
|
final RocksDB db = new RocksDB(openROnly(options.nativeHandle_, path)); |
|
|
|
|
|
|
|
db.storeOptionsInstance(options); |
|
|
|
|
|
|
|
return db; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -402,6 +453,8 @@ public class RocksDB extends RocksObject { |
|
|
|
* @param columnFamilyDescriptors list of column family descriptors |
|
|
|
* @param columnFamilyDescriptors list of column family descriptors |
|
|
|
* @param columnFamilyHandles will be filled with ColumnFamilyHandle instances |
|
|
|
* @param columnFamilyHandles will be filled with ColumnFamilyHandle instances |
|
|
|
* on open. |
|
|
|
* on open. |
|
|
|
|
|
|
|
* @param errorIfWalFileExists true to raise an error when opening the db |
|
|
|
|
|
|
|
* if a Write Ahead Log file exists, false otherwise. |
|
|
|
* @return a {@link RocksDB} instance on success, null if the specified |
|
|
|
* @return a {@link RocksDB} instance on success, null if the specified |
|
|
|
* {@link RocksDB} can not be opened. |
|
|
|
* {@link RocksDB} can not be opened. |
|
|
|
* |
|
|
|
* |
|
|
@ -410,7 +463,7 @@ public class RocksDB extends RocksObject { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static RocksDB openReadOnly(final DBOptions options, final String path, |
|
|
|
public static RocksDB openReadOnly(final DBOptions options, final String path, |
|
|
|
final List<ColumnFamilyDescriptor> columnFamilyDescriptors, |
|
|
|
final List<ColumnFamilyDescriptor> columnFamilyDescriptors, |
|
|
|
final List<ColumnFamilyHandle> columnFamilyHandles) |
|
|
|
final List<ColumnFamilyHandle> columnFamilyHandles, final boolean errorIfWalFileExists) |
|
|
|
throws RocksDBException { |
|
|
|
throws RocksDBException { |
|
|
|
// when non-default Options is used, keeping an Options reference
|
|
|
|
// when non-default Options is used, keeping an Options reference
|
|
|
|
// in RocksDB can prevent Java to GC during the life-time of
|
|
|
|
// in RocksDB can prevent Java to GC during the life-time of
|
|
|
@ -425,8 +478,8 @@ public class RocksDB extends RocksObject { |
|
|
|
cfOptionHandles[i] = cfDescriptor.getOptions().nativeHandle_; |
|
|
|
cfOptionHandles[i] = cfDescriptor.getOptions().nativeHandle_; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final long[] handles = openROnly(options.nativeHandle_, path, cfNames, |
|
|
|
final long[] handles = |
|
|
|
cfOptionHandles); |
|
|
|
openROnly(options.nativeHandle_, path, cfNames, cfOptionHandles, errorIfWalFileExists); |
|
|
|
final RocksDB db = new RocksDB(handles[0]); |
|
|
|
final RocksDB db = new RocksDB(handles[0]); |
|
|
|
db.storeOptionsInstance(options); |
|
|
|
db.storeOptionsInstance(options); |
|
|
|
|
|
|
|
|
|
|
@ -4381,8 +4434,8 @@ public class RocksDB extends RocksObject { |
|
|
|
final String path, final byte[][] columnFamilyNames, |
|
|
|
final String path, final byte[][] columnFamilyNames, |
|
|
|
final long[] columnFamilyOptions) throws RocksDBException; |
|
|
|
final long[] columnFamilyOptions) throws RocksDBException; |
|
|
|
|
|
|
|
|
|
|
|
private native static long openROnly(final long optionsHandle, |
|
|
|
private native static long openROnly(final long optionsHandle, final String path, |
|
|
|
final String path) throws RocksDBException; |
|
|
|
final boolean errorIfWalFileExists) throws RocksDBException; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param optionsHandle Native handle pointing to an Options object |
|
|
|
* @param optionsHandle Native handle pointing to an Options object |
|
|
@ -4396,10 +4449,9 @@ public class RocksDB extends RocksObject { |
|
|
|
* |
|
|
|
* |
|
|
|
* @throws RocksDBException thrown if the database could not be opened |
|
|
|
* @throws RocksDBException thrown if the database could not be opened |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private native static long[] openROnly(final long optionsHandle, |
|
|
|
private native static long[] openROnly(final long optionsHandle, final String path, |
|
|
|
final String path, final byte[][] columnFamilyNames, |
|
|
|
final byte[][] columnFamilyNames, final long[] columnFamilyOptions, |
|
|
|
final long[] columnFamilyOptions |
|
|
|
final boolean errorIfWalFileExists) throws RocksDBException; |
|
|
|
) throws RocksDBException; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private native static long openAsSecondary(final long optionsHandle, final String path, |
|
|
|
private native static long openAsSecondary(final long optionsHandle, final String path, |
|
|
|
final String secondaryPath) throws RocksDBException; |
|
|
|
final String secondaryPath) throws RocksDBException; |
|
|
|