1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
10 public class OptionsUtil
{
12 * A static method to construct the DBOptions and ColumnFamilyDescriptors by
13 * loading the latest RocksDB options file stored in the specified rocksdb
16 * Note that the all the pointer options (except table_factory, which will
17 * be described in more details below) will be initialized with the default
18 * values. Developers can further initialize them after this function call.
19 * Below is an example list of pointer options which will be initialized.
23 * - compaction_filter_factory
29 * For table_factory, this function further supports deserializing
30 * BlockBasedTableFactory and its BlockBasedTableOptions except the
31 * pointer options of BlockBasedTableOptions (flush_block_policy_factory,
32 * block_cache, and block_cache_compressed), which will be initialized with
33 * default values. Developers can further specify these three options by
34 * casting the return value of TableFactoroy::GetOptions() to
35 * BlockBasedTableOptions and making necessary changes.
37 * @param dbPath the path to the RocksDB.
38 * @param env {@link org.rocksdb.Env} instance.
39 * @param dbOptions {@link org.rocksdb.DBOptions} instance. This will be
40 * filled and returned.
41 * @param cfDescs A list of {@link org.rocksdb.ColumnFamilyDescriptor}'s be
44 * @throws RocksDBException thrown if error happens in underlying
48 public static void loadLatestOptions(String dbPath
, Env env
, DBOptions dbOptions
,
49 List
<ColumnFamilyDescriptor
> cfDescs
) throws RocksDBException
{
50 loadLatestOptions(dbPath
, env
, dbOptions
, cfDescs
, false);
54 * @param dbPath the path to the RocksDB.
55 * @param env {@link org.rocksdb.Env} instance.
56 * @param dbOptions {@link org.rocksdb.DBOptions} instance. This will be
57 * filled and returned.
58 * @param cfDescs A list of {@link org.rocksdb.ColumnFamilyDescriptor}'s be
60 * @param ignoreUnknownOptions this flag can be set to true if you want to
61 * ignore options that are from a newer version of the db, essentially for
62 * forward compatibility.
64 * @throws RocksDBException thrown if error happens in underlying
67 public static void loadLatestOptions(String dbPath
, Env env
, DBOptions dbOptions
,
68 List
<ColumnFamilyDescriptor
> cfDescs
, boolean ignoreUnknownOptions
) throws RocksDBException
{
70 dbPath
, env
.nativeHandle_
, dbOptions
.nativeHandle_
, cfDescs
, ignoreUnknownOptions
);
74 * Similar to LoadLatestOptions, this function constructs the DBOptions
75 * and ColumnFamilyDescriptors based on the specified RocksDB Options file.
76 * See LoadLatestOptions above.
78 * @param dbPath the path to the RocksDB.
79 * @param configOptions {@link org.rocksdb.ConfigOptions} instance.
80 * @param dbOptions {@link org.rocksdb.DBOptions} instance. This will be
81 * filled and returned.
82 * @param cfDescs A list of {@link org.rocksdb.ColumnFamilyDescriptor}'s be
84 * @throws RocksDBException thrown if error happens in underlying
87 public static void loadLatestOptions(ConfigOptions configOptions
, String dbPath
,
88 DBOptions dbOptions
, List
<ColumnFamilyDescriptor
> cfDescs
) throws RocksDBException
{
89 loadLatestOptions(configOptions
.nativeHandle_
, dbPath
, dbOptions
.nativeHandle_
, cfDescs
);
93 * Similar to LoadLatestOptions, this function constructs the DBOptions
94 * and ColumnFamilyDescriptors based on the specified RocksDB Options file.
95 * See LoadLatestOptions above.
97 * @param optionsFileName the RocksDB options file path.
98 * @param env {@link org.rocksdb.Env} instance.
99 * @param dbOptions {@link org.rocksdb.DBOptions} instance. This will be
100 * filled and returned.
101 * @param cfDescs A list of {@link org.rocksdb.ColumnFamilyDescriptor}'s be
104 * @throws RocksDBException thrown if error happens in underlying
107 public static void loadOptionsFromFile(String optionsFileName
, Env env
, DBOptions dbOptions
,
108 List
<ColumnFamilyDescriptor
> cfDescs
) throws RocksDBException
{
109 loadOptionsFromFile(optionsFileName
, env
, dbOptions
, cfDescs
, false);
113 * @param optionsFileName the RocksDB options file path.
114 * @param env {@link org.rocksdb.Env} instance.
115 * @param dbOptions {@link org.rocksdb.DBOptions} instance. This will be
116 * filled and returned.
117 * @param cfDescs A list of {@link org.rocksdb.ColumnFamilyDescriptor}'s be
119 * @param ignoreUnknownOptions this flag can be set to true if you want to
120 * ignore options that are from a newer version of the db, esentially for
121 * forward compatibility.
123 * @throws RocksDBException thrown if error happens in underlying
126 public static void loadOptionsFromFile(String optionsFileName
, Env env
, DBOptions dbOptions
,
127 List
<ColumnFamilyDescriptor
> cfDescs
, boolean ignoreUnknownOptions
) throws RocksDBException
{
129 optionsFileName
, env
.nativeHandle_
, dbOptions
.nativeHandle_
, cfDescs
, ignoreUnknownOptions
);
133 * Similar to LoadLatestOptions, this function constructs the DBOptions
134 * and ColumnFamilyDescriptors based on the specified RocksDB Options file.
135 * See LoadLatestOptions above.
137 * @param optionsFileName the RocksDB options file path.
138 * @param configOptions {@link org.rocksdb.ConfigOptions} instance.
139 * @param dbOptions {@link org.rocksdb.DBOptions} instance. This will be
140 * filled and returned.
141 * @param cfDescs A list of {@link org.rocksdb.ColumnFamilyDescriptor}'s be
143 * @throws RocksDBException thrown if error happens in underlying
146 public static void loadOptionsFromFile(ConfigOptions configOptions
, String optionsFileName
,
147 DBOptions dbOptions
, List
<ColumnFamilyDescriptor
> cfDescs
) throws RocksDBException
{
149 configOptions
.nativeHandle_
, optionsFileName
, dbOptions
.nativeHandle_
, cfDescs
);
153 * Returns the latest options file name under the specified RocksDB path.
155 * @param dbPath the path to the RocksDB.
156 * @param env {@link org.rocksdb.Env} instance.
157 * @return the latest options file name under the db path.
159 * @throws RocksDBException thrown if error happens in underlying
162 public static String
getLatestOptionsFileName(String dbPath
, Env env
) throws RocksDBException
{
163 return getLatestOptionsFileName(dbPath
, env
.nativeHandle_
);
167 * Private constructor.
168 * This class has only static methods and shouldn't be instantiated.
170 private OptionsUtil() {}
173 private native static void loadLatestOptions(String dbPath
, long envHandle
, long dbOptionsHandle
,
174 List
<ColumnFamilyDescriptor
> cfDescs
, boolean ignoreUnknownOptions
) throws RocksDBException
;
175 private native static void loadLatestOptions(long cfgHandle
, String dbPath
, long dbOptionsHandle
,
176 List
<ColumnFamilyDescriptor
> cfDescs
) throws RocksDBException
;
177 private native static void loadOptionsFromFile(String optionsFileName
, long envHandle
,
178 long dbOptionsHandle
, List
<ColumnFamilyDescriptor
> cfDescs
, boolean ignoreUnknownOptions
)
179 throws RocksDBException
;
180 private native static void loadOptionsFromFile(long cfgHandle
, String optionsFileName
,
181 long dbOptionsHandle
, List
<ColumnFamilyDescriptor
> cfDescs
) throws RocksDBException
;
182 private native static String
getLatestOptionsFileName(String dbPath
, long envHandle
)
183 throws RocksDBException
;