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