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).
8 import java
.util
.ArrayList
;
11 public class OptionsUtil
{
13 * A static method to construct the DBOptions and ColumnFamilyDescriptors by
14 * loading the latest RocksDB options file stored in the specified rocksdb
17 * Note that the all the pointer options (except table_factory, which will
18 * be described in more details below) will be initialized with the default
19 * values. Developers can further initialize them after this function call.
20 * Below is an example list of pointer options which will be initialized.
24 * - compaction_filter_factory
30 * For table_factory, this function further supports deserializing
31 * BlockBasedTableFactory and its BlockBasedTableOptions except the
32 * pointer options of BlockBasedTableOptions (flush_block_policy_factory,
33 * block_cache, and block_cache_compressed), which will be initialized with
34 * default values. Developers can further specify these three options by
35 * casting the return value of TableFactoroy::GetOptions() to
36 * BlockBasedTableOptions and making necessary changes.
38 * @param dbPath the path to the RocksDB.
39 * @param env {@link org.rocksdb.Env} instance.
40 * @param dbOptions {@link org.rocksdb.DBOptions} instance. This will be
41 * filled and returned.
42 * @param cfDescs A list of {@link org.rocksdb.ColumnFamilyDescriptor}'s be
45 * @throws RocksDBException thrown if error happens in underlying
49 public static void loadLatestOptions(String dbPath
, Env env
, DBOptions dbOptions
,
50 List
<ColumnFamilyDescriptor
> cfDescs
) throws RocksDBException
{
51 loadLatestOptions(dbPath
, env
, dbOptions
, cfDescs
, false);
55 * @param dbPath the path to the RocksDB.
56 * @param env {@link org.rocksdb.Env} instance.
57 * @param dbOptions {@link org.rocksdb.DBOptions} instance. This will be
58 * filled and returned.
59 * @param cfDescs A list of {@link org.rocksdb.ColumnFamilyDescriptor}'s be
61 * @param ignoreUnknownOptions this flag can be set to true if you want to
62 * ignore options that are from a newer version of the db, essentially for
63 * forward compatibility.
65 * @throws RocksDBException thrown if error happens in underlying
68 public static void loadLatestOptions(String dbPath
, Env env
, DBOptions dbOptions
,
69 List
<ColumnFamilyDescriptor
> cfDescs
, boolean ignoreUnknownOptions
) throws RocksDBException
{
71 dbPath
, env
.nativeHandle_
, dbOptions
.nativeHandle_
, cfDescs
, ignoreUnknownOptions
);
75 * Similar to LoadLatestOptions, this function constructs the DBOptions
76 * and ColumnFamilyDescriptors based on the specified RocksDB Options file.
77 * See LoadLatestOptions above.
79 * @param dbPath the path to the RocksDB.
80 * @param configOptions {@link org.rocksdb.ConfigOptions} instance.
81 * @param dbOptions {@link org.rocksdb.DBOptions} instance. This will be
82 * filled and returned.
83 * @param cfDescs A list of {@link org.rocksdb.ColumnFamilyDescriptor}'s be
85 * @throws RocksDBException thrown if error happens in underlying
88 public static void loadLatestOptions(ConfigOptions configOptions
, String dbPath
,
89 DBOptions dbOptions
, List
<ColumnFamilyDescriptor
> cfDescs
) throws RocksDBException
{
90 loadLatestOptions(configOptions
.nativeHandle_
, dbPath
, dbOptions
.nativeHandle_
, cfDescs
);
94 * Similar to LoadLatestOptions, this function constructs the DBOptions
95 * and ColumnFamilyDescriptors based on the specified RocksDB Options file.
96 * See LoadLatestOptions above.
98 * @param optionsFileName the RocksDB options file path.
99 * @param env {@link org.rocksdb.Env} instance.
100 * @param dbOptions {@link org.rocksdb.DBOptions} instance. This will be
101 * filled and returned.
102 * @param cfDescs A list of {@link org.rocksdb.ColumnFamilyDescriptor}'s be
105 * @throws RocksDBException thrown if error happens in underlying
108 public static void loadOptionsFromFile(String optionsFileName
, Env env
, DBOptions dbOptions
,
109 List
<ColumnFamilyDescriptor
> cfDescs
) throws RocksDBException
{
110 loadOptionsFromFile(optionsFileName
, env
, dbOptions
, cfDescs
, false);
114 * @param optionsFileName the RocksDB options file path.
115 * @param env {@link org.rocksdb.Env} instance.
116 * @param dbOptions {@link org.rocksdb.DBOptions} instance. This will be
117 * filled and returned.
118 * @param cfDescs A list of {@link org.rocksdb.ColumnFamilyDescriptor}'s be
120 * @param ignoreUnknownOptions this flag can be set to true if you want to
121 * ignore options that are from a newer version of the db, esentially for
122 * forward compatibility.
124 * @throws RocksDBException thrown if error happens in underlying
127 public static void loadOptionsFromFile(String optionsFileName
, Env env
, DBOptions dbOptions
,
128 List
<ColumnFamilyDescriptor
> cfDescs
, boolean ignoreUnknownOptions
) throws RocksDBException
{
130 optionsFileName
, env
.nativeHandle_
, dbOptions
.nativeHandle_
, cfDescs
, ignoreUnknownOptions
);
134 * Similar to LoadLatestOptions, this function constructs the DBOptions
135 * and ColumnFamilyDescriptors based on the specified RocksDB Options file.
136 * See LoadLatestOptions above.
138 * @param optionsFileName the RocksDB options file path.
139 * @param configOptions {@link org.rocksdb.ConfigOptions} instance.
140 * @param dbOptions {@link org.rocksdb.DBOptions} instance. This will be
141 * filled and returned.
142 * @param cfDescs A list of {@link org.rocksdb.ColumnFamilyDescriptor}'s be
144 * @throws RocksDBException thrown if error happens in underlying
147 public static void loadOptionsFromFile(ConfigOptions configOptions
, String optionsFileName
,
148 DBOptions dbOptions
, List
<ColumnFamilyDescriptor
> cfDescs
) throws RocksDBException
{
150 configOptions
.nativeHandle_
, optionsFileName
, dbOptions
.nativeHandle_
, cfDescs
);
154 * Returns the latest options file name under the specified RocksDB path.
156 * @param dbPath the path to the RocksDB.
157 * @param env {@link org.rocksdb.Env} instance.
158 * @return the latest options file name under the db path.
160 * @throws RocksDBException thrown if error happens in underlying
163 public static String
getLatestOptionsFileName(String dbPath
, Env env
) throws RocksDBException
{
164 return getLatestOptionsFileName(dbPath
, env
.nativeHandle_
);
168 * Private constructor.
169 * This class has only static methods and shouldn't be instantiated.
171 private OptionsUtil() {}
174 private native static void loadLatestOptions(String dbPath
, long envHandle
, long dbOptionsHandle
,
175 List
<ColumnFamilyDescriptor
> cfDescs
, boolean ignoreUnknownOptions
) throws RocksDBException
;
176 private native static void loadLatestOptions(long cfgHandle
, String dbPath
, long dbOptionsHandle
,
177 List
<ColumnFamilyDescriptor
> cfDescs
) throws RocksDBException
;
178 private native static void loadOptionsFromFile(String optionsFileName
, long envHandle
,
179 long dbOptionsHandle
, List
<ColumnFamilyDescriptor
> cfDescs
, boolean ignoreUnknownOptions
)
180 throws RocksDBException
;
181 private native static void loadOptionsFromFile(long cfgHandle
, String optionsFileName
,
182 long dbOptionsHandle
, List
<ColumnFamilyDescriptor
> cfDescs
) throws RocksDBException
;
183 private native static String
getLatestOptionsFileName(String dbPath
, long envHandle
)
184 throws RocksDBException
;