]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/main/java/org/rocksdb/OptionsUtil.java
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / OptionsUtil.java
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).
5
6 package org.rocksdb;
7
8 import java.util.List;
9
10 public class OptionsUtil {
11 /**
12 * A static method to construct the DBOptions and ColumnFamilyDescriptors by
13 * loading the latest RocksDB options file stored in the specified rocksdb
14 * database.
15 *
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.
20 *
21 * - env
22 * - memtable_factory
23 * - compaction_filter_factory
24 * - prefix_extractor
25 * - comparator
26 * - merge_operator
27 * - compaction_filter
28 *
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.
36 *
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
42 * returned.
43 *
44 * @throws RocksDBException thrown if error happens in underlying
45 * native library.
46 */
47
48 public static void loadLatestOptions(String dbPath, Env env, DBOptions dbOptions,
49 List<ColumnFamilyDescriptor> cfDescs) throws RocksDBException {
50 loadLatestOptions(dbPath, env, dbOptions, cfDescs, false);
51 }
52
53 /**
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
59 * returned.
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.
63 *
64 * @throws RocksDBException thrown if error happens in underlying
65 * native library.
66 */
67 public static void loadLatestOptions(String dbPath, Env env, DBOptions dbOptions,
68 List<ColumnFamilyDescriptor> cfDescs, boolean ignoreUnknownOptions) throws RocksDBException {
69 loadLatestOptions(
70 dbPath, env.nativeHandle_, dbOptions.nativeHandle_, cfDescs, ignoreUnknownOptions);
71 }
72
73 /**
74 * Similar to LoadLatestOptions, this function constructs the DBOptions
75 * and ColumnFamilyDescriptors based on the specified RocksDB Options file.
76 * See LoadLatestOptions above.
77 *
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
83 * returned.
84 * @throws RocksDBException thrown if error happens in underlying
85 * native library.
86 */
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);
90 }
91
92 /**
93 * Similar to LoadLatestOptions, this function constructs the DBOptions
94 * and ColumnFamilyDescriptors based on the specified RocksDB Options file.
95 * See LoadLatestOptions above.
96 *
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
102 * returned.
103 *
104 * @throws RocksDBException thrown if error happens in underlying
105 * native library.
106 */
107 public static void loadOptionsFromFile(String optionsFileName, Env env, DBOptions dbOptions,
108 List<ColumnFamilyDescriptor> cfDescs) throws RocksDBException {
109 loadOptionsFromFile(optionsFileName, env, dbOptions, cfDescs, false);
110 }
111
112 /**
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
118 * returned.
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.
122 *
123 * @throws RocksDBException thrown if error happens in underlying
124 * native library.
125 */
126 public static void loadOptionsFromFile(String optionsFileName, Env env, DBOptions dbOptions,
127 List<ColumnFamilyDescriptor> cfDescs, boolean ignoreUnknownOptions) throws RocksDBException {
128 loadOptionsFromFile(
129 optionsFileName, env.nativeHandle_, dbOptions.nativeHandle_, cfDescs, ignoreUnknownOptions);
130 }
131
132 /**
133 * Similar to LoadLatestOptions, this function constructs the DBOptions
134 * and ColumnFamilyDescriptors based on the specified RocksDB Options file.
135 * See LoadLatestOptions above.
136 *
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
142 * returned.
143 * @throws RocksDBException thrown if error happens in underlying
144 * native library.
145 */
146 public static void loadOptionsFromFile(ConfigOptions configOptions, String optionsFileName,
147 DBOptions dbOptions, List<ColumnFamilyDescriptor> cfDescs) throws RocksDBException {
148 loadOptionsFromFile(
149 configOptions.nativeHandle_, optionsFileName, dbOptions.nativeHandle_, cfDescs);
150 }
151
152 /**
153 * Returns the latest options file name under the specified RocksDB path.
154 *
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.
158 *
159 * @throws RocksDBException thrown if error happens in underlying
160 * native library.
161 */
162 public static String getLatestOptionsFileName(String dbPath, Env env) throws RocksDBException {
163 return getLatestOptionsFileName(dbPath, env.nativeHandle_);
164 }
165
166 /**
167 * Private constructor.
168 * This class has only static methods and shouldn't be instantiated.
169 */
170 private OptionsUtil() {}
171
172 // native methods
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;
184 }