]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/java/src/main/java/org/rocksdb/RocksDB.java
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / RocksDB.java
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
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).
7c673cae
FG
5
6package org.rocksdb;
7
8import java.util.*;
9import java.io.IOException;
7c673cae
FG
10import java.util.concurrent.atomic.AtomicReference;
11
12import org.rocksdb.util.Environment;
13
14/**
15 * A RocksDB is a persistent ordered map from keys to values. It is safe for
16 * concurrent access from multiple threads without any external synchronization.
17 * All methods of this class could potentially throw RocksDBException, which
18 * indicates sth wrong at the RocksDB library side and the call failed.
19 */
20public class RocksDB extends RocksObject {
21 public static final byte[] DEFAULT_COLUMN_FAMILY = "default".getBytes();
22 public static final int NOT_FOUND = -1;
23
24 private enum LibraryState {
25 NOT_LOADED,
26 LOADING,
27 LOADED
28 }
29
30 private static AtomicReference<LibraryState> libraryLoaded
31 = new AtomicReference<>(LibraryState.NOT_LOADED);
32
33 static {
34 RocksDB.loadLibrary();
35 }
36
37 /**
38 * Loads the necessary library files.
39 * Calling this method twice will have no effect.
40 * By default the method extracts the shared library for loading at
41 * java.io.tmpdir, however, you can override this temporary location by
42 * setting the environment variable ROCKSDB_SHAREDLIB_DIR.
43 */
44 public static void loadLibrary() {
45 if (libraryLoaded.get() == LibraryState.LOADED) {
46 return;
47 }
48
49 if (libraryLoaded.compareAndSet(LibraryState.NOT_LOADED,
50 LibraryState.LOADING)) {
51 final String tmpDir = System.getenv("ROCKSDB_SHAREDLIB_DIR");
52 // loading possibly necessary libraries.
53 for (final CompressionType compressionType : CompressionType.values()) {
54 try {
55 if (compressionType.getLibraryName() != null) {
56 System.loadLibrary(compressionType.getLibraryName());
57 }
58 } catch (UnsatisfiedLinkError e) {
59 // since it may be optional, we ignore its loading failure here.
60 }
61 }
62 try {
63 NativeLibraryLoader.getInstance().loadLibrary(tmpDir);
64 } catch (IOException e) {
65 libraryLoaded.set(LibraryState.NOT_LOADED);
494da23a
TL
66 throw new RuntimeException("Unable to load the RocksDB shared library",
67 e);
7c673cae
FG
68 }
69
70 libraryLoaded.set(LibraryState.LOADED);
71 return;
72 }
73
74 while (libraryLoaded.get() == LibraryState.LOADING) {
75 try {
76 Thread.sleep(10);
77 } catch(final InterruptedException e) {
78 //ignore
79 }
80 }
81 }
82
83 /**
84 * Tries to load the necessary library files from the given list of
85 * directories.
86 *
87 * @param paths a list of strings where each describes a directory
88 * of a library.
89 */
90 public static void loadLibrary(final List<String> paths) {
91 if (libraryLoaded.get() == LibraryState.LOADED) {
92 return;
93 }
94
95 if (libraryLoaded.compareAndSet(LibraryState.NOT_LOADED,
96 LibraryState.LOADING)) {
97 for (final CompressionType compressionType : CompressionType.values()) {
98 if (compressionType.equals(CompressionType.NO_COMPRESSION)) {
99 continue;
100 }
101 for (final String path : paths) {
102 try {
103 System.load(path + "/" + Environment.getSharedLibraryFileName(
104 compressionType.getLibraryName()));
105 break;
106 } catch (UnsatisfiedLinkError e) {
107 // since they are optional, we ignore loading fails.
108 }
109 }
110 }
111 boolean success = false;
112 UnsatisfiedLinkError err = null;
113 for (final String path : paths) {
114 try {
115 System.load(path + "/" +
116 Environment.getJniLibraryFileName("rocksdbjni"));
117 success = true;
118 break;
119 } catch (UnsatisfiedLinkError e) {
120 err = e;
121 }
122 }
123 if (!success) {
124 libraryLoaded.set(LibraryState.NOT_LOADED);
125 throw err;
126 }
127
128 libraryLoaded.set(LibraryState.LOADED);
129 return;
130 }
131
132 while (libraryLoaded.get() == LibraryState.LOADING) {
133 try {
134 Thread.sleep(10);
135 } catch(final InterruptedException e) {
136 //ignore
137 }
138 }
139 }
140
494da23a
TL
141 /**
142 * Private constructor.
143 *
144 * @param nativeHandle The native handle of the C++ RocksDB object
145 */
146 protected RocksDB(final long nativeHandle) {
147 super(nativeHandle);
148 }
149
7c673cae
FG
150 /**
151 * The factory constructor of RocksDB that opens a RocksDB instance given
152 * the path to the database using the default options w/ createIfMissing
153 * set to true.
154 *
155 * @param path the path to the rocksdb.
156 * @return a {@link RocksDB} instance on success, null if the specified
157 * {@link RocksDB} can not be opened.
158 *
159 * @throws RocksDBException thrown if error happens in underlying
160 * native library.
161 * @see Options#setCreateIfMissing(boolean)
162 */
163 public static RocksDB open(final String path) throws RocksDBException {
494da23a 164 final Options options = new Options();
7c673cae
FG
165 options.setCreateIfMissing(true);
166 return open(options, path);
167 }
168
169 /**
170 * The factory constructor of RocksDB that opens a RocksDB instance given
171 * the path to the database using the specified options and db path and a list
172 * of column family names.
173 * <p>
174 * If opened in read write mode every existing column family name must be
175 * passed within the list to this method.</p>
176 * <p>
177 * If opened in read-only mode only a subset of existing column families must
178 * be passed to this method.</p>
179 * <p>
180 * Options instance *should* not be disposed before all DBs using this options
181 * instance have been closed. If user doesn't call options dispose explicitly,
182 * then this options instance will be GC'd automatically</p>
183 * <p>
184 * ColumnFamily handles are disposed when the RocksDB instance is disposed.
185 * </p>
186 *
187 * @param path the path to the rocksdb.
188 * @param columnFamilyDescriptors list of column family descriptors
189 * @param columnFamilyHandles will be filled with ColumnFamilyHandle instances
190 * on open.
191 * @return a {@link RocksDB} instance on success, null if the specified
192 * {@link RocksDB} can not be opened.
193 *
194 * @throws RocksDBException thrown if error happens in underlying
195 * native library.
196 * @see DBOptions#setCreateIfMissing(boolean)
197 */
198 public static RocksDB open(final String path,
199 final List<ColumnFamilyDescriptor> columnFamilyDescriptors,
200 final List<ColumnFamilyHandle> columnFamilyHandles)
201 throws RocksDBException {
494da23a 202 final DBOptions options = new DBOptions();
7c673cae
FG
203 return open(options, path, columnFamilyDescriptors, columnFamilyHandles);
204 }
205
206 /**
207 * The factory constructor of RocksDB that opens a RocksDB instance given
208 * the path to the database using the specified options and db path.
209 *
210 * <p>
211 * Options instance *should* not be disposed before all DBs using this options
212 * instance have been closed. If user doesn't call options dispose explicitly,
213 * then this options instance will be GC'd automatically.</p>
214 * <p>
215 * Options instance can be re-used to open multiple DBs if DB statistics is
216 * not used. If DB statistics are required, then its recommended to open DB
217 * with new Options instance as underlying native statistics instance does not
218 * use any locks to prevent concurrent updates.</p>
219 *
220 * @param options {@link org.rocksdb.Options} instance.
221 * @param path the path to the rocksdb.
222 * @return a {@link RocksDB} instance on success, null if the specified
223 * {@link RocksDB} can not be opened.
224 *
225 * @throws RocksDBException thrown if error happens in underlying
226 * native library.
227 *
228 * @see Options#setCreateIfMissing(boolean)
229 */
230 public static RocksDB open(final Options options, final String path)
231 throws RocksDBException {
232 // when non-default Options is used, keeping an Options reference
233 // in RocksDB can prevent Java to GC during the life-time of
234 // the currently-created RocksDB.
235 final RocksDB db = new RocksDB(open(options.nativeHandle_, path));
236 db.storeOptionsInstance(options);
237 return db;
238 }
239
240 /**
241 * The factory constructor of RocksDB that opens a RocksDB instance given
242 * the path to the database using the specified options and db path and a list
243 * of column family names.
244 * <p>
245 * If opened in read write mode every existing column family name must be
246 * passed within the list to this method.</p>
247 * <p>
248 * If opened in read-only mode only a subset of existing column families must
249 * be passed to this method.</p>
250 * <p>
251 * Options instance *should* not be disposed before all DBs using this options
252 * instance have been closed. If user doesn't call options dispose explicitly,
253 * then this options instance will be GC'd automatically.</p>
254 * <p>
255 * Options instance can be re-used to open multiple DBs if DB statistics is
256 * not used. If DB statistics are required, then its recommended to open DB
257 * with new Options instance as underlying native statistics instance does not
258 * use any locks to prevent concurrent updates.</p>
259 * <p>
260 * ColumnFamily handles are disposed when the RocksDB instance is disposed.
261 * </p>
262 *
263 * @param options {@link org.rocksdb.DBOptions} instance.
264 * @param path the path to the rocksdb.
265 * @param columnFamilyDescriptors list of column family descriptors
266 * @param columnFamilyHandles will be filled with ColumnFamilyHandle instances
267 * on open.
268 * @return a {@link RocksDB} instance on success, null if the specified
269 * {@link RocksDB} can not be opened.
270 *
271 * @throws RocksDBException thrown if error happens in underlying
272 * native library.
273 *
274 * @see DBOptions#setCreateIfMissing(boolean)
275 */
276 public static RocksDB open(final DBOptions options, final String path,
277 final List<ColumnFamilyDescriptor> columnFamilyDescriptors,
278 final List<ColumnFamilyHandle> columnFamilyHandles)
279 throws RocksDBException {
280
281 final byte[][] cfNames = new byte[columnFamilyDescriptors.size()][];
282 final long[] cfOptionHandles = new long[columnFamilyDescriptors.size()];
283 for (int i = 0; i < columnFamilyDescriptors.size(); i++) {
284 final ColumnFamilyDescriptor cfDescriptor = columnFamilyDescriptors
285 .get(i);
286 cfNames[i] = cfDescriptor.columnFamilyName();
287 cfOptionHandles[i] = cfDescriptor.columnFamilyOptions().nativeHandle_;
288 }
289
290 final long[] handles = open(options.nativeHandle_, path, cfNames,
291 cfOptionHandles);
292 final RocksDB db = new RocksDB(handles[0]);
293 db.storeOptionsInstance(options);
294
295 for (int i = 1; i < handles.length; i++) {
296 columnFamilyHandles.add(new ColumnFamilyHandle(db, handles[i]));
297 }
298
299 return db;
300 }
301
302 /**
303 * The factory constructor of RocksDB that opens a RocksDB instance in
304 * Read-Only mode given the path to the database using the default
305 * options.
306 *
307 * @param path the path to the RocksDB.
308 * @return a {@link RocksDB} instance on success, null if the specified
309 * {@link RocksDB} can not be opened.
310 *
311 * @throws RocksDBException thrown if error happens in underlying
312 * native library.
313 */
314 public static RocksDB openReadOnly(final String path)
315 throws RocksDBException {
316 // This allows to use the rocksjni default Options instead of
317 // the c++ one.
318 Options options = new Options();
319 return openReadOnly(options, path);
320 }
321
322 /**
323 * The factory constructor of RocksDB that opens a RocksDB instance in
324 * Read-Only mode given the path to the database using the default
325 * options.
326 *
327 * @param path the path to the RocksDB.
328 * @param columnFamilyDescriptors list of column family descriptors
329 * @param columnFamilyHandles will be filled with ColumnFamilyHandle instances
330 * on open.
331 * @return a {@link RocksDB} instance on success, null if the specified
332 * {@link RocksDB} can not be opened.
333 *
334 * @throws RocksDBException thrown if error happens in underlying
335 * native library.
336 */
337 public static RocksDB openReadOnly(final String path,
338 final List<ColumnFamilyDescriptor> columnFamilyDescriptors,
339 final List<ColumnFamilyHandle> columnFamilyHandles)
340 throws RocksDBException {
341 // This allows to use the rocksjni default Options instead of
342 // the c++ one.
343 final DBOptions options = new DBOptions();
344 return openReadOnly(options, path, columnFamilyDescriptors,
345 columnFamilyHandles);
346 }
347
348 /**
349 * The factory constructor of RocksDB that opens a RocksDB instance in
350 * Read-Only mode given the path to the database using the specified
351 * options and db path.
352 *
353 * Options instance *should* not be disposed before all DBs using this options
354 * instance have been closed. If user doesn't call options dispose explicitly,
355 * then this options instance will be GC'd automatically.
356 *
357 * @param options {@link Options} instance.
358 * @param path the path to the RocksDB.
359 * @return a {@link RocksDB} instance on success, null if the specified
360 * {@link RocksDB} can not be opened.
361 *
362 * @throws RocksDBException thrown if error happens in underlying
363 * native library.
364 */
365 public static RocksDB openReadOnly(final Options options, final String path)
366 throws RocksDBException {
367 // when non-default Options is used, keeping an Options reference
368 // in RocksDB can prevent Java to GC during the life-time of
369 // the currently-created RocksDB.
370 final RocksDB db = new RocksDB(openROnly(options.nativeHandle_, path));
371 db.storeOptionsInstance(options);
372 return db;
373 }
374
375 /**
376 * The factory constructor of RocksDB that opens a RocksDB instance in
377 * Read-Only mode given the path to the database using the specified
378 * options and db path.
379 *
380 * <p>This open method allows to open RocksDB using a subset of available
381 * column families</p>
382 * <p>Options instance *should* not be disposed before all DBs using this
383 * options instance have been closed. If user doesn't call options dispose
384 * explicitly,then this options instance will be GC'd automatically.</p>
385 *
386 * @param options {@link DBOptions} instance.
387 * @param path the path to the RocksDB.
388 * @param columnFamilyDescriptors list of column family descriptors
389 * @param columnFamilyHandles will be filled with ColumnFamilyHandle instances
390 * on open.
391 * @return a {@link RocksDB} instance on success, null if the specified
392 * {@link RocksDB} can not be opened.
393 *
394 * @throws RocksDBException thrown if error happens in underlying
395 * native library.
396 */
397 public static RocksDB openReadOnly(final DBOptions options, final String path,
398 final List<ColumnFamilyDescriptor> columnFamilyDescriptors,
399 final List<ColumnFamilyHandle> columnFamilyHandles)
400 throws RocksDBException {
401 // when non-default Options is used, keeping an Options reference
402 // in RocksDB can prevent Java to GC during the life-time of
403 // the currently-created RocksDB.
404
405 final byte[][] cfNames = new byte[columnFamilyDescriptors.size()][];
406 final long[] cfOptionHandles = new long[columnFamilyDescriptors.size()];
407 for (int i = 0; i < columnFamilyDescriptors.size(); i++) {
408 final ColumnFamilyDescriptor cfDescriptor = columnFamilyDescriptors
409 .get(i);
410 cfNames[i] = cfDescriptor.columnFamilyName();
411 cfOptionHandles[i] = cfDescriptor.columnFamilyOptions().nativeHandle_;
412 }
413
414 final long[] handles = openROnly(options.nativeHandle_, path, cfNames,
415 cfOptionHandles);
416 final RocksDB db = new RocksDB(handles[0]);
417 db.storeOptionsInstance(options);
418
419 for (int i = 1; i < handles.length; i++) {
420 columnFamilyHandles.add(new ColumnFamilyHandle(db, handles[i]));
421 }
422
423 return db;
424 }
494da23a
TL
425
426 /**
427 * This is similar to {@link #close()} except that it
428 * throws an exception if any error occurs.
429 *
430 * This will not fsync the WAL files.
431 * If syncing is required, the caller must first call {@link #syncWal()}
432 * or {@link #write(WriteOptions, WriteBatch)} using an empty write batch
433 * with {@link WriteOptions#setSync(boolean)} set to true.
434 *
435 * See also {@link #close()}.
436 *
437 * @throws RocksDBException if an error occurs whilst closing.
438 */
439 public void closeE() throws RocksDBException {
440 if (owningHandle_.compareAndSet(true, false)) {
441 try {
442 closeDatabase(nativeHandle_);
443 } finally {
444 disposeInternal();
445 }
446 }
447 }
448
449 /**
450 * This is similar to {@link #closeE()} except that it
451 * silently ignores any errors.
452 *
453 * This will not fsync the WAL files.
454 * If syncing is required, the caller must first call {@link #syncWal()}
455 * or {@link #write(WriteOptions, WriteBatch)} using an empty write batch
456 * with {@link WriteOptions#setSync(boolean)} set to true.
457 *
458 * See also {@link #close()}.
459 */
460 @Override
461 public void close() {
462 if (owningHandle_.compareAndSet(true, false)) {
463 try {
464 closeDatabase(nativeHandle_);
465 } catch (final RocksDBException e) {
466 // silently ignore the error report
467 } finally {
468 disposeInternal();
469 }
470 }
471 }
472
7c673cae
FG
473 /**
474 * Static method to determine all available column families for a
475 * rocksdb database identified by path
476 *
477 * @param options Options for opening the database
478 * @param path Absolute path to rocksdb database
479 * @return List&lt;byte[]&gt; List containing the column family names
480 *
481 * @throws RocksDBException thrown if error happens in underlying
482 * native library.
483 */
484 public static List<byte[]> listColumnFamilies(final Options options,
485 final String path) throws RocksDBException {
486 return Arrays.asList(RocksDB.listColumnFamilies(options.nativeHandle_,
487 path));
488 }
489
494da23a
TL
490 /**
491 * Creates a new column family with the name columnFamilyName and
492 * allocates a ColumnFamilyHandle within an internal structure.
493 * The ColumnFamilyHandle is automatically disposed with DB disposal.
494 *
495 * @param columnFamilyDescriptor column family to be created.
496 * @return {@link org.rocksdb.ColumnFamilyHandle} instance.
497 *
498 * @throws RocksDBException thrown if error happens in underlying
499 * native library.
500 */
501 public ColumnFamilyHandle createColumnFamily(
502 final ColumnFamilyDescriptor columnFamilyDescriptor)
503 throws RocksDBException {
504 return new ColumnFamilyHandle(this, createColumnFamily(nativeHandle_,
505 columnFamilyDescriptor.getName(),
506 columnFamilyDescriptor.getName().length,
507 columnFamilyDescriptor.getOptions().nativeHandle_));
508 }
509
510 /**
511 * Bulk create column families with the same column family options.
512 *
513 * @param columnFamilyOptions the options for the column families.
514 * @param columnFamilyNames the names of the column families.
515 *
516 * @return the handles to the newly created column families.
517 */
518 public List<ColumnFamilyHandle> createColumnFamilies(
519 final ColumnFamilyOptions columnFamilyOptions,
520 final List<byte[]> columnFamilyNames) throws RocksDBException {
521 final byte[][] cfNames = columnFamilyNames.toArray(
522 new byte[0][]);
523 final long[] cfHandles = createColumnFamilies(nativeHandle_,
524 columnFamilyOptions.nativeHandle_, cfNames);
525 final List<ColumnFamilyHandle> columnFamilyHandles =
526 new ArrayList<>(cfHandles.length);
527 for (int i = 0; i < cfHandles.length; i++) {
528 columnFamilyHandles.add(new ColumnFamilyHandle(this, cfHandles[i]));
529 }
530 return columnFamilyHandles;
531 }
532
533 /**
534 * Bulk create column families with the same column family options.
535 *
536 * @param columnFamilyDescriptors the descriptions of the column families.
537 *
538 * @return the handles to the newly created column families.
539 */
540 public List<ColumnFamilyHandle> createColumnFamilies(
541 final List<ColumnFamilyDescriptor> columnFamilyDescriptors)
542 throws RocksDBException {
543 final long[] cfOptsHandles = new long[columnFamilyDescriptors.size()];
544 final byte[][] cfNames = new byte[columnFamilyDescriptors.size()][];
545 for (int i = 0; i < columnFamilyDescriptors.size(); i++) {
546 final ColumnFamilyDescriptor columnFamilyDescriptor
547 = columnFamilyDescriptors.get(i);
548 cfOptsHandles[i] = columnFamilyDescriptor.getOptions().nativeHandle_;
549 cfNames[i] = columnFamilyDescriptor.getName();
550 }
551 final long[] cfHandles = createColumnFamilies(nativeHandle_,
552 cfOptsHandles, cfNames);
553 final List<ColumnFamilyHandle> columnFamilyHandles =
554 new ArrayList<>(cfHandles.length);
555 for (int i = 0; i < cfHandles.length; i++) {
556 columnFamilyHandles.add(new ColumnFamilyHandle(this, cfHandles[i]));
557 }
558 return columnFamilyHandles;
559 }
560
561 /**
562 * Drops the column family specified by {@code columnFamilyHandle}. This call
563 * only records a drop record in the manifest and prevents the column
564 * family from flushing and compacting.
565 *
566 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
567 * instance
568 *
569 * @throws RocksDBException thrown if error happens in underlying
570 * native library.
571 */
572 public void dropColumnFamily(final ColumnFamilyHandle columnFamilyHandle)
573 throws RocksDBException {
574 dropColumnFamily(nativeHandle_, columnFamilyHandle.nativeHandle_);
575 }
576
577 // Bulk drop column families. This call only records drop records in the
578 // manifest and prevents the column families from flushing and compacting.
579 // In case of error, the request may succeed partially. User may call
580 // ListColumnFamilies to check the result.
581 public void dropColumnFamilies(
582 final List<ColumnFamilyHandle> columnFamilies) throws RocksDBException {
583 final long[] cfHandles = new long[columnFamilies.size()];
584 for (int i = 0; i < columnFamilies.size(); i++) {
585 cfHandles[i] = columnFamilies.get(i).nativeHandle_;
586 }
587 dropColumnFamilies(nativeHandle_, cfHandles);
7c673cae
FG
588 }
589
494da23a
TL
590 //TODO(AR) what about DestroyColumnFamilyHandle
591
7c673cae
FG
592 /**
593 * Set the database entry for "key" to "value".
594 *
595 * @param key the specified key to be inserted.
596 * @param value the value associated with the specified key.
597 *
598 * @throws RocksDBException thrown if error happens in underlying
599 * native library.
600 */
601 public void put(final byte[] key, final byte[] value)
602 throws RocksDBException {
603 put(nativeHandle_, key, 0, key.length, value, 0, value.length);
604 }
605
494da23a
TL
606 /**
607 * Set the database entry for "key" to "value".
608 *
609 * @param key The specified key to be inserted
610 * @param offset the offset of the "key" array to be used, must be
611 * non-negative and no larger than "key".length
612 * @param len the length of the "key" array to be used, must be non-negative
613 * and no larger than ("key".length - offset)
614 * @param value the value associated with the specified key
615 * @param vOffset the offset of the "value" array to be used, must be
616 * non-negative and no longer than "key".length
617 * @param vLen the length of the "value" array to be used, must be
618 * non-negative and no larger than ("value".length - offset)
619 *
620 * @throws RocksDBException thrown if errors happens in underlying native
621 * library.
622 * @throws IndexOutOfBoundsException if an offset or length is out of bounds
623 */
624 public void put(final byte[] key, final int offset, final int len,
625 final byte[] value, final int vOffset, final int vLen)
626 throws RocksDBException {
627 checkBounds(offset, len, key.length);
628 checkBounds(vOffset, vLen, value.length);
629 put(nativeHandle_, key, offset, len, value, vOffset, vLen);
630 }
631
7c673cae
FG
632 /**
633 * Set the database entry for "key" to "value" in the specified
634 * column family.
635 *
636 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
637 * instance
638 * @param key the specified key to be inserted.
639 * @param value the value associated with the specified key.
640 *
641 * throws IllegalArgumentException if column family is not present
642 *
643 * @throws RocksDBException thrown if error happens in underlying
644 * native library.
645 */
646 public void put(final ColumnFamilyHandle columnFamilyHandle,
647 final byte[] key, final byte[] value) throws RocksDBException {
648 put(nativeHandle_, key, 0, key.length, value, 0, value.length,
649 columnFamilyHandle.nativeHandle_);
650 }
651
494da23a
TL
652 /**
653 * Set the database entry for "key" to "value" in the specified
654 * column family.
655 *
656 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
657 * instance
658 * @param key The specified key to be inserted
659 * @param offset the offset of the "key" array to be used, must
660 * be non-negative and no larger than "key".length
661 * @param len the length of the "key" array to be used, must be non-negative
662 * and no larger than ("key".length - offset)
663 * @param value the value associated with the specified key
664 * @param vOffset the offset of the "value" array to be used, must be
665 * non-negative and no longer than "key".length
666 * @param vLen the length of the "value" array to be used, must be
667 * non-negative and no larger than ("value".length - offset)
668 *
669 * @throws RocksDBException thrown if errors happens in underlying native
670 * library.
671 * @throws IndexOutOfBoundsException if an offset or length is out of bounds
672 */
673 public void put(final ColumnFamilyHandle columnFamilyHandle,
674 final byte[] key, final int offset, final int len,
675 final byte[] value, final int vOffset, final int vLen)
676 throws RocksDBException {
677 checkBounds(offset, len, key.length);
678 checkBounds(vOffset, vLen, value.length);
679 put(nativeHandle_, key, offset, len, value, vOffset, vLen,
680 columnFamilyHandle.nativeHandle_);
681 }
682
7c673cae
FG
683 /**
684 * Set the database entry for "key" to "value".
685 *
686 * @param writeOpts {@link org.rocksdb.WriteOptions} instance.
687 * @param key the specified key to be inserted.
688 * @param value the value associated with the specified key.
689 *
690 * @throws RocksDBException thrown if error happens in underlying
691 * native library.
692 */
693 public void put(final WriteOptions writeOpts, final byte[] key,
694 final byte[] value) throws RocksDBException {
695 put(nativeHandle_, writeOpts.nativeHandle_,
696 key, 0, key.length, value, 0, value.length);
697 }
698
494da23a
TL
699 /**
700 * Set the database entry for "key" to "value".
701 *
702 * @param writeOpts {@link org.rocksdb.WriteOptions} instance.
703 * @param key The specified key to be inserted
704 * @param offset the offset of the "key" array to be used, must be
705 * non-negative and no larger than "key".length
706 * @param len the length of the "key" array to be used, must be non-negative
707 * and no larger than ("key".length - offset)
708 * @param value the value associated with the specified key
709 * @param vOffset the offset of the "value" array to be used, must be
710 * non-negative and no longer than "key".length
711 * @param vLen the length of the "value" array to be used, must be
712 * non-negative and no larger than ("value".length - offset)
713 *
714 * @throws RocksDBException thrown if error happens in underlying
715 * native library.
716 * @throws IndexOutOfBoundsException if an offset or length is out of bounds
717 */
718 public void put(final WriteOptions writeOpts,
719 final byte[] key, final int offset, final int len,
720 final byte[] value, final int vOffset, final int vLen)
721 throws RocksDBException {
722 checkBounds(offset, len, key.length);
723 checkBounds(vOffset, vLen, value.length);
724 put(nativeHandle_, writeOpts.nativeHandle_,
725 key, offset, len, value, vOffset, vLen);
726 }
727
7c673cae
FG
728 /**
729 * Set the database entry for "key" to "value" for the specified
730 * column family.
731 *
732 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
733 * instance
734 * @param writeOpts {@link org.rocksdb.WriteOptions} instance.
735 * @param key the specified key to be inserted.
736 * @param value the value associated with the specified key.
737 *
738 * throws IllegalArgumentException if column family is not present
739 *
740 * @throws RocksDBException thrown if error happens in underlying
741 * native library.
742 * @see IllegalArgumentException
743 */
744 public void put(final ColumnFamilyHandle columnFamilyHandle,
745 final WriteOptions writeOpts, final byte[] key,
746 final byte[] value) throws RocksDBException {
747 put(nativeHandle_, writeOpts.nativeHandle_, key, 0, key.length, value,
748 0, value.length, columnFamilyHandle.nativeHandle_);
749 }
750
751 /**
494da23a
TL
752 * Set the database entry for "key" to "value" for the specified
753 * column family.
7c673cae 754 *
494da23a
TL
755 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
756 * instance
757 * @param writeOpts {@link org.rocksdb.WriteOptions} instance.
758 * @param key The specified key to be inserted
759 * @param offset the offset of the "key" array to be used, must be
760 * non-negative and no larger than "key".length
761 * @param len the length of the "key" array to be used, must be non-negative
762 * and no larger than ("key".length - offset)
763 * @param value the value associated with the specified key
764 * @param vOffset the offset of the "value" array to be used, must be
765 * non-negative and no longer than "key".length
766 * @param vLen the length of the "value" array to be used, must be
767 * non-negative and no larger than ("value".length - offset)
7c673cae 768 *
494da23a
TL
769 * @throws RocksDBException thrown if error happens in underlying
770 * native library.
771 * @throws IndexOutOfBoundsException if an offset or length is out of bounds
7c673cae 772 */
494da23a
TL
773 public void put(final ColumnFamilyHandle columnFamilyHandle,
774 final WriteOptions writeOpts,
775 final byte[] key, final int offset, final int len,
776 final byte[] value, final int vOffset, final int vLen)
777 throws RocksDBException {
778 checkBounds(offset, len, key.length);
779 checkBounds(vOffset, vLen, value.length);
780 put(nativeHandle_, writeOpts.nativeHandle_, key, offset, len, value,
781 vOffset, vLen, columnFamilyHandle.nativeHandle_);
7c673cae
FG
782 }
783
784 /**
494da23a
TL
785 * Remove the database entry (if any) for "key". Returns OK on
786 * success, and a non-OK status on error. It is not an error if "key"
787 * did not exist in the database.
7c673cae 788 *
494da23a 789 * @param key Key to delete within database
7c673cae 790 *
494da23a
TL
791 * @throws RocksDBException thrown if error happens in underlying
792 * native library.
793 *
794 * @deprecated Use {@link #delete(byte[])}
7c673cae 795 */
494da23a
TL
796 @Deprecated
797 public void remove(final byte[] key) throws RocksDBException {
798 delete(key);
7c673cae
FG
799 }
800
801 /**
494da23a
TL
802 * Delete the database entry (if any) for "key". Returns OK on
803 * success, and a non-OK status on error. It is not an error if "key"
804 * did not exist in the database.
7c673cae 805 *
494da23a 806 * @param key Key to delete within database
7c673cae 807 *
494da23a
TL
808 * @throws RocksDBException thrown if error happens in underlying
809 * native library.
7c673cae 810 */
494da23a
TL
811 public void delete(final byte[] key) throws RocksDBException {
812 delete(nativeHandle_, key, 0, key.length);
7c673cae
FG
813 }
814
815 /**
494da23a
TL
816 * Delete the database entry (if any) for "key". Returns OK on
817 * success, and a non-OK status on error. It is not an error if "key"
818 * did not exist in the database.
7c673cae 819 *
494da23a
TL
820 * @param key Key to delete within database
821 * @param offset the offset of the "key" array to be used, must be
822 * non-negative and no larger than "key".length
823 * @param len the length of the "key" array to be used, must be
824 * non-negative and no larger than ("key".length - offset)
7c673cae 825 *
494da23a
TL
826 * @throws RocksDBException thrown if error happens in underlying
827 * native library.
7c673cae 828 */
494da23a
TL
829 public void delete(final byte[] key, final int offset, final int len)
830 throws RocksDBException {
831 delete(nativeHandle_, key, offset, len);
7c673cae
FG
832 }
833
834 /**
494da23a
TL
835 * Remove the database entry (if any) for "key". Returns OK on
836 * success, and a non-OK status on error. It is not an error if "key"
837 * did not exist in the database.
7c673cae 838 *
494da23a
TL
839 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
840 * instance
841 * @param key Key to delete within database
7c673cae
FG
842 *
843 * @throws RocksDBException thrown if error happens in underlying
844 * native library.
494da23a
TL
845 *
846 * @deprecated Use {@link #delete(ColumnFamilyHandle, byte[])}
7c673cae 847 */
494da23a
TL
848 @Deprecated
849 public void remove(final ColumnFamilyHandle columnFamilyHandle,
850 final byte[] key) throws RocksDBException {
851 delete(columnFamilyHandle, key);
7c673cae
FG
852 }
853
854 /**
494da23a
TL
855 * Delete the database entry (if any) for "key". Returns OK on
856 * success, and a non-OK status on error. It is not an error if "key"
857 * did not exist in the database.
7c673cae 858 *
494da23a
TL
859 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
860 * instance
861 * @param key Key to delete within database
7c673cae
FG
862 *
863 * @throws RocksDBException thrown if error happens in underlying
864 * native library.
865 */
494da23a
TL
866 public void delete(final ColumnFamilyHandle columnFamilyHandle,
867 final byte[] key) throws RocksDBException {
868 delete(nativeHandle_, key, 0, key.length, columnFamilyHandle.nativeHandle_);
7c673cae
FG
869 }
870
871 /**
494da23a
TL
872 * Delete the database entry (if any) for "key". Returns OK on
873 * success, and a non-OK status on error. It is not an error if "key"
874 * did not exist in the database.
7c673cae 875 *
494da23a
TL
876 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
877 * instance
878 * @param key Key to delete within database
879 * @param offset the offset of the "key" array to be used,
880 * must be non-negative and no larger than "key".length
881 * @param len the length of the "key" array to be used, must be non-negative
882 * and no larger than ("value".length - offset)
7c673cae
FG
883 *
884 * @throws RocksDBException thrown if error happens in underlying
885 * native library.
886 */
494da23a
TL
887 public void delete(final ColumnFamilyHandle columnFamilyHandle,
888 final byte[] key, final int offset, final int len)
7c673cae 889 throws RocksDBException {
494da23a 890 delete(nativeHandle_, key, offset, len, columnFamilyHandle.nativeHandle_);
7c673cae
FG
891 }
892
893 /**
494da23a
TL
894 * Remove the database entry (if any) for "key". Returns OK on
895 * success, and a non-OK status on error. It is not an error if "key"
896 * did not exist in the database.
7c673cae 897 *
494da23a
TL
898 * @param writeOpt WriteOptions to be used with delete operation
899 * @param key Key to delete within database
7c673cae
FG
900 *
901 * @throws RocksDBException thrown if error happens in underlying
902 * native library.
494da23a
TL
903 *
904 * @deprecated Use {@link #delete(WriteOptions, byte[])}
7c673cae 905 */
494da23a
TL
906 @Deprecated
907 public void remove(final WriteOptions writeOpt, final byte[] key)
908 throws RocksDBException {
909 delete(writeOpt, key);
7c673cae
FG
910 }
911
912 /**
494da23a
TL
913 * Delete the database entry (if any) for "key". Returns OK on
914 * success, and a non-OK status on error. It is not an error if "key"
915 * did not exist in the database.
7c673cae 916 *
494da23a
TL
917 * @param writeOpt WriteOptions to be used with delete operation
918 * @param key Key to delete within database
7c673cae
FG
919 *
920 * @throws RocksDBException thrown if error happens in underlying
921 * native library.
922 */
494da23a
TL
923 public void delete(final WriteOptions writeOpt, final byte[] key)
924 throws RocksDBException {
925 delete(nativeHandle_, writeOpt.nativeHandle_, key, 0, key.length);
7c673cae
FG
926 }
927
928 /**
494da23a
TL
929 * Delete the database entry (if any) for "key". Returns OK on
930 * success, and a non-OK status on error. It is not an error if "key"
931 * did not exist in the database.
7c673cae 932 *
494da23a
TL
933 * @param writeOpt WriteOptions to be used with delete operation
934 * @param key Key to delete within database
935 * @param offset the offset of the "key" array to be used, must be
936 * non-negative and no larger than "key".length
937 * @param len the length of the "key" array to be used, must be
938 * non-negative and no larger than ("key".length - offset)
7c673cae
FG
939 *
940 * @throws RocksDBException thrown if error happens in underlying
941 * native library.
942 */
494da23a
TL
943 public void delete(final WriteOptions writeOpt, final byte[] key,
944 final int offset, final int len) throws RocksDBException {
945 delete(nativeHandle_, writeOpt.nativeHandle_, key, offset, len);
7c673cae
FG
946 }
947
7c673cae 948 /**
494da23a
TL
949 * Remove the database entry (if any) for "key". Returns OK on
950 * success, and a non-OK status on error. It is not an error if "key"
951 * did not exist in the database.
952 *
953 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
954 * instance
955 * @param writeOpt WriteOptions to be used with delete operation
956 * @param key Key to delete within database
7c673cae
FG
957 *
958 * @throws RocksDBException thrown if error happens in underlying
959 * native library.
494da23a
TL
960 *
961 * @deprecated Use {@link #delete(ColumnFamilyHandle, WriteOptions, byte[])}
7c673cae 962 */
494da23a
TL
963 @Deprecated
964 public void remove(final ColumnFamilyHandle columnFamilyHandle,
965 final WriteOptions writeOpt, final byte[] key) throws RocksDBException {
966 delete(columnFamilyHandle, writeOpt, key);
7c673cae
FG
967 }
968
969 /**
494da23a
TL
970 * Delete the database entry (if any) for "key". Returns OK on
971 * success, and a non-OK status on error. It is not an error if "key"
972 * did not exist in the database.
7c673cae
FG
973 *
974 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
975 * instance
494da23a
TL
976 * @param writeOpt WriteOptions to be used with delete operation
977 * @param key Key to delete within database
7c673cae
FG
978 *
979 * @throws RocksDBException thrown if error happens in underlying
980 * native library.
981 */
494da23a
TL
982 public void delete(final ColumnFamilyHandle columnFamilyHandle,
983 final WriteOptions writeOpt, final byte[] key)
984 throws RocksDBException {
985 delete(nativeHandle_, writeOpt.nativeHandle_, key, 0, key.length,
7c673cae
FG
986 columnFamilyHandle.nativeHandle_);
987 }
988
989 /**
494da23a
TL
990 * Delete the database entry (if any) for "key". Returns OK on
991 * success, and a non-OK status on error. It is not an error if "key"
992 * did not exist in the database.
7c673cae
FG
993 *
994 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
995 * instance
494da23a
TL
996 * @param writeOpt WriteOptions to be used with delete operation
997 * @param key Key to delete within database
998 * @param offset the offset of the "key" array to be used, must be
999 * non-negative and no larger than "key".length
1000 * @param len the length of the "key" array to be used, must be
1001 * non-negative and no larger than ("key".length - offset)
7c673cae
FG
1002 *
1003 * @throws RocksDBException thrown if error happens in underlying
1004 * native library.
1005 */
494da23a
TL
1006 public void delete(final ColumnFamilyHandle columnFamilyHandle,
1007 final WriteOptions writeOpt, final byte[] key, final int offset,
1008 final int len) throws RocksDBException {
1009 delete(nativeHandle_, writeOpt.nativeHandle_, key, offset, len,
1010 columnFamilyHandle.nativeHandle_);
7c673cae
FG
1011 }
1012
1013 /**
494da23a
TL
1014 * Remove the database entry for {@code key}. Requires that the key exists
1015 * and was not overwritten. It is not an error if the key did not exist
1016 * in the database.
7c673cae 1017 *
494da23a
TL
1018 * If a key is overwritten (by calling {@link #put(byte[], byte[])} multiple
1019 * times), then the result of calling SingleDelete() on this key is undefined.
1020 * SingleDelete() only behaves correctly if there has been only one Put()
1021 * for this key since the previous call to SingleDelete() for this key.
1022 *
1023 * This feature is currently an experimental performance optimization
1024 * for a very specific workload. It is up to the caller to ensure that
1025 * SingleDelete is only used for a key that is not deleted using Delete() or
1026 * written using Merge(). Mixing SingleDelete operations with Deletes and
1027 * Merges can result in undefined behavior.
1028 *
1029 * @param key Key to delete within database
7c673cae
FG
1030 *
1031 * @throws RocksDBException thrown if error happens in underlying
494da23a 1032 * native library.
7c673cae 1033 */
494da23a
TL
1034 @Experimental("Performance optimization for a very specific workload")
1035 public void singleDelete(final byte[] key) throws RocksDBException {
1036 singleDelete(nativeHandle_, key, key.length);
7c673cae
FG
1037 }
1038
1039 /**
494da23a
TL
1040 * Remove the database entry for {@code key}. Requires that the key exists
1041 * and was not overwritten. It is not an error if the key did not exist
1042 * in the database.
7c673cae 1043 *
494da23a
TL
1044 * If a key is overwritten (by calling {@link #put(byte[], byte[])} multiple
1045 * times), then the result of calling SingleDelete() on this key is undefined.
1046 * SingleDelete() only behaves correctly if there has been only one Put()
1047 * for this key since the previous call to SingleDelete() for this key.
1048 *
1049 * This feature is currently an experimental performance optimization
1050 * for a very specific workload. It is up to the caller to ensure that
1051 * SingleDelete is only used for a key that is not deleted using Delete() or
1052 * written using Merge(). Mixing SingleDelete operations with Deletes and
1053 * Merges can result in undefined behavior.
1054 *
1055 * @param columnFamilyHandle The column family to delete the key from
1056 * @param key Key to delete within database
7c673cae
FG
1057 *
1058 * @throws RocksDBException thrown if error happens in underlying
494da23a 1059 * native library.
7c673cae 1060 */
494da23a
TL
1061 @Experimental("Performance optimization for a very specific workload")
1062 public void singleDelete(final ColumnFamilyHandle columnFamilyHandle,
7c673cae 1063 final byte[] key) throws RocksDBException {
494da23a 1064 singleDelete(nativeHandle_, key, key.length,
7c673cae
FG
1065 columnFamilyHandle.nativeHandle_);
1066 }
1067
1068 /**
494da23a
TL
1069 * Remove the database entry for {@code key}. Requires that the key exists
1070 * and was not overwritten. It is not an error if the key did not exist
1071 * in the database.
7c673cae 1072 *
494da23a
TL
1073 * If a key is overwritten (by calling {@link #put(byte[], byte[])} multiple
1074 * times), then the result of calling SingleDelete() on this key is undefined.
1075 * SingleDelete() only behaves correctly if there has been only one Put()
1076 * for this key since the previous call to SingleDelete() for this key.
7c673cae 1077 *
494da23a
TL
1078 * This feature is currently an experimental performance optimization
1079 * for a very specific workload. It is up to the caller to ensure that
1080 * SingleDelete is only used for a key that is not deleted using Delete() or
1081 * written using Merge(). Mixing SingleDelete operations with Deletes and
1082 * Merges can result in undefined behavior.
7c673cae 1083 *
494da23a
TL
1084 * Note: consider setting {@link WriteOptions#setSync(boolean)} true.
1085 *
1086 * @param writeOpt Write options for the delete
1087 * @param key Key to delete within database
7c673cae
FG
1088 *
1089 * @throws RocksDBException thrown if error happens in underlying
494da23a 1090 * native library.
7c673cae 1091 */
494da23a
TL
1092 @Experimental("Performance optimization for a very specific workload")
1093 public void singleDelete(final WriteOptions writeOpt, final byte[] key)
1094 throws RocksDBException {
1095 singleDelete(nativeHandle_, writeOpt.nativeHandle_, key, key.length);
7c673cae
FG
1096 }
1097
1098 /**
494da23a
TL
1099 * Remove the database entry for {@code key}. Requires that the key exists
1100 * and was not overwritten. It is not an error if the key did not exist
1101 * in the database.
7c673cae 1102 *
494da23a
TL
1103 * If a key is overwritten (by calling {@link #put(byte[], byte[])} multiple
1104 * times), then the result of calling SingleDelete() on this key is undefined.
1105 * SingleDelete() only behaves correctly if there has been only one Put()
1106 * for this key since the previous call to SingleDelete() for this key.
1107 *
1108 * This feature is currently an experimental performance optimization
1109 * for a very specific workload. It is up to the caller to ensure that
1110 * SingleDelete is only used for a key that is not deleted using Delete() or
1111 * written using Merge(). Mixing SingleDelete operations with Deletes and
1112 * Merges can result in undefined behavior.
1113 *
1114 * Note: consider setting {@link WriteOptions#setSync(boolean)} true.
1115 *
1116 * @param columnFamilyHandle The column family to delete the key from
1117 * @param writeOpt Write options for the delete
1118 * @param key Key to delete within database
7c673cae
FG
1119 *
1120 * @throws RocksDBException thrown if error happens in underlying
494da23a 1121 * native library.
7c673cae 1122 */
494da23a
TL
1123 @Experimental("Performance optimization for a very specific workload")
1124 public void singleDelete(final ColumnFamilyHandle columnFamilyHandle,
1125 final WriteOptions writeOpt, final byte[] key) throws RocksDBException {
1126 singleDelete(nativeHandle_, writeOpt.nativeHandle_, key, key.length,
1127 columnFamilyHandle.nativeHandle_);
7c673cae
FG
1128 }
1129
7c673cae
FG
1130
1131 /**
494da23a
TL
1132 * Removes the database entries in the range ["beginKey", "endKey"), i.e.,
1133 * including "beginKey" and excluding "endKey". a non-OK status on error. It
1134 * is not an error if no keys exist in the range ["beginKey", "endKey").
7c673cae 1135 *
494da23a
TL
1136 * Delete the database entry (if any) for "key". Returns OK on success, and a
1137 * non-OK status on error. It is not an error if "key" did not exist in the
1138 * database.
7c673cae 1139 *
494da23a
TL
1140 * @param beginKey First key to delete within database (inclusive)
1141 * @param endKey Last key to delete within database (exclusive)
1142 *
1143 * @throws RocksDBException thrown if error happens in underlying native
1144 * library.
7c673cae 1145 */
494da23a
TL
1146 public void deleteRange(final byte[] beginKey, final byte[] endKey)
1147 throws RocksDBException {
1148 deleteRange(nativeHandle_, beginKey, 0, beginKey.length, endKey, 0,
1149 endKey.length);
7c673cae
FG
1150 }
1151
1152 /**
494da23a
TL
1153 * Removes the database entries in the range ["beginKey", "endKey"), i.e.,
1154 * including "beginKey" and excluding "endKey". a non-OK status on error. It
1155 * is not an error if no keys exist in the range ["beginKey", "endKey").
7c673cae 1156 *
494da23a
TL
1157 * Delete the database entry (if any) for "key". Returns OK on success, and a
1158 * non-OK status on error. It is not an error if "key" did not exist in the
1159 * database.
7c673cae 1160 *
494da23a
TL
1161 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle} instance
1162 * @param beginKey First key to delete within database (inclusive)
1163 * @param endKey Last key to delete within database (exclusive)
1164 *
1165 * @throws RocksDBException thrown if error happens in underlying native
1166 * library.
7c673cae 1167 */
494da23a
TL
1168 public void deleteRange(final ColumnFamilyHandle columnFamilyHandle,
1169 final byte[] beginKey, final byte[] endKey) throws RocksDBException {
1170 deleteRange(nativeHandle_, beginKey, 0, beginKey.length, endKey, 0,
1171 endKey.length, columnFamilyHandle.nativeHandle_);
7c673cae
FG
1172 }
1173
1174 /**
494da23a
TL
1175 * Removes the database entries in the range ["beginKey", "endKey"), i.e.,
1176 * including "beginKey" and excluding "endKey". a non-OK status on error. It
1177 * is not an error if no keys exist in the range ["beginKey", "endKey").
7c673cae 1178 *
494da23a
TL
1179 * Delete the database entry (if any) for "key". Returns OK on success, and a
1180 * non-OK status on error. It is not an error if "key" did not exist in the
1181 * database.
1182 *
1183 * @param writeOpt WriteOptions to be used with delete operation
1184 * @param beginKey First key to delete within database (inclusive)
1185 * @param endKey Last key to delete within database (exclusive)
7c673cae
FG
1186 *
1187 * @throws RocksDBException thrown if error happens in underlying
494da23a 1188 * native library.
7c673cae 1189 */
494da23a
TL
1190 public void deleteRange(final WriteOptions writeOpt, final byte[] beginKey,
1191 final byte[] endKey) throws RocksDBException {
1192 deleteRange(nativeHandle_, writeOpt.nativeHandle_, beginKey, 0,
1193 beginKey.length, endKey, 0, endKey.length);
7c673cae
FG
1194 }
1195
1196 /**
494da23a
TL
1197 * Removes the database entries in the range ["beginKey", "endKey"), i.e.,
1198 * including "beginKey" and excluding "endKey". a non-OK status on error. It
1199 * is not an error if no keys exist in the range ["beginKey", "endKey").
7c673cae 1200 *
494da23a
TL
1201 * Delete the database entry (if any) for "key". Returns OK on success, and a
1202 * non-OK status on error. It is not an error if "key" did not exist in the
1203 * database.
7c673cae 1204 *
494da23a
TL
1205 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle} instance
1206 * @param writeOpt WriteOptions to be used with delete operation
1207 * @param beginKey First key to delete within database (included)
1208 * @param endKey Last key to delete within database (excluded)
7c673cae 1209 *
494da23a
TL
1210 * @throws RocksDBException thrown if error happens in underlying native
1211 * library.
7c673cae 1212 */
494da23a
TL
1213 public void deleteRange(final ColumnFamilyHandle columnFamilyHandle,
1214 final WriteOptions writeOpt, final byte[] beginKey, final byte[] endKey)
1215 throws RocksDBException {
1216 deleteRange(nativeHandle_, writeOpt.nativeHandle_, beginKey, 0,
1217 beginKey.length, endKey, 0, endKey.length,
1218 columnFamilyHandle.nativeHandle_);
7c673cae
FG
1219 }
1220
494da23a 1221
7c673cae 1222 /**
494da23a 1223 * Add merge operand for key/value pair.
7c673cae 1224 *
494da23a
TL
1225 * @param key the specified key to be merged.
1226 * @param value the value to be merged with the current value for the
1227 * specified key.
7c673cae
FG
1228 *
1229 * @throws RocksDBException thrown if error happens in underlying
1230 * native library.
1231 */
494da23a
TL
1232 public void merge(final byte[] key, final byte[] value)
1233 throws RocksDBException {
1234 merge(nativeHandle_, key, 0, key.length, value, 0, value.length);
7c673cae
FG
1235 }
1236
1237 /**
494da23a 1238 * Add merge operand for key/value pair.
7c673cae 1239 *
494da23a
TL
1240 * @param key the specified key to be merged.
1241 * @param offset the offset of the "key" array to be used, must be
1242 * non-negative and no larger than "key".length
1243 * @param len the length of the "key" array to be used, must be non-negative
1244 * and no larger than ("key".length - offset)
1245 * @param value the value to be merged with the current value for the
1246 * specified key.
1247 * @param vOffset the offset of the "value" array to be used, must be
1248 * non-negative and no longer than "key".length
1249 * @param vLen the length of the "value" array to be used, must be
1250 * non-negative and must be non-negative and no larger than
1251 * ("value".length - offset)
7c673cae
FG
1252 *
1253 * @throws RocksDBException thrown if error happens in underlying
1254 * native library.
494da23a 1255 * @throws IndexOutOfBoundsException if an offset or length is out of bounds
7c673cae 1256 */
494da23a
TL
1257 public void merge(final byte[] key, int offset, int len, final byte[] value,
1258 final int vOffset, final int vLen) throws RocksDBException {
1259 checkBounds(offset, len, key.length);
1260 checkBounds(vOffset, vLen, value.length);
1261 merge(nativeHandle_, key, offset, len, value, vOffset, vLen);
7c673cae
FG
1262 }
1263
1264 /**
494da23a 1265 * Add merge operand for key/value pair in a ColumnFamily.
7c673cae 1266 *
494da23a
TL
1267 * @param columnFamilyHandle {@link ColumnFamilyHandle} instance
1268 * @param key the specified key to be merged.
1269 * @param value the value to be merged with the current value for
1270 * the specified key.
7c673cae
FG
1271 *
1272 * @throws RocksDBException thrown if error happens in underlying
1273 * native library.
1274 */
494da23a
TL
1275 public void merge(final ColumnFamilyHandle columnFamilyHandle,
1276 final byte[] key, final byte[] value) throws RocksDBException {
1277 merge(nativeHandle_, key, 0, key.length, value, 0, value.length,
1278 columnFamilyHandle.nativeHandle_);
7c673cae
FG
1279 }
1280
1281 /**
494da23a 1282 * Add merge operand for key/value pair in a ColumnFamily.
7c673cae 1283 *
494da23a
TL
1284 * @param columnFamilyHandle {@link ColumnFamilyHandle} instance
1285 * @param key the specified key to be merged.
1286 * @param offset the offset of the "key" array to be used, must be
1287 * non-negative and no larger than "key".length
1288 * @param len the length of the "key" array to be used, must be non-negative
1289 * and no larger than ("key".length - offset)
1290 * @param value the value to be merged with the current value for
1291 * the specified key.
1292 * @param vOffset the offset of the "value" array to be used, must be
1293 * non-negative and no longer than "key".length
1294 * @param vLen the length of the "value" array to be used, must be
1295 * must be non-negative and no larger than ("value".length - offset)
7c673cae
FG
1296 *
1297 * @throws RocksDBException thrown if error happens in underlying
1298 * native library.
494da23a
TL
1299 * @throws IndexOutOfBoundsException if an offset or length is out of bounds
1300 */
1301 public void merge(final ColumnFamilyHandle columnFamilyHandle,
1302 final byte[] key, final int offset, final int len, final byte[] value,
1303 final int vOffset, final int vLen) throws RocksDBException {
1304 checkBounds(offset, len, key.length);
1305 checkBounds(vOffset, vLen, value.length);
1306 merge(nativeHandle_, key, offset, len, value, vOffset, vLen,
1307 columnFamilyHandle.nativeHandle_);
1308 }
1309
1310 /**
1311 * Add merge operand for key/value pair.
7c673cae 1312 *
494da23a
TL
1313 * @param writeOpts {@link WriteOptions} for this write.
1314 * @param key the specified key to be merged.
1315 * @param value the value to be merged with the current value for
1316 * the specified key.
1317 *
1318 * @throws RocksDBException thrown if error happens in underlying
1319 * native library.
7c673cae 1320 */
494da23a
TL
1321 public void merge(final WriteOptions writeOpts, final byte[] key,
1322 final byte[] value) throws RocksDBException {
1323 merge(nativeHandle_, writeOpts.nativeHandle_,
1324 key, 0, key.length, value, 0, value.length);
7c673cae
FG
1325 }
1326
1327 /**
494da23a 1328 * Add merge operand for key/value pair.
7c673cae 1329 *
494da23a
TL
1330 * @param writeOpts {@link WriteOptions} for this write.
1331 * @param key the specified key to be merged.
1332 * @param offset the offset of the "key" array to be used, must be
1333 * non-negative and no larger than "key".length
1334 * @param len the length of the "key" array to be used, must be non-negative
1335 * and no larger than ("value".length - offset)
1336 * @param value the value to be merged with the current value for
1337 * the specified key.
1338 * @param vOffset the offset of the "value" array to be used, must be
1339 * non-negative and no longer than "key".length
1340 * @param vLen the length of the "value" array to be used, must be
1341 * non-negative and no larger than ("value".length - offset)
7c673cae
FG
1342 *
1343 * @throws RocksDBException thrown if error happens in underlying
1344 * native library.
494da23a 1345 * @throws IndexOutOfBoundsException if an offset or length is out of bounds
7c673cae 1346 */
494da23a
TL
1347 public void merge(final WriteOptions writeOpts,
1348 final byte[] key, final int offset, final int len,
1349 final byte[] value, final int vOffset, final int vLen)
7c673cae 1350 throws RocksDBException {
494da23a
TL
1351 checkBounds(offset, len, key.length);
1352 checkBounds(vOffset, vLen, value.length);
1353 merge(nativeHandle_, writeOpts.nativeHandle_,
1354 key, offset, len, value, vOffset, vLen);
7c673cae
FG
1355 }
1356
1357 /**
494da23a 1358 * Add merge operand for key/value pair.
7c673cae 1359 *
494da23a
TL
1360 * @param columnFamilyHandle {@link ColumnFamilyHandle} instance
1361 * @param writeOpts {@link WriteOptions} for this write.
1362 * @param key the specified key to be merged.
1363 * @param value the value to be merged with the current value for the
1364 * specified key.
7c673cae
FG
1365 *
1366 * @throws RocksDBException thrown if error happens in underlying
1367 * native library.
7c673cae 1368 */
494da23a
TL
1369 public void merge(final ColumnFamilyHandle columnFamilyHandle,
1370 final WriteOptions writeOpts, final byte[] key, final byte[] value)
7c673cae 1371 throws RocksDBException {
494da23a
TL
1372 merge(nativeHandle_, writeOpts.nativeHandle_,
1373 key, 0, key.length, value, 0, value.length,
1374 columnFamilyHandle.nativeHandle_);
7c673cae
FG
1375 }
1376
1377 /**
494da23a 1378 * Add merge operand for key/value pair.
7c673cae 1379 *
494da23a
TL
1380 * @param columnFamilyHandle {@link ColumnFamilyHandle} instance
1381 * @param writeOpts {@link WriteOptions} for this write.
1382 * @param key the specified key to be merged.
1383 * @param offset the offset of the "key" array to be used, must be
1384 * non-negative and no larger than "key".length
1385 * @param len the length of the "key" array to be used, must be non-negative
1386 * and no larger than ("key".length - offset)
1387 * @param value the value to be merged with the current value for
1388 * the specified key.
1389 * @param vOffset the offset of the "value" array to be used, must be
1390 * non-negative and no longer than "key".length
1391 * @param vLen the length of the "value" array to be used, must be
1392 * non-negative and no larger than ("value".length - offset)
7c673cae
FG
1393 *
1394 * @throws RocksDBException thrown if error happens in underlying
1395 * native library.
494da23a 1396 * @throws IndexOutOfBoundsException if an offset or length is out of bounds
7c673cae 1397 */
494da23a
TL
1398 public void merge(
1399 final ColumnFamilyHandle columnFamilyHandle, final WriteOptions writeOpts,
1400 final byte[] key, final int offset, final int len,
1401 final byte[] value, final int vOffset, final int vLen)
7c673cae 1402 throws RocksDBException {
494da23a
TL
1403 checkBounds(offset, len, key.length);
1404 checkBounds(vOffset, vLen, value.length);
1405 merge(nativeHandle_, writeOpts.nativeHandle_,
1406 key, offset, len, value, vOffset, vLen,
7c673cae
FG
1407 columnFamilyHandle.nativeHandle_);
1408 }
1409
1410 /**
494da23a 1411 * Apply the specified updates to the database.
7c673cae 1412 *
494da23a
TL
1413 * @param writeOpts WriteOptions instance
1414 * @param updates WriteBatch instance
7c673cae 1415 *
494da23a
TL
1416 * @throws RocksDBException thrown if error happens in underlying
1417 * native library.
1418 */
1419 public void write(final WriteOptions writeOpts, final WriteBatch updates)
1420 throws RocksDBException {
1421 write0(nativeHandle_, writeOpts.nativeHandle_, updates.nativeHandle_);
1422 }
1423
1424 /**
1425 * Apply the specified updates to the database.
7c673cae 1426 *
494da23a
TL
1427 * @param writeOpts WriteOptions instance
1428 * @param updates WriteBatchWithIndex instance
7c673cae
FG
1429 *
1430 * @throws RocksDBException thrown if error happens in underlying
494da23a 1431 * native library.
7c673cae 1432 */
494da23a
TL
1433 public void write(final WriteOptions writeOpts,
1434 final WriteBatchWithIndex updates) throws RocksDBException {
1435 write1(nativeHandle_, writeOpts.nativeHandle_, updates.nativeHandle_);
7c673cae
FG
1436 }
1437
494da23a
TL
1438 // TODO(AR) we should improve the #get() API, returning -1 (RocksDB.NOT_FOUND) is not very nice
1439 // when we could communicate better status into, also the C++ code show that -2 could be returned
1440
7c673cae 1441 /**
494da23a 1442 * Get the value associated with the specified key within column family*
7c673cae 1443 *
494da23a
TL
1444 * @param key the key to retrieve the value.
1445 * @param value the out-value to receive the retrieved value.
7c673cae 1446 *
494da23a
TL
1447 * @return The size of the actual value that matches the specified
1448 * {@code key} in byte. If the return value is greater than the
1449 * length of {@code value}, then it indicates that the size of the
1450 * input buffer {@code value} is insufficient and partial result will
1451 * be returned. RocksDB.NOT_FOUND will be returned if the value not
1452 * found.
7c673cae
FG
1453 *
1454 * @throws RocksDBException thrown if error happens in underlying
494da23a 1455 * native library.
7c673cae 1456 */
494da23a
TL
1457 public int get(final byte[] key, final byte[] value) throws RocksDBException {
1458 return get(nativeHandle_, key, 0, key.length, value, 0, value.length);
7c673cae
FG
1459 }
1460
1461 /**
494da23a 1462 * Get the value associated with the specified key within column family*
7c673cae 1463 *
494da23a
TL
1464 * @param key the key to retrieve the value.
1465 * @param offset the offset of the "key" array to be used, must be
1466 * non-negative and no larger than "key".length
1467 * @param len the length of the "key" array to be used, must be non-negative
1468 * and no larger than ("key".length - offset)
1469 * @param value the out-value to receive the retrieved value.
1470 * @param vOffset the offset of the "value" array to be used, must be
1471 * non-negative and no longer than "value".length
1472 * @param vLen the length of the "value" array to be used, must be
1473 * non-negative and and no larger than ("value".length - offset)
7c673cae 1474 *
494da23a
TL
1475 * @return The size of the actual value that matches the specified
1476 * {@code key} in byte. If the return value is greater than the
1477 * length of {@code value}, then it indicates that the size of the
1478 * input buffer {@code value} is insufficient and partial result will
1479 * be returned. RocksDB.NOT_FOUND will be returned if the value not
1480 * found.
7c673cae
FG
1481 *
1482 * @throws RocksDBException thrown if error happens in underlying
494da23a 1483 * native library.
7c673cae 1484 */
494da23a
TL
1485 public int get(final byte[] key, final int offset, final int len,
1486 final byte[] value, final int vOffset, final int vLen)
7c673cae 1487 throws RocksDBException {
494da23a
TL
1488 checkBounds(offset, len, key.length);
1489 checkBounds(vOffset, vLen, value.length);
1490 return get(nativeHandle_, key, offset, len, value, vOffset, vLen);
7c673cae
FG
1491 }
1492
1493 /**
494da23a 1494 * Get the value associated with the specified key within column family.
7c673cae 1495 *
494da23a
TL
1496 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
1497 * instance
1498 * @param key the key to retrieve the value.
1499 * @param value the out-value to receive the retrieved value.
1500 * @return The size of the actual value that matches the specified
1501 * {@code key} in byte. If the return value is greater than the
1502 * length of {@code value}, then it indicates that the size of the
1503 * input buffer {@code value} is insufficient and partial result will
1504 * be returned. RocksDB.NOT_FOUND will be returned if the value not
1505 * found.
7c673cae
FG
1506 *
1507 * @throws RocksDBException thrown if error happens in underlying
494da23a 1508 * native library.
7c673cae 1509 */
494da23a
TL
1510 public int get(final ColumnFamilyHandle columnFamilyHandle, final byte[] key,
1511 final byte[] value) throws RocksDBException, IllegalArgumentException {
1512 return get(nativeHandle_, key, 0, key.length, value, 0, value.length,
7c673cae
FG
1513 columnFamilyHandle.nativeHandle_);
1514 }
1515
1516 /**
494da23a 1517 * Get the value associated with the specified key within column family.
7c673cae 1518 *
494da23a
TL
1519 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
1520 * instance
1521 * @param key the key to retrieve the value.
1522 * @param offset the offset of the "key" array to be used, must be
1523 * non-negative and no larger than "key".length
1524 * @param len the length of the "key" array to be used, must be non-negative
1525 * an no larger than ("key".length - offset)
1526 * @param value the out-value to receive the retrieved value.
1527 * @param vOffset the offset of the "value" array to be used, must be
1528 * non-negative and no longer than "key".length
1529 * @param vLen the length of the "value" array to be used, must be
1530 * non-negative and no larger than ("value".length - offset)
7c673cae 1531 *
494da23a
TL
1532 * @return The size of the actual value that matches the specified
1533 * {@code key} in byte. If the return value is greater than the
1534 * length of {@code value}, then it indicates that the size of the
1535 * input buffer {@code value} is insufficient and partial result will
1536 * be returned. RocksDB.NOT_FOUND will be returned if the value not
1537 * found.
1538 *
1539 * @throws RocksDBException thrown if error happens in underlying
1540 * native library.
1541 */
1542 public int get(final ColumnFamilyHandle columnFamilyHandle, final byte[] key,
1543 final int offset, final int len, final byte[] value, final int vOffset,
1544 final int vLen) throws RocksDBException, IllegalArgumentException {
1545 checkBounds(offset, len, key.length);
1546 checkBounds(vOffset, vLen, value.length);
1547 return get(nativeHandle_, key, offset, len, value, vOffset, vLen,
1548 columnFamilyHandle.nativeHandle_);
1549 }
1550
1551 /**
1552 * Get the value associated with the specified key.
1553 *
1554 * @param opt {@link org.rocksdb.ReadOptions} instance.
1555 * @param key the key to retrieve the value.
1556 * @param value the out-value to receive the retrieved value.
1557 * @return The size of the actual value that matches the specified
1558 * {@code key} in byte. If the return value is greater than the
1559 * length of {@code value}, then it indicates that the size of the
1560 * input buffer {@code value} is insufficient and partial result will
1561 * be returned. RocksDB.NOT_FOUND will be returned if the value not
1562 * found.
1563 *
1564 * @throws RocksDBException thrown if error happens in underlying
1565 * native library.
1566 */
1567 public int get(final ReadOptions opt, final byte[] key,
1568 final byte[] value) throws RocksDBException {
1569 return get(nativeHandle_, opt.nativeHandle_,
1570 key, 0, key.length, value, 0, value.length);
1571 }
1572
1573 /**
1574 * Get the value associated with the specified key.
1575 *
1576 * @param opt {@link org.rocksdb.ReadOptions} instance.
1577 * @param key the key to retrieve the value.
1578 * @param offset the offset of the "key" array to be used, must be
1579 * non-negative and no larger than "key".length
1580 * @param len the length of the "key" array to be used, must be non-negative
1581 * and no larger than ("key".length - offset)
1582 * @param value the out-value to receive the retrieved value.
1583 * @param vOffset the offset of the "value" array to be used, must be
1584 * non-negative and no longer than "key".length
1585 * @param vLen the length of the "value" array to be used, must be
1586 * non-negative and no larger than ("value".length - offset)
1587 * @return The size of the actual value that matches the specified
1588 * {@code key} in byte. If the return value is greater than the
1589 * length of {@code value}, then it indicates that the size of the
1590 * input buffer {@code value} is insufficient and partial result will
1591 * be returned. RocksDB.NOT_FOUND will be returned if the value not
1592 * found.
1593 *
1594 * @throws RocksDBException thrown if error happens in underlying
1595 * native library.
1596 */
1597 public int get(final ReadOptions opt, final byte[] key, final int offset,
1598 final int len, final byte[] value, final int vOffset, final int vLen)
1599 throws RocksDBException {
1600 checkBounds(offset, len, key.length);
1601 checkBounds(vOffset, vLen, value.length);
1602 return get(nativeHandle_, opt.nativeHandle_,
1603 key, offset, len, value, vOffset, vLen);
1604 }
1605
1606 /**
1607 * Get the value associated with the specified key within column family.
7c673cae
FG
1608 *
1609 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
1610 * instance
494da23a
TL
1611 * @param opt {@link org.rocksdb.ReadOptions} instance.
1612 * @param key the key to retrieve the value.
1613 * @param value the out-value to receive the retrieved value.
1614 * @return The size of the actual value that matches the specified
1615 * {@code key} in byte. If the return value is greater than the
1616 * length of {@code value}, then it indicates that the size of the
1617 * input buffer {@code value} is insufficient and partial result will
1618 * be returned. RocksDB.NOT_FOUND will be returned if the value not
1619 * found.
1620 *
1621 * @throws RocksDBException thrown if error happens in underlying
1622 * native library.
1623 */
1624 public int get(final ColumnFamilyHandle columnFamilyHandle,
1625 final ReadOptions opt, final byte[] key, final byte[] value)
1626 throws RocksDBException {
1627 return get(nativeHandle_, opt.nativeHandle_, key, 0, key.length, value,
1628 0, value.length, columnFamilyHandle.nativeHandle_);
1629 }
1630
1631 /**
1632 * Get the value associated with the specified key within column family.
1633 *
1634 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
1635 * instance
1636 * @param opt {@link org.rocksdb.ReadOptions} instance.
1637 * @param key the key to retrieve the value.
1638 * @param offset the offset of the "key" array to be used, must be
1639 * non-negative and no larger than "key".length
1640 * @param len the length of the "key" array to be used, must be
1641 * non-negative and and no larger than ("key".length - offset)
1642 * @param value the out-value to receive the retrieved value.
1643 * @param vOffset the offset of the "value" array to be used, must be
1644 * non-negative and no longer than "key".length
1645 * @param vLen the length of the "value" array to be used, and must be
1646 * non-negative and no larger than ("value".length - offset)
1647 * @return The size of the actual value that matches the specified
1648 * {@code key} in byte. If the return value is greater than the
1649 * length of {@code value}, then it indicates that the size of the
1650 * input buffer {@code value} is insufficient and partial result will
1651 * be returned. RocksDB.NOT_FOUND will be returned if the value not
1652 * found.
1653 *
1654 * @throws RocksDBException thrown if error happens in underlying
1655 * native library.
1656 */
1657 public int get(final ColumnFamilyHandle columnFamilyHandle,
1658 final ReadOptions opt, final byte[] key, final int offset, final int len,
1659 final byte[] value, final int vOffset, final int vLen)
1660 throws RocksDBException {
1661 checkBounds(offset, len, key.length);
1662 checkBounds(vOffset, vLen, value.length);
1663 return get(nativeHandle_, opt.nativeHandle_, key, offset, len, value,
1664 vOffset, vLen, columnFamilyHandle.nativeHandle_);
1665 }
1666
1667 /**
1668 * The simplified version of get which returns a new byte array storing
1669 * the value associated with the specified input key if any. null will be
1670 * returned if the specified key is not found.
1671 *
1672 * @param key the key retrieve the value.
1673 * @return a byte array storing the value associated with the input key if
1674 * any. null if it does not find the specified key.
1675 *
1676 * @throws RocksDBException thrown if error happens in underlying
1677 * native library.
1678 */
1679 public byte[] get(final byte[] key) throws RocksDBException {
1680 return get(nativeHandle_, key, 0, key.length);
1681 }
1682
1683 /**
1684 * The simplified version of get which returns a new byte array storing
1685 * the value associated with the specified input key if any. null will be
1686 * returned if the specified key is not found.
1687 *
1688 * @param key the key retrieve the value.
1689 * @param offset the offset of the "key" array to be used, must be
1690 * non-negative and no larger than "key".length
1691 * @param len the length of the "key" array to be used, must be non-negative
1692 * and no larger than ("key".length - offset)
1693 * @return a byte array storing the value associated with the input key if
1694 * any. null if it does not find the specified key.
1695 *
1696 * @throws RocksDBException thrown if error happens in underlying
1697 * native library.
1698 */
1699 public byte[] get(final byte[] key, final int offset,
1700 final int len) throws RocksDBException {
1701 checkBounds(offset, len, key.length);
1702 return get(nativeHandle_, key, offset, len);
1703 }
1704
1705 /**
1706 * The simplified version of get which returns a new byte array storing
1707 * the value associated with the specified input key if any. null will be
1708 * returned if the specified key is not found.
1709 *
1710 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
1711 * instance
1712 * @param key the key retrieve the value.
1713 * @return a byte array storing the value associated with the input key if
1714 * any. null if it does not find the specified key.
1715 *
1716 * @throws RocksDBException thrown if error happens in underlying
1717 * native library.
1718 */
1719 public byte[] get(final ColumnFamilyHandle columnFamilyHandle,
1720 final byte[] key) throws RocksDBException {
1721 return get(nativeHandle_, key, 0, key.length,
1722 columnFamilyHandle.nativeHandle_);
1723 }
1724
1725 /**
1726 * The simplified version of get which returns a new byte array storing
1727 * the value associated with the specified input key if any. null will be
1728 * returned if the specified key is not found.
1729 *
1730 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
1731 * instance
1732 * @param key the key retrieve the value.
1733 * @param offset the offset of the "key" array to be used, must be
1734 * non-negative and no larger than "key".length
1735 * @param len the length of the "key" array to be used, must be non-negative
1736 * and no larger than ("key".length - offset)
1737 * @return a byte array storing the value associated with the input key if
1738 * any. null if it does not find the specified key.
1739 *
1740 * @throws RocksDBException thrown if error happens in underlying
1741 * native library.
1742 */
1743 public byte[] get(final ColumnFamilyHandle columnFamilyHandle,
1744 final byte[] key, final int offset, final int len)
1745 throws RocksDBException {
1746 checkBounds(offset, len, key.length);
1747 return get(nativeHandle_, key, offset, len,
1748 columnFamilyHandle.nativeHandle_);
1749 }
1750
1751 /**
1752 * The simplified version of get which returns a new byte array storing
1753 * the value associated with the specified input key if any. null will be
1754 * returned if the specified key is not found.
1755 *
1756 * @param key the key retrieve the value.
1757 * @param opt Read options.
1758 * @return a byte array storing the value associated with the input key if
1759 * any. null if it does not find the specified key.
1760 *
1761 * @throws RocksDBException thrown if error happens in underlying
1762 * native library.
1763 */
1764 public byte[] get(final ReadOptions opt, final byte[] key)
1765 throws RocksDBException {
1766 return get(nativeHandle_, opt.nativeHandle_, key, 0, key.length);
1767 }
1768
1769 /**
1770 * The simplified version of get which returns a new byte array storing
1771 * the value associated with the specified input key if any. null will be
1772 * returned if the specified key is not found.
1773 *
1774 * @param key the key retrieve the value.
1775 * @param offset the offset of the "key" array to be used, must be
1776 * non-negative and no larger than "key".length
1777 * @param len the length of the "key" array to be used, must be non-negative
1778 * and no larger than ("key".length - offset)
1779 * @param opt Read options.
1780 * @return a byte array storing the value associated with the input key if
1781 * any. null if it does not find the specified key.
1782 *
1783 * @throws RocksDBException thrown if error happens in underlying
1784 * native library.
1785 */
1786 public byte[] get(final ReadOptions opt, final byte[] key, final int offset,
1787 final int len) throws RocksDBException {
1788 checkBounds(offset, len, key.length);
1789 return get(nativeHandle_, opt.nativeHandle_, key, offset, len);
1790 }
1791
1792 /**
1793 * The simplified version of get which returns a new byte array storing
1794 * the value associated with the specified input key if any. null will be
1795 * returned if the specified key is not found.
1796 *
1797 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
1798 * instance
1799 * @param key the key retrieve the value.
1800 * @param opt Read options.
1801 * @return a byte array storing the value associated with the input key if
1802 * any. null if it does not find the specified key.
1803 *
1804 * @throws RocksDBException thrown if error happens in underlying
1805 * native library.
1806 */
1807 public byte[] get(final ColumnFamilyHandle columnFamilyHandle,
1808 final ReadOptions opt, final byte[] key) throws RocksDBException {
1809 return get(nativeHandle_, opt.nativeHandle_, key, 0, key.length,
1810 columnFamilyHandle.nativeHandle_);
1811 }
1812
1813 /**
1814 * The simplified version of get which returns a new byte array storing
1815 * the value associated with the specified input key if any. null will be
1816 * returned if the specified key is not found.
1817 *
1818 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
1819 * instance
1820 * @param key the key retrieve the value.
1821 * @param offset the offset of the "key" array to be used, must be
1822 * non-negative and no larger than "key".length
1823 * @param len the length of the "key" array to be used, must be non-negative
1824 * and no larger than ("key".length - offset)
1825 * @param opt Read options.
1826 * @return a byte array storing the value associated with the input key if
1827 * any. null if it does not find the specified key.
1828 *
1829 * @throws RocksDBException thrown if error happens in underlying
1830 * native library.
1831 */
1832 public byte[] get(final ColumnFamilyHandle columnFamilyHandle,
1833 final ReadOptions opt, final byte[] key, final int offset, final int len)
1834 throws RocksDBException {
1835 checkBounds(offset, len, key.length);
1836 return get(nativeHandle_, opt.nativeHandle_, key, offset, len,
1837 columnFamilyHandle.nativeHandle_);
1838 }
1839
1840 /**
1841 * Returns a map of keys for which values were found in DB.
1842 *
1843 * @param keys List of keys for which values need to be retrieved.
1844 * @return Map where key of map is the key passed by user and value for map
1845 * entry is the corresponding value in DB.
1846 *
1847 * @throws RocksDBException thrown if error happens in underlying
1848 * native library.
1849 *
1850 * @deprecated Consider {@link #multiGetAsList(List)} instead.
1851 */
1852 @Deprecated
1853 public Map<byte[], byte[]> multiGet(final List<byte[]> keys)
1854 throws RocksDBException {
1855 assert(keys.size() != 0);
1856
1857 final byte[][] keysArray = keys.toArray(new byte[0][]);
1858 final int keyOffsets[] = new int[keysArray.length];
1859 final int keyLengths[] = new int[keysArray.length];
1860 for(int i = 0; i < keyLengths.length; i++) {
1861 keyLengths[i] = keysArray[i].length;
1862 }
1863
1864 final byte[][] values = multiGet(nativeHandle_, keysArray, keyOffsets,
1865 keyLengths);
1866
1867 final Map<byte[], byte[]> keyValueMap =
1868 new HashMap<>(computeCapacityHint(values.length));
1869 for(int i = 0; i < values.length; i++) {
1870 if(values[i] == null) {
1871 continue;
1872 }
1873
1874 keyValueMap.put(keys.get(i), values[i]);
1875 }
1876
1877 return keyValueMap;
1878 }
1879
1880 /**
1881 * Returns a map of keys for which values were found in DB.
1882 * <p>
1883 * Note: Every key needs to have a related column family name in
1884 * {@code columnFamilyHandleList}.
1885 * </p>
1886 *
1887 * @param columnFamilyHandleList {@link java.util.List} containing
1888 * {@link org.rocksdb.ColumnFamilyHandle} instances.
1889 * @param keys List of keys for which values need to be retrieved.
1890 * @return Map where key of map is the key passed by user and value for map
1891 * entry is the corresponding value in DB.
1892 *
1893 * @throws RocksDBException thrown if error happens in underlying
1894 * native library.
1895 * @throws IllegalArgumentException thrown if the size of passed keys is not
1896 * equal to the amount of passed column family handles.
1897 *
1898 * @deprecated Consider {@link #multiGetAsList(List, List)} instead.
1899 */
1900 @Deprecated
1901 public Map<byte[], byte[]> multiGet(
1902 final List<ColumnFamilyHandle> columnFamilyHandleList,
1903 final List<byte[]> keys) throws RocksDBException,
1904 IllegalArgumentException {
1905 assert(keys.size() != 0);
1906 // Check if key size equals cfList size. If not a exception must be
1907 // thrown. If not a Segmentation fault happens.
1908 if (keys.size() != columnFamilyHandleList.size()) {
1909 throw new IllegalArgumentException(
1910 "For each key there must be a ColumnFamilyHandle.");
1911 }
1912 final long[] cfHandles = new long[columnFamilyHandleList.size()];
1913 for (int i = 0; i < columnFamilyHandleList.size(); i++) {
1914 cfHandles[i] = columnFamilyHandleList.get(i).nativeHandle_;
1915 }
1916
1917 final byte[][] keysArray = keys.toArray(new byte[0][]);
1918 final int keyOffsets[] = new int[keysArray.length];
1919 final int keyLengths[] = new int[keysArray.length];
1920 for(int i = 0; i < keyLengths.length; i++) {
1921 keyLengths[i] = keysArray[i].length;
1922 }
1923
1924 final byte[][] values = multiGet(nativeHandle_, keysArray, keyOffsets,
1925 keyLengths, cfHandles);
1926
1927 final Map<byte[], byte[]> keyValueMap =
1928 new HashMap<>(computeCapacityHint(values.length));
1929 for(int i = 0; i < values.length; i++) {
1930 if (values[i] == null) {
1931 continue;
1932 }
1933 keyValueMap.put(keys.get(i), values[i]);
1934 }
1935 return keyValueMap;
1936 }
1937
1938 /**
1939 * Returns a map of keys for which values were found in DB.
1940 *
1941 * @param opt Read options.
1942 * @param keys of keys for which values need to be retrieved.
1943 * @return Map where key of map is the key passed by user and value for map
1944 * entry is the corresponding value in DB.
1945 *
1946 * @throws RocksDBException thrown if error happens in underlying
1947 * native library.
1948 *
1949 * @deprecated Consider {@link #multiGetAsList(ReadOptions, List)} instead.
1950 */
1951 @Deprecated
1952 public Map<byte[], byte[]> multiGet(final ReadOptions opt,
1953 final List<byte[]> keys) throws RocksDBException {
1954 assert(keys.size() != 0);
1955
1956 final byte[][] keysArray = keys.toArray(new byte[0][]);
1957 final int keyOffsets[] = new int[keysArray.length];
1958 final int keyLengths[] = new int[keysArray.length];
1959 for(int i = 0; i < keyLengths.length; i++) {
1960 keyLengths[i] = keysArray[i].length;
1961 }
1962
1963 final byte[][] values = multiGet(nativeHandle_, opt.nativeHandle_,
1964 keysArray, keyOffsets, keyLengths);
1965
1966 final Map<byte[], byte[]> keyValueMap =
1967 new HashMap<>(computeCapacityHint(values.length));
1968 for(int i = 0; i < values.length; i++) {
1969 if(values[i] == null) {
1970 continue;
1971 }
1972
1973 keyValueMap.put(keys.get(i), values[i]);
1974 }
1975
1976 return keyValueMap;
1977 }
1978
1979 /**
1980 * Returns a map of keys for which values were found in DB.
1981 * <p>
1982 * Note: Every key needs to have a related column family name in
1983 * {@code columnFamilyHandleList}.
1984 * </p>
1985 *
1986 * @param opt Read options.
1987 * @param columnFamilyHandleList {@link java.util.List} containing
1988 * {@link org.rocksdb.ColumnFamilyHandle} instances.
1989 * @param keys of keys for which values need to be retrieved.
1990 * @return Map where key of map is the key passed by user and value for map
1991 * entry is the corresponding value in DB.
1992 *
1993 * @throws RocksDBException thrown if error happens in underlying
1994 * native library.
1995 * @throws IllegalArgumentException thrown if the size of passed keys is not
1996 * equal to the amount of passed column family handles.
1997 *
1998 * @deprecated Consider {@link #multiGetAsList(ReadOptions, List, List)}
1999 * instead.
2000 */
2001 @Deprecated
2002 public Map<byte[], byte[]> multiGet(final ReadOptions opt,
2003 final List<ColumnFamilyHandle> columnFamilyHandleList,
2004 final List<byte[]> keys) throws RocksDBException {
2005 assert(keys.size() != 0);
2006 // Check if key size equals cfList size. If not a exception must be
2007 // thrown. If not a Segmentation fault happens.
2008 if (keys.size()!=columnFamilyHandleList.size()){
2009 throw new IllegalArgumentException(
2010 "For each key there must be a ColumnFamilyHandle.");
2011 }
2012 final long[] cfHandles = new long[columnFamilyHandleList.size()];
2013 for (int i = 0; i < columnFamilyHandleList.size(); i++) {
2014 cfHandles[i] = columnFamilyHandleList.get(i).nativeHandle_;
2015 }
2016
2017 final byte[][] keysArray = keys.toArray(new byte[0][]);
2018 final int keyOffsets[] = new int[keysArray.length];
2019 final int keyLengths[] = new int[keysArray.length];
2020 for(int i = 0; i < keyLengths.length; i++) {
2021 keyLengths[i] = keysArray[i].length;
2022 }
2023
2024 final byte[][] values = multiGet(nativeHandle_, opt.nativeHandle_,
2025 keysArray, keyOffsets, keyLengths, cfHandles);
2026
2027 final Map<byte[], byte[]> keyValueMap
2028 = new HashMap<>(computeCapacityHint(values.length));
2029 for(int i = 0; i < values.length; i++) {
2030 if(values[i] == null) {
2031 continue;
2032 }
2033 keyValueMap.put(keys.get(i), values[i]);
2034 }
2035
2036 return keyValueMap;
2037 }
2038
2039 /**
2040 * Takes a list of keys, and returns a list of values for the given list of
2041 * keys. List will contain null for keys which could not be found.
2042 *
2043 * @param keys List of keys for which values need to be retrieved.
2044 * @return List of values for the given list of keys. List will contain
2045 * null for keys which could not be found.
2046 *
2047 * @throws RocksDBException thrown if error happens in underlying
2048 * native library.
2049 */
2050 public List<byte[]> multiGetAsList(final List<byte[]> keys)
2051 throws RocksDBException {
2052 assert(keys.size() != 0);
2053
2054 final byte[][] keysArray = keys.toArray(new byte[keys.size()][]);
2055 final int keyOffsets[] = new int[keysArray.length];
2056 final int keyLengths[] = new int[keysArray.length];
2057 for(int i = 0; i < keyLengths.length; i++) {
2058 keyLengths[i] = keysArray[i].length;
2059 }
2060
2061 return Arrays.asList(multiGet(nativeHandle_, keysArray, keyOffsets,
2062 keyLengths));
2063 }
2064
2065 /**
2066 * Returns a list of values for the given list of keys. List will contain
2067 * null for keys which could not be found.
2068 * <p>
2069 * Note: Every key needs to have a related column family name in
2070 * {@code columnFamilyHandleList}.
2071 * </p>
2072 *
2073 * @param columnFamilyHandleList {@link java.util.List} containing
2074 * {@link org.rocksdb.ColumnFamilyHandle} instances.
2075 * @param keys List of keys for which values need to be retrieved.
2076 * @return List of values for the given list of keys. List will contain
2077 * null for keys which could not be found.
2078 *
2079 * @throws RocksDBException thrown if error happens in underlying
2080 * native library.
2081 * @throws IllegalArgumentException thrown if the size of passed keys is not
2082 * equal to the amount of passed column family handles.
2083 */
2084 public List<byte[]> multiGetAsList(
2085 final List<ColumnFamilyHandle> columnFamilyHandleList,
2086 final List<byte[]> keys) throws RocksDBException,
2087 IllegalArgumentException {
2088 assert(keys.size() != 0);
2089 // Check if key size equals cfList size. If not a exception must be
2090 // thrown. If not a Segmentation fault happens.
2091 if (keys.size() != columnFamilyHandleList.size()) {
2092 throw new IllegalArgumentException(
2093 "For each key there must be a ColumnFamilyHandle.");
2094 }
2095 final long[] cfHandles = new long[columnFamilyHandleList.size()];
2096 for (int i = 0; i < columnFamilyHandleList.size(); i++) {
2097 cfHandles[i] = columnFamilyHandleList.get(i).nativeHandle_;
2098 }
2099
2100 final byte[][] keysArray = keys.toArray(new byte[keys.size()][]);
2101 final int keyOffsets[] = new int[keysArray.length];
2102 final int keyLengths[] = new int[keysArray.length];
2103 for(int i = 0; i < keyLengths.length; i++) {
2104 keyLengths[i] = keysArray[i].length;
2105 }
2106
2107 return Arrays.asList(multiGet(nativeHandle_, keysArray, keyOffsets,
2108 keyLengths, cfHandles));
2109 }
2110
2111 /**
2112 * Returns a list of values for the given list of keys. List will contain
2113 * null for keys which could not be found.
2114 *
2115 * @param opt Read options.
2116 * @param keys of keys for which values need to be retrieved.
2117 * @return List of values for the given list of keys. List will contain
2118 * null for keys which could not be found.
7c673cae
FG
2119 *
2120 * @throws RocksDBException thrown if error happens in underlying
2121 * native library.
2122 */
494da23a
TL
2123 public List<byte[]> multiGetAsList(final ReadOptions opt,
2124 final List<byte[]> keys) throws RocksDBException {
2125 assert(keys.size() != 0);
2126
2127 final byte[][] keysArray = keys.toArray(new byte[keys.size()][]);
2128 final int keyOffsets[] = new int[keysArray.length];
2129 final int keyLengths[] = new int[keysArray.length];
2130 for(int i = 0; i < keyLengths.length; i++) {
2131 keyLengths[i] = keysArray[i].length;
2132 }
2133
2134 return Arrays.asList(multiGet(nativeHandle_, opt.nativeHandle_,
2135 keysArray, keyOffsets, keyLengths));
7c673cae
FG
2136 }
2137
2138 /**
494da23a
TL
2139 * Returns a list of values for the given list of keys. List will contain
2140 * null for keys which could not be found.
2141 * <p>
2142 * Note: Every key needs to have a related column family name in
2143 * {@code columnFamilyHandleList}.
2144 * </p>
7c673cae 2145 *
494da23a
TL
2146 * @param opt Read options.
2147 * @param columnFamilyHandleList {@link java.util.List} containing
2148 * {@link org.rocksdb.ColumnFamilyHandle} instances.
2149 * @param keys of keys for which values need to be retrieved.
2150 * @return List of values for the given list of keys. List will contain
2151 * null for keys which could not be found.
7c673cae 2152 *
494da23a
TL
2153 * @throws RocksDBException thrown if error happens in underlying
2154 * native library.
2155 * @throws IllegalArgumentException thrown if the size of passed keys is not
2156 * equal to the amount of passed column family handles.
7c673cae 2157 */
494da23a
TL
2158 public List<byte[]> multiGetAsList(final ReadOptions opt,
2159 final List<ColumnFamilyHandle> columnFamilyHandleList,
2160 final List<byte[]> keys) throws RocksDBException {
2161 assert(keys.size() != 0);
2162 // Check if key size equals cfList size. If not a exception must be
2163 // thrown. If not a Segmentation fault happens.
2164 if (keys.size()!=columnFamilyHandleList.size()){
2165 throw new IllegalArgumentException(
2166 "For each key there must be a ColumnFamilyHandle.");
2167 }
2168 final long[] cfHandles = new long[columnFamilyHandleList.size()];
2169 for (int i = 0; i < columnFamilyHandleList.size(); i++) {
2170 cfHandles[i] = columnFamilyHandleList.get(i).nativeHandle_;
2171 }
2172
2173 final byte[][] keysArray = keys.toArray(new byte[keys.size()][]);
2174 final int keyOffsets[] = new int[keysArray.length];
2175 final int keyLengths[] = new int[keysArray.length];
2176 for(int i = 0; i < keyLengths.length; i++) {
2177 keyLengths[i] = keysArray[i].length;
2178 }
2179
2180 return Arrays.asList(multiGet(nativeHandle_, opt.nativeHandle_,
2181 keysArray, keyOffsets, keyLengths, cfHandles));
7c673cae
FG
2182 }
2183
2184 /**
494da23a
TL
2185 * If the key definitely does not exist in the database, then this method
2186 * returns false, else true.
7c673cae 2187 *
494da23a
TL
2188 * This check is potentially lighter-weight than invoking DB::Get(). One way
2189 * to make this lighter weight is to avoid doing any IOs.
7c673cae 2190 *
494da23a
TL
2191 * @param key byte array of a key to search for
2192 * @param value StringBuilder instance which is a out parameter if a value is
2193 * found in block-cache.
2194 * @return boolean value indicating if key does not exist or might exist.
7c673cae 2195 */
494da23a
TL
2196 public boolean keyMayExist(final byte[] key, final StringBuilder value) {
2197 return keyMayExist(nativeHandle_, key, 0, key.length, value);
7c673cae
FG
2198 }
2199
2200 /**
494da23a
TL
2201 * If the key definitely does not exist in the database, then this method
2202 * returns false, else true.
7c673cae 2203 *
494da23a
TL
2204 * This check is potentially lighter-weight than invoking DB::Get(). One way
2205 * to make this lighter weight is to avoid doing any IOs.
7c673cae 2206 *
494da23a
TL
2207 * @param key byte array of a key to search for
2208 * @param offset the offset of the "key" array to be used, must be
2209 * non-negative and no larger than "key".length
2210 * @param len the length of the "key" array to be used, must be non-negative
2211 * and no larger than "key".length
2212 * @param value StringBuilder instance which is a out parameter if a value is
2213 * found in block-cache.
7c673cae 2214 *
494da23a 2215 * @return boolean value indicating if key does not exist or might exist.
7c673cae 2216 */
494da23a
TL
2217 public boolean keyMayExist(final byte[] key, final int offset, final int len,
2218 final StringBuilder value) {
2219 checkBounds(offset, len, key.length);
2220 return keyMayExist(nativeHandle_, key, offset, len, value);
7c673cae
FG
2221 }
2222
2223 /**
494da23a
TL
2224 * If the key definitely does not exist in the database, then this method
2225 * returns false, else true.
7c673cae 2226 *
494da23a
TL
2227 * This check is potentially lighter-weight than invoking DB::Get(). One way
2228 * to make this lighter weight is to avoid doing any IOs.
7c673cae 2229 *
494da23a
TL
2230 * @param columnFamilyHandle {@link ColumnFamilyHandle} instance
2231 * @param key byte array of a key to search for
2232 * @param value StringBuilder instance which is a out parameter if a value is
2233 * found in block-cache.
2234 * @return boolean value indicating if key does not exist or might exist.
7c673cae 2235 */
494da23a
TL
2236 public boolean keyMayExist(final ColumnFamilyHandle columnFamilyHandle,
2237 final byte[] key, final StringBuilder value) {
2238 return keyMayExist(nativeHandle_, key, 0, key.length,
2239 columnFamilyHandle.nativeHandle_, value);
7c673cae
FG
2240 }
2241
2242 /**
494da23a
TL
2243 * If the key definitely does not exist in the database, then this method
2244 * returns false, else true.
7c673cae 2245 *
494da23a
TL
2246 * This check is potentially lighter-weight than invoking DB::Get(). One way
2247 * to make this lighter weight is to avoid doing any IOs.
7c673cae 2248 *
494da23a
TL
2249 * @param columnFamilyHandle {@link ColumnFamilyHandle} instance
2250 * @param key byte array of a key to search for
2251 * @param offset the offset of the "key" array to be used, must be
2252 * non-negative and no larger than "key".length
2253 * @param len the length of the "key" array to be used, must be non-negative
2254 * and no larger than "key".length
2255 * @param value StringBuilder instance which is a out parameter if a value is
2256 * found in block-cache.
2257 * @return boolean value indicating if key does not exist or might exist.
7c673cae 2258 */
494da23a
TL
2259 public boolean keyMayExist(final ColumnFamilyHandle columnFamilyHandle,
2260 final byte[] key, int offset, int len, final StringBuilder value) {
2261 checkBounds(offset, len, key.length);
2262 return keyMayExist(nativeHandle_, key, offset, len,
2263 columnFamilyHandle.nativeHandle_, value);
7c673cae
FG
2264 }
2265
2266 /**
494da23a
TL
2267 * If the key definitely does not exist in the database, then this method
2268 * returns false, else true.
7c673cae 2269 *
494da23a
TL
2270 * This check is potentially lighter-weight than invoking DB::Get(). One way
2271 * to make this lighter weight is to avoid doing any IOs.
7c673cae 2272 *
494da23a
TL
2273 * @param readOptions {@link ReadOptions} instance
2274 * @param key byte array of a key to search for
2275 * @param value StringBuilder instance which is a out parameter if a value is
2276 * found in block-cache.
2277 * @return boolean value indicating if key does not exist or might exist.
7c673cae 2278 */
494da23a
TL
2279 public boolean keyMayExist(final ReadOptions readOptions,
2280 final byte[] key, final StringBuilder value) {
2281 return keyMayExist(nativeHandle_, readOptions.nativeHandle_,
2282 key, 0, key.length, value);
7c673cae
FG
2283 }
2284
2285 /**
494da23a
TL
2286 * If the key definitely does not exist in the database, then this method
2287 * returns false, else true.
7c673cae 2288 *
494da23a
TL
2289 * This check is potentially lighter-weight than invoking DB::Get(). One way
2290 * to make this lighter weight is to avoid doing any IOs.
7c673cae 2291 *
494da23a
TL
2292 * @param readOptions {@link ReadOptions} instance
2293 * @param key byte array of a key to search for
2294 * @param offset the offset of the "key" array to be used, must be
2295 * non-negative and no larger than "key".length
2296 * @param len the length of the "key" array to be used, must be non-negative
2297 * and no larger than "key".length
2298 * @param value StringBuilder instance which is a out parameter if a value is
2299 * found in block-cache.
2300 * @return boolean value indicating if key does not exist or might exist.
7c673cae 2301 */
494da23a
TL
2302 public boolean keyMayExist(final ReadOptions readOptions,
2303 final byte[] key, final int offset, final int len,
2304 final StringBuilder value) {
2305 checkBounds(offset, len, key.length);
2306 return keyMayExist(nativeHandle_, readOptions.nativeHandle_,
2307 key, offset, len, value);
7c673cae
FG
2308 }
2309
494da23a
TL
2310 /**
2311 * If the key definitely does not exist in the database, then this method
2312 * returns false, else true.
11fdf7f2 2313 *
494da23a
TL
2314 * This check is potentially lighter-weight than invoking DB::Get(). One way
2315 * to make this lighter weight is to avoid doing any IOs.
11fdf7f2 2316 *
494da23a
TL
2317 * @param readOptions {@link ReadOptions} instance
2318 * @param columnFamilyHandle {@link ColumnFamilyHandle} instance
2319 * @param key byte array of a key to search for
2320 * @param value StringBuilder instance which is a out parameter if a value is
2321 * found in block-cache.
2322 * @return boolean value indicating if key does not exist or might exist.
2323 */
2324 public boolean keyMayExist(final ReadOptions readOptions,
2325 final ColumnFamilyHandle columnFamilyHandle, final byte[] key,
2326 final StringBuilder value) {
2327 return keyMayExist(nativeHandle_, readOptions.nativeHandle_,
2328 key, 0, key.length, columnFamilyHandle.nativeHandle_,
2329 value);
2330 }
2331
2332 /**
2333 * If the key definitely does not exist in the database, then this method
2334 * returns false, else true.
11fdf7f2 2335 *
494da23a
TL
2336 * This check is potentially lighter-weight than invoking DB::Get(). One way
2337 * to make this lighter weight is to avoid doing any IOs.
11fdf7f2 2338 *
494da23a
TL
2339 * @param readOptions {@link ReadOptions} instance
2340 * @param columnFamilyHandle {@link ColumnFamilyHandle} instance
2341 * @param key byte array of a key to search for
2342 * @param offset the offset of the "key" array to be used, must be
2343 * non-negative and no larger than "key".length
2344 * @param len the length of the "key" array to be used, must be non-negative
2345 * and no larger than "key".length
2346 * @param value StringBuilder instance which is a out parameter if a value is
2347 * found in block-cache.
2348 * @return boolean value indicating if key does not exist or might exist.
11fdf7f2 2349 */
494da23a
TL
2350 public boolean keyMayExist(final ReadOptions readOptions,
2351 final ColumnFamilyHandle columnFamilyHandle, final byte[] key,
2352 final int offset, final int len, final StringBuilder value) {
2353 checkBounds(offset, len, key.length);
2354 return keyMayExist(nativeHandle_, readOptions.nativeHandle_,
2355 key, offset, len, columnFamilyHandle.nativeHandle_,
2356 value);
11fdf7f2
TL
2357 }
2358
7c673cae
FG
2359 /**
2360 * <p>Return a heap-allocated iterator over the contents of the
2361 * database. The result of newIterator() is initially invalid
2362 * (caller must call one of the Seek methods on the iterator
2363 * before using it).</p>
2364 *
2365 * <p>Caller should close the iterator when it is no longer needed.
2366 * The returned iterator should be closed before this db is closed.
2367 * </p>
2368 *
2369 * @return instance of iterator object.
2370 */
2371 public RocksIterator newIterator() {
2372 return new RocksIterator(this, iterator(nativeHandle_));
2373 }
2374
2375 /**
2376 * <p>Return a heap-allocated iterator over the contents of the
2377 * database. The result of newIterator() is initially invalid
2378 * (caller must call one of the Seek methods on the iterator
2379 * before using it).</p>
2380 *
2381 * <p>Caller should close the iterator when it is no longer needed.
2382 * The returned iterator should be closed before this db is closed.
2383 * </p>
2384 *
2385 * @param readOptions {@link ReadOptions} instance.
2386 * @return instance of iterator object.
2387 */
2388 public RocksIterator newIterator(final ReadOptions readOptions) {
2389 return new RocksIterator(this, iterator(nativeHandle_,
2390 readOptions.nativeHandle_));
2391 }
2392
7c673cae
FG
2393 /**
2394 * <p>Return a heap-allocated iterator over the contents of the
2395 * database. The result of newIterator() is initially invalid
2396 * (caller must call one of the Seek methods on the iterator
2397 * before using it).</p>
2398 *
2399 * <p>Caller should close the iterator when it is no longer needed.
2400 * The returned iterator should be closed before this db is closed.
2401 * </p>
2402 *
2403 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
2404 * instance
2405 * @return instance of iterator object.
2406 */
2407 public RocksIterator newIterator(
2408 final ColumnFamilyHandle columnFamilyHandle) {
2409 return new RocksIterator(this, iteratorCF(nativeHandle_,
2410 columnFamilyHandle.nativeHandle_));
2411 }
2412
2413 /**
2414 * <p>Return a heap-allocated iterator over the contents of the
2415 * database. The result of newIterator() is initially invalid
2416 * (caller must call one of the Seek methods on the iterator
2417 * before using it).</p>
2418 *
2419 * <p>Caller should close the iterator when it is no longer needed.
2420 * The returned iterator should be closed before this db is closed.
2421 * </p>
2422 *
2423 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
2424 * instance
2425 * @param readOptions {@link ReadOptions} instance.
2426 * @return instance of iterator object.
2427 */
2428 public RocksIterator newIterator(final ColumnFamilyHandle columnFamilyHandle,
2429 final ReadOptions readOptions) {
2430 return new RocksIterator(this, iteratorCF(nativeHandle_,
2431 columnFamilyHandle.nativeHandle_, readOptions.nativeHandle_));
2432 }
2433
2434 /**
2435 * Returns iterators from a consistent database state across multiple
2436 * column families. Iterators are heap allocated and need to be deleted
2437 * before the db is deleted
2438 *
2439 * @param columnFamilyHandleList {@link java.util.List} containing
2440 * {@link org.rocksdb.ColumnFamilyHandle} instances.
2441 * @return {@link java.util.List} containing {@link org.rocksdb.RocksIterator}
2442 * instances
2443 *
2444 * @throws RocksDBException thrown if error happens in underlying
2445 * native library.
2446 */
2447 public List<RocksIterator> newIterators(
2448 final List<ColumnFamilyHandle> columnFamilyHandleList)
2449 throws RocksDBException {
2450 return newIterators(columnFamilyHandleList, new ReadOptions());
2451 }
2452
2453 /**
2454 * Returns iterators from a consistent database state across multiple
2455 * column families. Iterators are heap allocated and need to be deleted
2456 * before the db is deleted
2457 *
2458 * @param columnFamilyHandleList {@link java.util.List} containing
2459 * {@link org.rocksdb.ColumnFamilyHandle} instances.
2460 * @param readOptions {@link ReadOptions} instance.
2461 * @return {@link java.util.List} containing {@link org.rocksdb.RocksIterator}
2462 * instances
2463 *
2464 * @throws RocksDBException thrown if error happens in underlying
2465 * native library.
2466 */
2467 public List<RocksIterator> newIterators(
2468 final List<ColumnFamilyHandle> columnFamilyHandleList,
2469 final ReadOptions readOptions) throws RocksDBException {
2470
2471 final long[] columnFamilyHandles = new long[columnFamilyHandleList.size()];
2472 for (int i = 0; i < columnFamilyHandleList.size(); i++) {
2473 columnFamilyHandles[i] = columnFamilyHandleList.get(i).nativeHandle_;
2474 }
2475
2476 final long[] iteratorRefs = iterators(nativeHandle_, columnFamilyHandles,
2477 readOptions.nativeHandle_);
2478
2479 final List<RocksIterator> iterators = new ArrayList<>(
2480 columnFamilyHandleList.size());
2481 for (int i=0; i<columnFamilyHandleList.size(); i++){
2482 iterators.add(new RocksIterator(this, iteratorRefs[i]));
2483 }
2484 return iterators;
2485 }
2486
494da23a 2487
7c673cae 2488 /**
494da23a
TL
2489 * <p>Return a handle to the current DB state. Iterators created with
2490 * this handle will all observe a stable snapshot of the current DB
2491 * state. The caller must call ReleaseSnapshot(result) when the
2492 * snapshot is no longer needed.</p>
7c673cae 2493 *
494da23a
TL
2494 * <p>nullptr will be returned if the DB fails to take a snapshot or does
2495 * not support snapshot.</p>
2496 *
2497 * @return Snapshot {@link Snapshot} instance
7c673cae 2498 */
494da23a
TL
2499 public Snapshot getSnapshot() {
2500 long snapshotHandle = getSnapshot(nativeHandle_);
2501 if (snapshotHandle != 0) {
2502 return new Snapshot(snapshotHandle);
2503 }
2504 return null;
7c673cae
FG
2505 }
2506
2507 /**
494da23a 2508 * Release a previously acquired snapshot.
7c673cae 2509 *
494da23a
TL
2510 * The caller must not use "snapshot" after this call.
2511 *
2512 * @param snapshot {@link Snapshot} instance
2513 */
2514 public void releaseSnapshot(final Snapshot snapshot) {
2515 if (snapshot != null) {
2516 releaseSnapshot(nativeHandle_, snapshot.nativeHandle_);
2517 }
2518 }
2519
2520 /**
2521 * DB implements can export properties about their state
2522 * via this method on a per column family level.
2523 *
2524 * <p>If {@code property} is a valid property understood by this DB
2525 * implementation, fills {@code value} with its current value and
2526 * returns true. Otherwise returns false.</p>
2527 *
2528 * <p>Valid property names include:
2529 * <ul>
2530 * <li>"rocksdb.num-files-at-level&lt;N&gt;" - return the number of files at
2531 * level &lt;N&gt;, where &lt;N&gt; is an ASCII representation of a level
2532 * number (e.g. "0").</li>
2533 * <li>"rocksdb.stats" - returns a multi-line string that describes statistics
2534 * about the internal operation of the DB.</li>
2535 * <li>"rocksdb.sstables" - returns a multi-line string that describes all
2536 * of the sstables that make up the db contents.</li>
2537 * </ul>
2538 *
2539 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
2540 * instance, or null for the default column family.
2541 * @param property to be fetched. See above for examples
2542 * @return property value
7c673cae
FG
2543 *
2544 * @throws RocksDBException thrown if error happens in underlying
2545 * native library.
2546 */
494da23a
TL
2547 public String getProperty(
2548 /* @Nullable */ final ColumnFamilyHandle columnFamilyHandle,
2549 final String property) throws RocksDBException {
2550 return getProperty(nativeHandle_,
2551 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_,
2552 property, property.length());
7c673cae
FG
2553 }
2554
2555 /**
494da23a
TL
2556 * DB implementations can export properties about their state
2557 * via this method. If "property" is a valid property understood by this
2558 * DB implementation, fills "*value" with its current value and returns
2559 * true. Otherwise returns false.
7c673cae 2560 *
494da23a
TL
2561 * <p>Valid property names include:
2562 * <ul>
2563 * <li>"rocksdb.num-files-at-level&lt;N&gt;" - return the number of files at
2564 * level &lt;N&gt;, where &lt;N&gt; is an ASCII representation of a level
2565 * number (e.g. "0").</li>
2566 * <li>"rocksdb.stats" - returns a multi-line string that describes statistics
2567 * about the internal operation of the DB.</li>
2568 * <li>"rocksdb.sstables" - returns a multi-line string that describes all
2569 * of the sstables that make up the db contents.</li>
2570 *</ul>
2571 *
2572 * @param property to be fetched. See above for examples
2573 * @return property value
7c673cae
FG
2574 *
2575 * @throws RocksDBException thrown if error happens in underlying
2576 * native library.
2577 */
494da23a
TL
2578 public String getProperty(final String property) throws RocksDBException {
2579 return getProperty(null, property);
7c673cae
FG
2580 }
2581
494da23a 2582
7c673cae 2583 /**
494da23a 2584 * Gets a property map.
7c673cae 2585 *
494da23a 2586 * @param property to be fetched.
7c673cae 2587 *
494da23a
TL
2588 * @return the property map
2589 *
2590 * @throws RocksDBException if an error happens in the underlying native code.
7c673cae 2591 */
494da23a
TL
2592 public Map<String, String> getMapProperty(final String property)
2593 throws RocksDBException {
2594 return getMapProperty(null, property);
2595 }
2596
2597 /**
2598 * Gets a property map.
2599 *
2600 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
2601 * instance, or null for the default column family.
2602 * @param property to be fetched.
2603 *
2604 * @return the property map
2605 *
2606 * @throws RocksDBException if an error happens in the underlying native code.
2607 */
2608 public Map<String, String> getMapProperty(
2609 /* @Nullable */ final ColumnFamilyHandle columnFamilyHandle,
2610 final String property) throws RocksDBException {
2611 return getMapProperty(nativeHandle_,
2612 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_,
2613 property, property.length());
2614 }
2615
2616 /**
2617 * <p> Similar to GetProperty(), but only works for a subset of properties
2618 * whose return value is a numerical value. Return the value as long.</p>
2619 *
2620 * <p><strong>Note</strong>: As the returned property is of type
2621 * {@code uint64_t} on C++ side the returning value can be negative
2622 * because Java supports in Java 7 only signed long values.</p>
2623 *
2624 * <p><strong>Java 7</strong>: To mitigate the problem of the non
2625 * existent unsigned long tpye, values should be encapsulated using
2626 * {@link java.math.BigInteger} to reflect the correct value. The correct
2627 * behavior is guaranteed if {@code 2^64} is added to negative values.</p>
2628 *
2629 * <p><strong>Java 8</strong>: In Java 8 the value should be treated as
2630 * unsigned long using provided methods of type {@link Long}.</p>
2631 *
2632 * @param property to be fetched.
2633 *
2634 * @return numerical property value.
2635 *
2636 * @throws RocksDBException if an error happens in the underlying native code.
2637 */
2638 public long getLongProperty(final String property) throws RocksDBException {
2639 return getLongProperty(null, property);
2640 }
2641
2642 /**
2643 * <p> Similar to GetProperty(), but only works for a subset of properties
2644 * whose return value is a numerical value. Return the value as long.</p>
2645 *
2646 * <p><strong>Note</strong>: As the returned property is of type
2647 * {@code uint64_t} on C++ side the returning value can be negative
2648 * because Java supports in Java 7 only signed long values.</p>
2649 *
2650 * <p><strong>Java 7</strong>: To mitigate the problem of the non
2651 * existent unsigned long tpye, values should be encapsulated using
2652 * {@link java.math.BigInteger} to reflect the correct value. The correct
2653 * behavior is guaranteed if {@code 2^64} is added to negative values.</p>
2654 *
2655 * <p><strong>Java 8</strong>: In Java 8 the value should be treated as
2656 * unsigned long using provided methods of type {@link Long}.</p>
2657 *
2658 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
2659 * instance, or null for the default column family
2660 * @param property to be fetched.
2661 *
2662 * @return numerical property value
2663 *
2664 * @throws RocksDBException if an error happens in the underlying native code.
2665 */
2666 public long getLongProperty(
2667 /* @Nullable */ final ColumnFamilyHandle columnFamilyHandle,
2668 final String property) throws RocksDBException {
2669 return getLongProperty(nativeHandle_,
2670 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_,
2671 property, property.length());
2672 }
2673
2674 /**
2675 * Reset internal stats for DB and all column families.
2676 *
2677 * Note this doesn't reset {@link Options#statistics()} as it is not
2678 * owned by DB.
2679 */
2680 public void resetStats() throws RocksDBException {
2681 resetStats(nativeHandle_);
2682 }
2683
2684 /**
2685 * <p> Return sum of the getLongProperty of all the column families</p>
2686 *
2687 * <p><strong>Note</strong>: As the returned property is of type
2688 * {@code uint64_t} on C++ side the returning value can be negative
2689 * because Java supports in Java 7 only signed long values.</p>
2690 *
2691 * <p><strong>Java 7</strong>: To mitigate the problem of the non
2692 * existent unsigned long tpye, values should be encapsulated using
2693 * {@link java.math.BigInteger} to reflect the correct value. The correct
2694 * behavior is guaranteed if {@code 2^64} is added to negative values.</p>
2695 *
2696 * <p><strong>Java 8</strong>: In Java 8 the value should be treated as
2697 * unsigned long using provided methods of type {@link Long}.</p>
2698 *
2699 * @param property to be fetched.
2700 *
2701 * @return numerical property value
2702 *
2703 * @throws RocksDBException if an error happens in the underlying native code.
2704 */
2705 public long getAggregatedLongProperty(final String property)
7c673cae 2706 throws RocksDBException {
494da23a
TL
2707 return getAggregatedLongProperty(nativeHandle_, property,
2708 property.length());
2709 }
2710
2711 /**
2712 * Get the approximate file system space used by keys in each range.
2713 *
2714 * Note that the returned sizes measure file system space usage, so
2715 * if the user data compresses by a factor of ten, the returned
2716 * sizes will be one-tenth the size of the corresponding user data size.
2717 *
2718 * If {@code sizeApproximationFlags} defines whether the returned size
2719 * should include the recently written data in the mem-tables (if
2720 * the mem-table type supports it), data serialized to disk, or both.
2721 *
2722 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
2723 * instance, or null for the default column family
2724 * @param ranges the ranges over which to approximate sizes
2725 * @param sizeApproximationFlags flags to determine what to include in the
2726 * approximation.
2727 *
2728 * @return the sizes
2729 */
2730 public long[] getApproximateSizes(
2731 /*@Nullable*/ final ColumnFamilyHandle columnFamilyHandle,
2732 final List<Range> ranges,
2733 final SizeApproximationFlag... sizeApproximationFlags) {
2734
2735 byte flags = 0x0;
2736 for (final SizeApproximationFlag sizeApproximationFlag
2737 : sizeApproximationFlags) {
2738 flags |= sizeApproximationFlag.getValue();
2739 }
2740
2741 return getApproximateSizes(nativeHandle_,
2742 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_,
2743 toRangeSliceHandles(ranges), flags);
2744 }
2745
2746 /**
2747 * Get the approximate file system space used by keys in each range for
2748 * the default column family.
2749 *
2750 * Note that the returned sizes measure file system space usage, so
2751 * if the user data compresses by a factor of ten, the returned
2752 * sizes will be one-tenth the size of the corresponding user data size.
2753 *
2754 * If {@code sizeApproximationFlags} defines whether the returned size
2755 * should include the recently written data in the mem-tables (if
2756 * the mem-table type supports it), data serialized to disk, or both.
2757 *
2758 * @param ranges the ranges over which to approximate sizes
2759 * @param sizeApproximationFlags flags to determine what to include in the
2760 * approximation.
2761 *
2762 * @return the sizes.
2763 */
2764 public long[] getApproximateSizes(final List<Range> ranges,
2765 final SizeApproximationFlag... sizeApproximationFlags) {
2766 return getApproximateSizes(null, ranges, sizeApproximationFlags);
2767 }
2768
2769 public static class CountAndSize {
2770 public final long count;
2771 public final long size;
2772
2773 public CountAndSize(final long count, final long size) {
2774 this.count = count;
2775 this.size = size;
2776 }
2777 }
2778
2779 /**
2780 * This method is similar to
2781 * {@link #getApproximateSizes(ColumnFamilyHandle, List, SizeApproximationFlag...)},
2782 * except that it returns approximate number of records and size in memtables.
2783 *
2784 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
2785 * instance, or null for the default column family
2786 * @param range the ranges over which to get the memtable stats
2787 *
2788 * @return the count and size for the range
2789 */
2790 public CountAndSize getApproximateMemTableStats(
2791 /*@Nullable*/ final ColumnFamilyHandle columnFamilyHandle,
2792 final Range range) {
2793 final long[] result = getApproximateMemTableStats(nativeHandle_,
2794 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_,
2795 range.start.getNativeHandle(),
2796 range.limit.getNativeHandle());
2797 return new CountAndSize(result[0], result[1]);
7c673cae
FG
2798 }
2799
2800 /**
494da23a
TL
2801 * This method is similar to
2802 * {@link #getApproximateSizes(ColumnFamilyHandle, List, SizeApproximationFlag...)},
2803 * except that it returns approximate number of records and size in memtables.
7c673cae 2804 *
494da23a 2805 * @param range the ranges over which to get the memtable stats
7c673cae 2806 *
494da23a 2807 * @return the count and size for the range
7c673cae 2808 */
494da23a
TL
2809 public CountAndSize getApproximateMemTableStats(
2810 final Range range) {
2811 return getApproximateMemTableStats(null, range);
7c673cae
FG
2812 }
2813
2814 /**
2815 * <p>Range compaction of database.</p>
2816 * <p><strong>Note</strong>: After the database has been compacted,
2817 * all data will have been pushed down to the last level containing
2818 * any data.</p>
2819 *
2820 * <p><strong>See also</strong></p>
2821 * <ul>
2822 * <li>{@link #compactRange(boolean, int, int)}</li>
2823 * <li>{@link #compactRange(byte[], byte[])}</li>
2824 * <li>{@link #compactRange(byte[], byte[], boolean, int, int)}</li>
2825 * </ul>
2826 *
2827 * @throws RocksDBException thrown if an error occurs within the native
2828 * part of the library.
2829 */
2830 public void compactRange() throws RocksDBException {
494da23a
TL
2831 compactRange(null);
2832 }
2833
2834 /**
2835 * <p>Range compaction of column family.</p>
2836 * <p><strong>Note</strong>: After the database has been compacted,
2837 * all data will have been pushed down to the last level containing
2838 * any data.</p>
2839 *
2840 * <p><strong>See also</strong></p>
2841 * <ul>
2842 * <li>
2843 * {@link #compactRange(ColumnFamilyHandle, boolean, int, int)}
2844 * </li>
2845 * <li>
2846 * {@link #compactRange(ColumnFamilyHandle, byte[], byte[])}
2847 * </li>
2848 * <li>
2849 * {@link #compactRange(ColumnFamilyHandle, byte[], byte[],
2850 * boolean, int, int)}
2851 * </li>
2852 * </ul>
2853 *
2854 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
2855 * instance, or null for the default column family.
2856 *
2857 * @throws RocksDBException thrown if an error occurs within the native
2858 * part of the library.
2859 */
2860 public void compactRange(
2861 /* @Nullable */ final ColumnFamilyHandle columnFamilyHandle)
2862 throws RocksDBException {
2863 compactRange(nativeHandle_, null, -1, null, -1, 0,
2864 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_);
7c673cae
FG
2865 }
2866
2867 /**
2868 * <p>Range compaction of database.</p>
2869 * <p><strong>Note</strong>: After the database has been compacted,
2870 * all data will have been pushed down to the last level containing
2871 * any data.</p>
2872 *
2873 * <p><strong>See also</strong></p>
2874 * <ul>
2875 * <li>{@link #compactRange()}</li>
2876 * <li>{@link #compactRange(boolean, int, int)}</li>
2877 * <li>{@link #compactRange(byte[], byte[], boolean, int, int)}</li>
2878 * </ul>
2879 *
2880 * @param begin start of key range (included in range)
2881 * @param end end of key range (excluded from range)
2882 *
2883 * @throws RocksDBException thrown if an error occurs within the native
2884 * part of the library.
2885 */
2886 public void compactRange(final byte[] begin, final byte[] end)
2887 throws RocksDBException {
494da23a 2888 compactRange(null, begin, end);
7c673cae
FG
2889 }
2890
2891 /**
494da23a 2892 * <p>Range compaction of column family.</p>
7c673cae
FG
2893 * <p><strong>Note</strong>: After the database has been compacted,
2894 * all data will have been pushed down to the last level containing
2895 * any data.</p>
2896 *
7c673cae
FG
2897 * <p><strong>See also</strong></p>
2898 * <ul>
494da23a
TL
2899 * <li>{@link #compactRange(ColumnFamilyHandle)}</li>
2900 * <li>
2901 * {@link #compactRange(ColumnFamilyHandle, boolean, int, int)}
2902 * </li>
2903 * <li>
2904 * {@link #compactRange(ColumnFamilyHandle, byte[], byte[],
2905 * boolean, int, int)}
2906 * </li>
7c673cae
FG
2907 * </ul>
2908 *
494da23a
TL
2909 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
2910 * instance, or null for the default column family.
2911 * @param begin start of key range (included in range)
2912 * @param end end of key range (excluded from range)
7c673cae
FG
2913 *
2914 * @throws RocksDBException thrown if an error occurs within the native
2915 * part of the library.
2916 */
494da23a
TL
2917 public void compactRange(
2918 /* @Nullable */ final ColumnFamilyHandle columnFamilyHandle,
2919 final byte[] begin, final byte[] end) throws RocksDBException {
2920 compactRange(nativeHandle_,
2921 begin, begin == null ? -1 : begin.length,
2922 end, end == null ? -1 : end.length,
2923 0, columnFamilyHandle == null ? 0: columnFamilyHandle.nativeHandle_);
7c673cae
FG
2924 }
2925
7c673cae
FG
2926 /**
2927 * <p>Range compaction of database.</p>
2928 * <p><strong>Note</strong>: After the database has been compacted,
2929 * all data will have been pushed down to the last level containing
2930 * any data.</p>
2931 *
2932 * <p>Compaction outputs should be placed in options.db_paths
2933 * [target_path_id]. Behavior is undefined if target_path_id is
2934 * out of range.</p>
2935 *
2936 * <p><strong>See also</strong></p>
2937 * <ul>
2938 * <li>{@link #compactRange()}</li>
7c673cae 2939 * <li>{@link #compactRange(byte[], byte[])}</li>
494da23a 2940 * <li>{@link #compactRange(byte[], byte[], boolean, int, int)}</li>
7c673cae
FG
2941 * </ul>
2942 *
11fdf7f2
TL
2943 * @deprecated Use {@link #compactRange(ColumnFamilyHandle, byte[], byte[], CompactRangeOptions)} instead
2944 *
494da23a
TL
2945 * @param changeLevel reduce level after compaction
2946 * @param targetLevel target level to compact to
2947 * @param targetPathId the target path id of output path
7c673cae
FG
2948 *
2949 * @throws RocksDBException thrown if an error occurs within the native
2950 * part of the library.
2951 */
11fdf7f2 2952 @Deprecated
494da23a
TL
2953 public void compactRange(final boolean changeLevel, final int targetLevel,
2954 final int targetPathId) throws RocksDBException {
2955 compactRange(null, changeLevel, targetLevel, targetPathId);
7c673cae
FG
2956 }
2957
2958 /**
2959 * <p>Range compaction of column family.</p>
2960 * <p><strong>Note</strong>: After the database has been compacted,
2961 * all data will have been pushed down to the last level containing
2962 * any data.</p>
2963 *
494da23a
TL
2964 * <p>Compaction outputs should be placed in options.db_paths
2965 * [target_path_id]. Behavior is undefined if target_path_id is
2966 * out of range.</p>
2967 *
7c673cae
FG
2968 * <p><strong>See also</strong></p>
2969 * <ul>
494da23a 2970 * <li>{@link #compactRange(ColumnFamilyHandle)}</li>
7c673cae
FG
2971 * <li>
2972 * {@link #compactRange(ColumnFamilyHandle, byte[], byte[])}
2973 * </li>
2974 * <li>
2975 * {@link #compactRange(ColumnFamilyHandle, byte[], byte[],
2976 * boolean, int, int)}
2977 * </li>
2978 * </ul>
2979 *
494da23a
TL
2980 * @deprecated Use {@link #compactRange(ColumnFamilyHandle, byte[], byte[], CompactRangeOptions)} instead
2981 *
7c673cae 2982 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
494da23a
TL
2983 * instance, or null for the default column family.
2984 * @param changeLevel reduce level after compaction
2985 * @param targetLevel target level to compact to
2986 * @param targetPathId the target path id of output path
7c673cae
FG
2987 *
2988 * @throws RocksDBException thrown if an error occurs within the native
2989 * part of the library.
2990 */
494da23a
TL
2991 @Deprecated
2992 public void compactRange(
2993 /* @Nullable */ final ColumnFamilyHandle columnFamilyHandle,
2994 final boolean changeLevel, final int targetLevel, final int targetPathId)
7c673cae 2995 throws RocksDBException {
494da23a
TL
2996 final CompactRangeOptions options = new CompactRangeOptions();
2997 options.setChangeLevel(changeLevel);
2998 options.setTargetLevel(targetLevel);
2999 options.setTargetPathId(targetPathId);
3000 compactRange(nativeHandle_,
3001 null, -1,
3002 null, -1,
3003 options.nativeHandle_,
3004 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_);
3005 }
3006
3007 /**
3008 * <p>Range compaction of database.</p>
3009 * <p><strong>Note</strong>: After the database has been compacted,
3010 * all data will have been pushed down to the last level containing
3011 * any data.</p>
3012 *
3013 * <p>Compaction outputs should be placed in options.db_paths
3014 * [target_path_id]. Behavior is undefined if target_path_id is
3015 * out of range.</p>
3016 *
3017 * <p><strong>See also</strong></p>
3018 * <ul>
3019 * <li>{@link #compactRange()}</li>
3020 * <li>{@link #compactRange(boolean, int, int)}</li>
3021 * <li>{@link #compactRange(byte[], byte[])}</li>
3022 * </ul>
3023 *
3024 * @deprecated Use {@link #compactRange(ColumnFamilyHandle, byte[], byte[], CompactRangeOptions)}
3025 * instead
3026 *
3027 * @param begin start of key range (included in range)
3028 * @param end end of key range (excluded from range)
3029 * @param changeLevel reduce level after compaction
3030 * @param targetLevel target level to compact to
3031 * @param targetPathId the target path id of output path
3032 *
3033 * @throws RocksDBException thrown if an error occurs within the native
3034 * part of the library.
3035 */
3036 @Deprecated
3037 public void compactRange(final byte[] begin, final byte[] end,
3038 final boolean changeLevel, final int targetLevel,
3039 final int targetPathId) throws RocksDBException {
3040 compactRange(null, begin, end, changeLevel, targetLevel, targetPathId);
7c673cae
FG
3041 }
3042
3043 /**
3044 * <p>Range compaction of column family.</p>
3045 * <p><strong>Note</strong>: After the database has been compacted,
3046 * all data will have been pushed down to the last level containing
3047 * any data.</p>
3048 *
494da23a
TL
3049 * <p>Compaction outputs should be placed in options.db_paths
3050 * [target_path_id]. Behavior is undefined if target_path_id is
3051 * out of range.</p>
3052 *
7c673cae
FG
3053 * <p><strong>See also</strong></p>
3054 * <ul>
3055 * <li>{@link #compactRange(ColumnFamilyHandle)}</li>
3056 * <li>
3057 * {@link #compactRange(ColumnFamilyHandle, boolean, int, int)}
3058 * </li>
3059 * <li>
494da23a 3060 * {@link #compactRange(ColumnFamilyHandle, byte[], byte[])}
7c673cae
FG
3061 * </li>
3062 * </ul>
3063 *
494da23a
TL
3064 * @deprecated Use {@link #compactRange(ColumnFamilyHandle, byte[], byte[], CompactRangeOptions)} instead
3065 *
7c673cae
FG
3066 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
3067 * instance.
3068 * @param begin start of key range (included in range)
3069 * @param end end of key range (excluded from range)
494da23a
TL
3070 * @param changeLevel reduce level after compaction
3071 * @param targetLevel target level to compact to
3072 * @param targetPathId the target path id of output path
7c673cae
FG
3073 *
3074 * @throws RocksDBException thrown if an error occurs within the native
3075 * part of the library.
3076 */
494da23a
TL
3077 @Deprecated
3078 public void compactRange(
3079 /* @Nullable */ final ColumnFamilyHandle columnFamilyHandle,
3080 final byte[] begin, final byte[] end, final boolean changeLevel,
3081 final int targetLevel, final int targetPathId)
3082 throws RocksDBException {
3083 final CompactRangeOptions options = new CompactRangeOptions();
3084 options.setChangeLevel(changeLevel);
3085 options.setTargetLevel(targetLevel);
3086 options.setTargetPathId(targetPathId);
3087 compactRange(nativeHandle_,
3088 begin, begin == null ? -1 : begin.length,
3089 end, end == null ? -1 : end.length,
3090 options.nativeHandle_,
3091 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_);
7c673cae
FG
3092 }
3093
11fdf7f2
TL
3094 /**
3095 * <p>Range compaction of column family.</p>
3096 * <p><strong>Note</strong>: After the database has been compacted,
3097 * all data will have been pushed down to the last level containing
3098 * any data.</p>
3099 *
3100 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle} instance.
3101 * @param begin start of key range (included in range)
3102 * @param end end of key range (excluded from range)
3103 * @param compactRangeOptions options for the compaction
3104 *
3105 * @throws RocksDBException thrown if an error occurs within the native
3106 * part of the library.
3107 */
3108 public void compactRange(final ColumnFamilyHandle columnFamilyHandle,
494da23a
TL
3109 final byte[] begin, final byte[] end,
3110 final CompactRangeOptions compactRangeOptions) throws RocksDBException {
3111 compactRange(nativeHandle_,
3112 begin, begin == null ? -1 : begin.length,
3113 end, end == null ? -1 : end.length,
3114 compactRangeOptions.nativeHandle_, columnFamilyHandle.nativeHandle_);
11fdf7f2
TL
3115 }
3116
7c673cae 3117 /**
494da23a 3118 * Change the options for the column family handle.
7c673cae 3119 *
494da23a
TL
3120 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
3121 * instance, or null for the default column family.
3122 * @param mutableColumnFamilyOptions the options.
3123 */
3124 public void setOptions(
3125 /* @Nullable */final ColumnFamilyHandle columnFamilyHandle,
3126 final MutableColumnFamilyOptions mutableColumnFamilyOptions)
3127 throws RocksDBException {
3128 setOptions(nativeHandle_, columnFamilyHandle.nativeHandle_,
3129 mutableColumnFamilyOptions.getKeys(),
3130 mutableColumnFamilyOptions.getValues());
3131 }
3132
3133 /**
3134 * Change the options for the default column family handle.
7c673cae 3135 *
494da23a
TL
3136 * @param mutableColumnFamilyOptions the options.
3137 */
3138 public void setOptions(
3139 final MutableColumnFamilyOptions mutableColumnFamilyOptions)
3140 throws RocksDBException {
3141 setOptions(null, mutableColumnFamilyOptions);
3142 }
3143
3144 /**
3145 * Set the options for the column family handle.
7c673cae 3146 *
494da23a
TL
3147 * @param mutableDBoptions the options.
3148 */
3149 public void setDBOptions(final MutableDBOptions mutableDBoptions)
3150 throws RocksDBException {
3151 setDBOptions(nativeHandle_,
3152 mutableDBoptions.getKeys(),
3153 mutableDBoptions.getValues());
3154 }
3155
3156 /**
3157 * Takes nputs a list of files specified by file names and
3158 * compacts them to the specified level.
3159 *
3160 * Note that the behavior is different from
3161 * {@link #compactRange(ColumnFamilyHandle, byte[], byte[])}
3162 * in that CompactFiles() performs the compaction job using the CURRENT
3163 * thread.
3164 *
3165 * @param compactionOptions compaction options
3166 * @param inputFileNames the name of the files to compact
3167 * @param outputLevel the level to which they should be compacted
3168 * @param outputPathId the id of the output path, or -1
3169 * @param compactionJobInfo the compaction job info, this parameter
3170 * will be updated with the info from compacting the files,
3171 * can just be null if you don't need it.
3172 */
3173 public List<String> compactFiles(
3174 final CompactionOptions compactionOptions,
3175 final List<String> inputFileNames,
3176 final int outputLevel,
3177 final int outputPathId,
3178 /* @Nullable */ final CompactionJobInfo compactionJobInfo)
3179 throws RocksDBException {
3180 return compactFiles(compactionOptions, null, inputFileNames, outputLevel,
3181 outputPathId, compactionJobInfo);
3182 }
3183
3184 /**
3185 * Takes a list of files specified by file names and
3186 * compacts them to the specified level.
3187 *
3188 * Note that the behavior is different from
3189 * {@link #compactRange(ColumnFamilyHandle, byte[], byte[])}
3190 * in that CompactFiles() performs the compaction job using the CURRENT
3191 * thread.
3192 *
3193 * @param compactionOptions compaction options
3194 * @param columnFamilyHandle columnFamilyHandle, or null for the
3195 * default column family
3196 * @param inputFileNames the name of the files to compact
3197 * @param outputLevel the level to which they should be compacted
3198 * @param outputPathId the id of the output path, or -1
3199 * @param compactionJobInfo the compaction job info, this parameter
3200 * will be updated with the info from compacting the files,
3201 * can just be null if you don't need it.
3202 */
3203 public List<String> compactFiles(
3204 final CompactionOptions compactionOptions,
3205 /* @Nullable */ final ColumnFamilyHandle columnFamilyHandle,
3206 final List<String> inputFileNames,
3207 final int outputLevel,
3208 final int outputPathId,
3209 /* @Nullable */ final CompactionJobInfo compactionJobInfo)
3210 throws RocksDBException {
3211 return Arrays.asList(compactFiles(nativeHandle_, compactionOptions.nativeHandle_,
3212 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_,
3213 inputFileNames.toArray(new String[0]),
3214 outputLevel,
3215 outputPathId,
3216 compactionJobInfo == null ? 0 : compactionJobInfo.nativeHandle_));
3217 }
3218
3219 /**
3220 * This function will wait until all currently running background processes
3221 * finish. After it returns, no background process will be run until
3222 * {@link #continueBackgroundWork()} is called
3223 *
3224 * @throws RocksDBException If an error occurs when pausing background work
3225 */
3226 public void pauseBackgroundWork() throws RocksDBException {
3227 pauseBackgroundWork(nativeHandle_);
3228 }
3229
3230 /**
3231 * Resumes background work which was suspended by
3232 * previously calling {@link #pauseBackgroundWork()}
3233 *
3234 * @throws RocksDBException If an error occurs when resuming background work
3235 */
3236 public void continueBackgroundWork() throws RocksDBException {
3237 continueBackgroundWork(nativeHandle_);
3238 }
3239
3240 /**
3241 * Enable automatic compactions for the given column
3242 * families if they were previously disabled.
3243 *
3244 * The function will first set the
3245 * {@link ColumnFamilyOptions#disableAutoCompactions()} option for each
3246 * column family to false, after which it will schedule a flush/compaction.
3247 *
3248 * NOTE: Setting disableAutoCompactions to 'false' through
3249 * {@link #setOptions(ColumnFamilyHandle, MutableColumnFamilyOptions)}
3250 * does NOT schedule a flush/compaction afterwards, and only changes the
3251 * parameter itself within the column family option.
3252 *
3253 * @param columnFamilyHandles the column family handles
3254 */
3255 public void enableAutoCompaction(
3256 final List<ColumnFamilyHandle> columnFamilyHandles)
3257 throws RocksDBException {
3258 enableAutoCompaction(nativeHandle_,
3259 toNativeHandleList(columnFamilyHandles));
3260 }
3261
3262 /**
3263 * Number of levels used for this DB.
3264 *
3265 * @return the number of levels
3266 */
3267 public int numberLevels() {
3268 return numberLevels(null);
3269 }
3270
3271 /**
3272 * Number of levels used for a column family in this DB.
3273 *
3274 * @param columnFamilyHandle the column family handle, or null
3275 * for the default column family
3276 *
3277 * @return the number of levels
3278 */
3279 public int numberLevels(/* @Nullable */final ColumnFamilyHandle columnFamilyHandle) {
3280 return numberLevels(nativeHandle_,
3281 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_);
3282 }
3283
3284 /**
3285 * Maximum level to which a new compacted memtable is pushed if it
3286 * does not create overlap.
3287 */
3288 public int maxMemCompactionLevel() {
3289 return maxMemCompactionLevel(null);
3290 }
3291
3292 /**
3293 * Maximum level to which a new compacted memtable is pushed if it
3294 * does not create overlap.
3295 *
3296 * @param columnFamilyHandle the column family handle
3297 */
3298 public int maxMemCompactionLevel(
3299 /* @Nullable */final ColumnFamilyHandle columnFamilyHandle) {
3300 return maxMemCompactionLevel(nativeHandle_,
3301 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_);
3302 }
3303
3304 /**
3305 * Number of files in level-0 that would stop writes.
3306 */
3307 public int level0StopWriteTrigger() {
3308 return level0StopWriteTrigger(null);
3309 }
3310
3311 /**
3312 * Number of files in level-0 that would stop writes.
3313 *
3314 * @param columnFamilyHandle the column family handle
3315 */
3316 public int level0StopWriteTrigger(
3317 /* @Nullable */final ColumnFamilyHandle columnFamilyHandle) {
3318 return level0StopWriteTrigger(nativeHandle_,
3319 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_);
3320 }
3321
3322 /**
3323 * Get DB name -- the exact same name that was provided as an argument to
3324 * as path to {@link #open(Options, String)}.
3325 *
3326 * @return the DB name
3327 */
3328 public String getName() {
3329 return getName(nativeHandle_);
3330 }
3331
3332 /**
3333 * Get the Env object from the DB
3334 *
3335 * @return the env
3336 */
3337 public Env getEnv() {
3338 final long envHandle = getEnv(nativeHandle_);
3339 if (envHandle == Env.getDefault().nativeHandle_) {
3340 return Env.getDefault();
3341 } else {
3342 final Env env = new RocksEnv(envHandle);
3343 env.disOwnNativeHandle(); // we do not own the Env!
3344 return env;
3345 }
3346 }
3347
3348 /**
3349 * <p>Flush all memory table data.</p>
3350 *
3351 * <p>Note: it must be ensured that the FlushOptions instance
3352 * is not GC'ed before this method finishes. If the wait parameter is
3353 * set to false, flush processing is asynchronous.</p>
3354 *
3355 * @param flushOptions {@link org.rocksdb.FlushOptions} instance.
3356 * @throws RocksDBException thrown if an error occurs within the native
3357 * part of the library.
3358 */
3359 public void flush(final FlushOptions flushOptions)
3360 throws RocksDBException {
3361 flush(flushOptions, (List<ColumnFamilyHandle>) null);
3362 }
3363
3364 /**
3365 * <p>Flush all memory table data.</p>
11fdf7f2 3366 *
494da23a
TL
3367 * <p>Note: it must be ensured that the FlushOptions instance
3368 * is not GC'ed before this method finishes. If the wait parameter is
3369 * set to false, flush processing is asynchronous.</p>
7c673cae 3370 *
494da23a
TL
3371 * @param flushOptions {@link org.rocksdb.FlushOptions} instance.
3372 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle} instance.
7c673cae
FG
3373 * @throws RocksDBException thrown if an error occurs within the native
3374 * part of the library.
3375 */
494da23a
TL
3376 public void flush(final FlushOptions flushOptions,
3377 /* @Nullable */ final ColumnFamilyHandle columnFamilyHandle)
3378 throws RocksDBException {
3379 flush(flushOptions,
3380 columnFamilyHandle == null ? null : Arrays.asList(columnFamilyHandle));
7c673cae
FG
3381 }
3382
3383 /**
494da23a 3384 * Flushes multiple column families.
7c673cae 3385 *
494da23a
TL
3386 * If atomic flush is not enabled, this is equivalent to calling
3387 * {@link #flush(FlushOptions, ColumnFamilyHandle)} multiple times.
11fdf7f2 3388 *
494da23a
TL
3389 * If atomic flush is enabled, this will flush all column families
3390 * specified up to the latest sequence number at the time when flush is
3391 * requested.
7c673cae 3392 *
494da23a
TL
3393 * @param flushOptions {@link org.rocksdb.FlushOptions} instance.
3394 * @param columnFamilyHandles column family handles.
7c673cae
FG
3395 * @throws RocksDBException thrown if an error occurs within the native
3396 * part of the library.
3397 */
494da23a
TL
3398 public void flush(final FlushOptions flushOptions,
3399 /* @Nullable */ final List<ColumnFamilyHandle> columnFamilyHandles)
7c673cae 3400 throws RocksDBException {
494da23a
TL
3401 flush(nativeHandle_, flushOptions.nativeHandle_,
3402 toNativeHandleList(columnFamilyHandles));
7c673cae
FG
3403 }
3404
3405 /**
494da23a
TL
3406 * Flush the WAL memory buffer to the file. If {@code sync} is true,
3407 * it calls {@link #syncWal()} afterwards.
7c673cae 3408 *
494da23a 3409 * @param sync true to also fsync to disk.
7c673cae 3410 */
494da23a
TL
3411 public void flushWal(final boolean sync) throws RocksDBException {
3412 flushWal(nativeHandle_, sync);
7c673cae
FG
3413 }
3414
3415 /**
494da23a 3416 * Sync the WAL.
7c673cae 3417 *
494da23a
TL
3418 * Note that {@link #write(WriteOptions, WriteBatch)} followed by
3419 * {@link #syncWal()} is not exactly the same as
3420 * {@link #write(WriteOptions, WriteBatch)} with
3421 * {@link WriteOptions#sync()} set to true; In the latter case the changes
3422 * won't be visible until the sync is done.
3423 *
3424 * Currently only works if {@link Options#allowMmapWrites()} is set to false.
7c673cae 3425 */
494da23a
TL
3426 public void syncWal() throws RocksDBException {
3427 syncWal(nativeHandle_);
7c673cae
FG
3428 }
3429
3430 /**
3431 * <p>The sequence number of the most recent transaction.</p>
3432 *
3433 * @return sequence number of the most
3434 * recent transaction.
3435 */
3436 public long getLatestSequenceNumber() {
3437 return getLatestSequenceNumber(nativeHandle_);
3438 }
3439
494da23a
TL
3440 /**
3441 * Instructs DB to preserve deletes with sequence numbers &gt;= sequenceNumber.
3442 *
3443 * Has no effect if DBOptions#preserveDeletes() is set to false.
3444 *
3445 * This function assumes that user calls this function with monotonically
3446 * increasing seqnums (otherwise we can't guarantee that a particular delete
3447 * hasn't been already processed).
3448 *
3449 * @param sequenceNumber the minimum sequence number to preserve
3450 *
3451 * @return true if the value was successfully updated,
3452 * false if user attempted to call if with
3453 * sequenceNumber &lt;= current value.
3454 */
3455 public boolean setPreserveDeletesSequenceNumber(final long sequenceNumber) {
3456 return setPreserveDeletesSequenceNumber(nativeHandle_, sequenceNumber);
3457 }
3458
7c673cae
FG
3459 /**
3460 * <p>Prevent file deletions. Compactions will continue to occur,
3461 * but no obsolete files will be deleted. Calling this multiple
3462 * times have the same effect as calling it once.</p>
3463 *
3464 * @throws RocksDBException thrown if operation was not performed
3465 * successfully.
3466 */
3467 public void disableFileDeletions() throws RocksDBException {
3468 disableFileDeletions(nativeHandle_);
3469 }
3470
3471 /**
3472 * <p>Allow compactions to delete obsolete files.
3473 * If force == true, the call to EnableFileDeletions()
3474 * will guarantee that file deletions are enabled after
3475 * the call, even if DisableFileDeletions() was called
3476 * multiple times before.</p>
3477 *
3478 * <p>If force == false, EnableFileDeletions will only
3479 * enable file deletion after it's been called at least
3480 * as many times as DisableFileDeletions(), enabling
3481 * the two methods to be called by two threads
3482 * concurrently without synchronization
3483 * -- i.e., file deletions will be enabled only after both
3484 * threads call EnableFileDeletions()</p>
3485 *
3486 * @param force boolean value described above.
3487 *
3488 * @throws RocksDBException thrown if operation was not performed
3489 * successfully.
3490 */
3491 public void enableFileDeletions(final boolean force)
3492 throws RocksDBException {
3493 enableFileDeletions(nativeHandle_, force);
3494 }
3495
494da23a
TL
3496 public static class LiveFiles {
3497 /**
3498 * The valid size of the manifest file. The manifest file is an ever growing
3499 * file, but only the portion specified here is valid for this snapshot.
3500 */
3501 public final long manifestFileSize;
3502
3503 /**
3504 * The files are relative to the {@link #getName()} and are not
3505 * absolute paths. Despite being relative paths, the file names begin
3506 * with "/".
3507 */
3508 public final List<String> files;
3509
3510 LiveFiles(final long manifestFileSize, final List<String> files) {
3511 this.manifestFileSize = manifestFileSize;
3512 this.files = files;
3513 }
3514 }
3515
3516 /**
3517 * Retrieve the list of all files in the database after flushing the memtable.
3518 *
3519 * See {@link #getLiveFiles(boolean)}.
3520 *
3521 * @return the live files
3522 */
3523 public LiveFiles getLiveFiles() throws RocksDBException {
3524 return getLiveFiles(true);
3525 }
3526
3527 /**
3528 * Retrieve the list of all files in the database.
3529 *
3530 * In case you have multiple column families, even if {@code flushMemtable}
3531 * is true, you still need to call {@link #getSortedWalFiles()}
3532 * after {@link #getLiveFiles(boolean)} to compensate for new data that
3533 * arrived to already-flushed column families while other column families
3534 * were flushing.
3535 *
3536 * NOTE: Calling {@link #getLiveFiles(boolean)} followed by
3537 * {@link #getSortedWalFiles()} can generate a lossless backup.
3538 *
3539 * @param flushMemtable set to true to flush before recoding the live
3540 * files. Setting to false is useful when we don't want to wait for flush
3541 * which may have to wait for compaction to complete taking an
3542 * indeterminate time.
3543 *
3544 * @return the live files
3545 */
3546 public LiveFiles getLiveFiles(final boolean flushMemtable)
3547 throws RocksDBException {
3548 final String[] result = getLiveFiles(nativeHandle_, flushMemtable);
3549 if (result == null) {
3550 return null;
3551 }
3552 final String[] files = Arrays.copyOf(result, result.length - 1);
3553 final long manifestFileSize = Long.parseLong(result[result.length - 1]);
3554
3555 return new LiveFiles(manifestFileSize, Arrays.asList(files));
3556 }
3557
3558 /**
3559 * Retrieve the sorted list of all wal files with earliest file first.
3560 *
3561 * @return the log files
3562 */
3563 public List<LogFile> getSortedWalFiles() throws RocksDBException {
3564 final LogFile[] logFiles = getSortedWalFiles(nativeHandle_);
3565 return Arrays.asList(logFiles);
3566 }
3567
7c673cae
FG
3568 /**
3569 * <p>Returns an iterator that is positioned at a write-batch containing
3570 * seq_number. If the sequence number is non existent, it returns an iterator
3571 * at the first available seq_no after the requested seq_no.</p>
3572 *
3573 * <p>Must set WAL_ttl_seconds or WAL_size_limit_MB to large values to
3574 * use this api, else the WAL files will get
3575 * cleared aggressively and the iterator might keep getting invalid before
3576 * an update is read.</p>
3577 *
3578 * @param sequenceNumber sequence number offset
3579 *
3580 * @return {@link org.rocksdb.TransactionLogIterator} instance.
3581 *
3582 * @throws org.rocksdb.RocksDBException if iterator cannot be retrieved
3583 * from native-side.
3584 */
3585 public TransactionLogIterator getUpdatesSince(final long sequenceNumber)
3586 throws RocksDBException {
3587 return new TransactionLogIterator(
3588 getUpdatesSince(nativeHandle_, sequenceNumber));
3589 }
3590
494da23a
TL
3591 /**
3592 * Delete the file name from the db directory and update the internal state to
3593 * reflect that. Supports deletion of sst and log files only. 'name' must be
3594 * path relative to the db directory. eg. 000001.sst, /archive/000003.log
3595 *
3596 * @param name the file name
3597 */
3598 public void deleteFile(final String name) throws RocksDBException {
3599 deleteFile(nativeHandle_, name);
7c673cae
FG
3600 }
3601
494da23a
TL
3602 /**
3603 * Gets a list of all table files metadata.
3604 *
3605 * @return table files metadata.
3606 */
3607 public List<LiveFileMetaData> getLiveFilesMetaData() {
3608 return Arrays.asList(getLiveFilesMetaData(nativeHandle_));
3609 }
3610
3611 /**
3612 * Obtains the meta data of the specified column family of the DB.
3613 *
3614 * @param columnFamilyHandle the column family
3615 *
3616 * @return the column family metadata
3617 */
3618 public ColumnFamilyMetaData getColumnFamilyMetaData(
3619 /* @Nullable */ final ColumnFamilyHandle columnFamilyHandle) {
3620 return getColumnFamilyMetaData(nativeHandle_,
3621 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_);
3622 }
3623
3624 /**
3625 * Obtains the meta data of the default column family of the DB.
3626 *
3627 * @return the column family metadata
3628 */
3629 public ColumnFamilyMetaData GetColumnFamilyMetaData() {
3630 return getColumnFamilyMetaData(null);
7c673cae
FG
3631 }
3632
11fdf7f2
TL
3633 /**
3634 * ingestExternalFile will load a list of external SST files (1) into the DB
3635 * We will try to find the lowest possible level that the file can fit in, and
3636 * ingest the file into this level (2). A file that have a key range that
3637 * overlap with the memtable key range will require us to Flush the memtable
3638 * first before ingesting the file.
3639 *
3640 * (1) External SST files can be created using {@link SstFileWriter}
3641 * (2) We will try to ingest the files to the lowest possible level
3642 * even if the file compression doesn't match the level compression
3643 *
3644 * @param filePathList The list of files to ingest
3645 * @param ingestExternalFileOptions the options for the ingestion
3646 *
3647 * @throws RocksDBException thrown if error happens in underlying
3648 * native library.
3649 */
3650 public void ingestExternalFile(final List<String> filePathList,
3651 final IngestExternalFileOptions ingestExternalFileOptions)
7c673cae 3652 throws RocksDBException {
11fdf7f2 3653 ingestExternalFile(nativeHandle_, getDefaultColumnFamily().nativeHandle_,
494da23a 3654 filePathList.toArray(new String[0]),
11fdf7f2 3655 filePathList.size(), ingestExternalFileOptions.nativeHandle_);
7c673cae
FG
3656 }
3657
11fdf7f2
TL
3658 /**
3659 * ingestExternalFile will load a list of external SST files (1) into the DB
3660 * We will try to find the lowest possible level that the file can fit in, and
3661 * ingest the file into this level (2). A file that have a key range that
3662 * overlap with the memtable key range will require us to Flush the memtable
3663 * first before ingesting the file.
3664 *
3665 * (1) External SST files can be created using {@link SstFileWriter}
3666 * (2) We will try to ingest the files to the lowest possible level
3667 * even if the file compression doesn't match the level compression
3668 *
3669 * @param columnFamilyHandle The column family for the ingested files
3670 * @param filePathList The list of files to ingest
3671 * @param ingestExternalFileOptions the options for the ingestion
3672 *
3673 * @throws RocksDBException thrown if error happens in underlying
3674 * native library.
3675 */
3676 public void ingestExternalFile(final ColumnFamilyHandle columnFamilyHandle,
3677 final List<String> filePathList,
3678 final IngestExternalFileOptions ingestExternalFileOptions)
7c673cae 3679 throws RocksDBException {
11fdf7f2 3680 ingestExternalFile(nativeHandle_, columnFamilyHandle.nativeHandle_,
494da23a 3681 filePathList.toArray(new String[0]),
11fdf7f2 3682 filePathList.size(), ingestExternalFileOptions.nativeHandle_);
7c673cae
FG
3683 }
3684
494da23a
TL
3685 /**
3686 * Verify checksum
3687 *
3688 * @throws RocksDBException if the checksum is not valid
3689 */
3690 public void verifyChecksum() throws RocksDBException {
3691 verifyChecksum(nativeHandle_);
3692 }
3693
3694 /**
3695 * Gets the handle for the default column family
3696 *
3697 * @return The handle of the default column family
3698 */
3699 public ColumnFamilyHandle getDefaultColumnFamily() {
3700 final ColumnFamilyHandle cfHandle = new ColumnFamilyHandle(this,
3701 getDefaultColumnFamily(nativeHandle_));
3702 cfHandle.disOwnNativeHandle();
3703 return cfHandle;
3704 }
3705
3706 /**
3707 * Get the properties of all tables.
3708 *
3709 * @param columnFamilyHandle the column family handle, or null for the default
3710 * column family.
3711 *
3712 * @return the properties
3713 */
3714 public Map<String, TableProperties> getPropertiesOfAllTables(
3715 /* @Nullable */final ColumnFamilyHandle columnFamilyHandle)
3716 throws RocksDBException {
3717 return getPropertiesOfAllTables(nativeHandle_,
3718 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_);
3719 }
3720
3721 /**
3722 * Get the properties of all tables in the default column family.
3723 *
3724 * @return the properties
3725 */
3726 public Map<String, TableProperties> getPropertiesOfAllTables()
3727 throws RocksDBException {
3728 return getPropertiesOfAllTables(null);
3729 }
3730
3731 /**
3732 * Get the properties of tables in range.
3733 *
3734 * @param columnFamilyHandle the column family handle, or null for the default
3735 * column family.
3736 * @param ranges the ranges over which to get the table properties
3737 *
3738 * @return the properties
3739 */
3740 public Map<String, TableProperties> getPropertiesOfTablesInRange(
3741 /* @Nullable */final ColumnFamilyHandle columnFamilyHandle,
3742 final List<Range> ranges) throws RocksDBException {
3743 return getPropertiesOfTablesInRange(nativeHandle_,
3744 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_,
3745 toRangeSliceHandles(ranges));
3746 }
3747
3748 /**
3749 * Get the properties of tables in range for the default column family.
3750 *
3751 * @param ranges the ranges over which to get the table properties
3752 *
3753 * @return the properties
3754 */
3755 public Map<String, TableProperties> getPropertiesOfTablesInRange(
3756 final List<Range> ranges) throws RocksDBException {
3757 return getPropertiesOfTablesInRange(null, ranges);
3758 }
3759
3760 /**
3761 * Suggest the range to compact.
3762 *
3763 * @param columnFamilyHandle the column family handle, or null for the default
3764 * column family.
3765 *
3766 * @return the suggested range.
3767 */
3768 public Range suggestCompactRange(
3769 /* @Nullable */final ColumnFamilyHandle columnFamilyHandle)
3770 throws RocksDBException {
3771 final long[] rangeSliceHandles = suggestCompactRange(nativeHandle_,
3772 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_);
3773 return new Range(new Slice(rangeSliceHandles[0]),
3774 new Slice(rangeSliceHandles[1]));
3775 }
3776
3777 /**
3778 * Suggest the range to compact for the default column family.
3779 *
3780 * @return the suggested range.
3781 */
3782 public Range suggestCompactRange()
3783 throws RocksDBException {
3784 return suggestCompactRange(null);
3785 }
3786
3787 /**
3788 * Promote L0.
3789 *
3790 * @param columnFamilyHandle the column family handle,
3791 * or null for the default column family.
3792 */
3793 public void promoteL0(
3794 /* @Nullable */final ColumnFamilyHandle columnFamilyHandle,
3795 final int targetLevel) throws RocksDBException {
3796 promoteL0(nativeHandle_,
3797 columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_,
3798 targetLevel);
3799 }
3800
3801 /**
3802 * Promote L0 for the default column family.
3803 */
3804 public void promoteL0(final int targetLevel)
3805 throws RocksDBException {
3806 promoteL0(null, targetLevel);
3807 }
3808
3809 /**
3810 * Trace DB operations.
3811 *
3812 * Use {@link #endTrace()} to stop tracing.
3813 *
3814 * @param traceOptions the options
3815 * @param traceWriter the trace writer
3816 */
3817 public void startTrace(final TraceOptions traceOptions,
3818 final AbstractTraceWriter traceWriter) throws RocksDBException {
3819 startTrace(nativeHandle_, traceOptions.getMaxTraceFileSize(),
3820 traceWriter.nativeHandle_);
3821 /**
3822 * NOTE: {@link #startTrace(long, long, long) transfers the ownership
3823 * from Java to C++, so we must disown the native handle here.
3824 */
3825 traceWriter.disOwnNativeHandle();
3826 }
3827
3828 /**
3829 * Stop tracing DB operations.
3830 *
3831 * See {@link #startTrace(TraceOptions, AbstractTraceWriter)}
3832 */
3833 public void endTrace() throws RocksDBException {
3834 endTrace(nativeHandle_);
3835 }
3836
11fdf7f2
TL
3837 /**
3838 * Static method to destroy the contents of the specified database.
3839 * Be very careful using this method.
3840 *
3841 * @param path the path to the Rocksdb database.
3842 * @param options {@link org.rocksdb.Options} instance.
3843 *
3844 * @throws RocksDBException thrown if error happens in underlying
3845 * native library.
3846 */
3847 public static void destroyDB(final String path, final Options options)
7c673cae 3848 throws RocksDBException {
11fdf7f2 3849 destroyDB(path, options.nativeHandle_);
7c673cae
FG
3850 }
3851
494da23a
TL
3852 private /* @Nullable */ long[] toNativeHandleList(
3853 /* @Nullable */ final List<? extends RocksObject> objectList) {
3854 if (objectList == null) {
3855 return null;
3856 }
3857 final int len = objectList.size();
3858 final long[] handleList = new long[len];
3859 for (int i = 0; i < len; i++) {
3860 handleList[i] = objectList.get(i).nativeHandle_;
3861 }
3862 return handleList;
3863 }
3864
3865 private static long[] toRangeSliceHandles(final List<Range> ranges) {
3866 final long rangeSliceHandles[] = new long [ranges.size() * 2];
3867 for (int i = 0, j = 0; i < ranges.size(); i++) {
3868 final Range range = ranges.get(i);
3869 rangeSliceHandles[j++] = range.start.getNativeHandle();
3870 rangeSliceHandles[j++] = range.limit.getNativeHandle();
3871 }
3872 return rangeSliceHandles;
3873 }
3874
3875 protected void storeOptionsInstance(DBOptionsInterface options) {
3876 options_ = options;
3877 }
3878
3879 private static void checkBounds(int offset, int len, int size) {
3880 if ((offset | len | (offset + len) | (size - (offset + len))) < 0) {
3881 throw new IndexOutOfBoundsException(String.format("offset(%d), len(%d), size(%d)", offset, len, size));
3882 }
3883 }
3884
3885 private static int computeCapacityHint(final int estimatedNumberOfItems) {
3886 // Default load factor for HashMap is 0.75, so N * 1.5 will be at the load
3887 // limit. We add +1 for a buffer.
3888 return (int)Math.ceil(estimatedNumberOfItems * 1.5 + 1.0);
7c673cae
FG
3889 }
3890
3891 // native methods
494da23a 3892 private native static long open(final long optionsHandle,
7c673cae
FG
3893 final String path) throws RocksDBException;
3894
3895 /**
3896 * @param optionsHandle Native handle pointing to an Options object
3897 * @param path The directory path for the database files
3898 * @param columnFamilyNames An array of column family names
3899 * @param columnFamilyOptions An array of native handles pointing to
3900 * ColumnFamilyOptions objects
3901 *
3902 * @return An array of native handles, [0] is the handle of the RocksDB object
3903 * [1..1+n] are handles of the ColumnFamilyReferences
3904 *
3905 * @throws RocksDBException thrown if the database could not be opened
3906 */
494da23a 3907 private native static long[] open(final long optionsHandle,
7c673cae
FG
3908 final String path, final byte[][] columnFamilyNames,
3909 final long[] columnFamilyOptions) throws RocksDBException;
3910
494da23a 3911 private native static long openROnly(final long optionsHandle,
7c673cae
FG
3912 final String path) throws RocksDBException;
3913
3914 /**
3915 * @param optionsHandle Native handle pointing to an Options object
3916 * @param path The directory path for the database files
3917 * @param columnFamilyNames An array of column family names
3918 * @param columnFamilyOptions An array of native handles pointing to
3919 * ColumnFamilyOptions objects
3920 *
3921 * @return An array of native handles, [0] is the handle of the RocksDB object
3922 * [1..1+n] are handles of the ColumnFamilyReferences
3923 *
3924 * @throws RocksDBException thrown if the database could not be opened
3925 */
494da23a 3926 private native static long[] openROnly(final long optionsHandle,
7c673cae
FG
3927 final String path, final byte[][] columnFamilyNames,
3928 final long[] columnFamilyOptions
3929 ) throws RocksDBException;
3930
494da23a
TL
3931 @Override protected native void disposeInternal(final long handle);
3932
3933 private native static void closeDatabase(final long handle)
3934 throws RocksDBException;
3935 private native static byte[][] listColumnFamilies(final long optionsHandle,
3936 final String path) throws RocksDBException;
3937 private native long createColumnFamily(final long handle,
3938 final byte[] columnFamilyName, final int columnFamilyNamelen,
3939 final long columnFamilyOptions) throws RocksDBException;
3940 private native long[] createColumnFamilies(final long handle,
3941 final long columnFamilyOptionsHandle, final byte[][] columnFamilyNames)
3942 throws RocksDBException;
3943 private native long[] createColumnFamilies(final long handle,
3944 final long columnFamilyOptionsHandles[], final byte[][] columnFamilyNames)
3945 throws RocksDBException;
3946 private native void dropColumnFamily(
3947 final long handle, final long cfHandle) throws RocksDBException;
3948 private native void dropColumnFamilies(final long handle,
3949 final long[] cfHandles) throws RocksDBException;
3950 //TODO(AR) best way to express DestroyColumnFamilyHandle? ...maybe in ColumnFamilyHandle?
3951 private native void put(final long handle, final byte[] key,
3952 final int keyOffset, final int keyLength, final byte[] value,
3953 final int valueOffset, int valueLength) throws RocksDBException;
3954 private native void put(final long handle, final byte[] key, final int keyOffset,
3955 final int keyLength, final byte[] value, final int valueOffset,
3956 final int valueLength, final long cfHandle) throws RocksDBException;
3957 private native void put(final long handle, final long writeOptHandle,
3958 final byte[] key, final int keyOffset, final int keyLength,
3959 final byte[] value, final int valueOffset, final int valueLength)
3960 throws RocksDBException;
3961 private native void put(final long handle, final long writeOptHandle,
3962 final byte[] key, final int keyOffset, final int keyLength,
3963 final byte[] value, final int valueOffset, final int valueLength,
3964 final long cfHandle) throws RocksDBException;
3965 private native void delete(final long handle, final byte[] key,
3966 final int keyOffset, final int keyLength) throws RocksDBException;
3967 private native void delete(final long handle, final byte[] key,
3968 final int keyOffset, final int keyLength, final long cfHandle)
3969 throws RocksDBException;
3970 private native void delete(final long handle, final long writeOptHandle,
3971 final byte[] key, final int keyOffset, final int keyLength)
3972 throws RocksDBException;
3973 private native void delete(final long handle, final long writeOptHandle,
3974 final byte[] key, final int keyOffset, final int keyLength,
3975 final long cfHandle) throws RocksDBException;
3976 private native void singleDelete(
3977 final long handle, final byte[] key, final int keyLen)
3978 throws RocksDBException;
3979 private native void singleDelete(
3980 final long handle, final byte[] key, final int keyLen,
3981 final long cfHandle) throws RocksDBException;
3982 private native void singleDelete(
3983 final long handle, final long writeOptHandle, final byte[] key,
3984 final int keyLen) throws RocksDBException;
3985 private native void singleDelete(
3986 final long handle, final long writeOptHandle,
3987 final byte[] key, final int keyLen, final long cfHandle)
7c673cae 3988 throws RocksDBException;
494da23a
TL
3989 private native void deleteRange(final long handle, final byte[] beginKey,
3990 final int beginKeyOffset, final int beginKeyLength, final byte[] endKey,
3991 final int endKeyOffset, final int endKeyLength) throws RocksDBException;
3992 private native void deleteRange(final long handle, final byte[] beginKey,
3993 final int beginKeyOffset, final int beginKeyLength, final byte[] endKey,
3994 final int endKeyOffset, final int endKeyLength, final long cfHandle)
3995 throws RocksDBException;
3996 private native void deleteRange(final long handle, final long writeOptHandle,
3997 final byte[] beginKey, final int beginKeyOffset, final int beginKeyLength,
3998 final byte[] endKey, final int endKeyOffset, final int endKeyLength)
3999 throws RocksDBException;
4000 private native void deleteRange(
4001 final long handle, final long writeOptHandle, final byte[] beginKey,
4002 final int beginKeyOffset, final int beginKeyLength, final byte[] endKey,
4003 final int endKeyOffset, final int endKeyLength, final long cfHandle)
4004 throws RocksDBException;
4005 private native void merge(final long handle, final byte[] key,
4006 final int keyOffset, final int keyLength, final byte[] value,
4007 final int valueOffset, final int valueLength) throws RocksDBException;
4008 private native void merge(final long handle, final byte[] key,
4009 final int keyOffset, final int keyLength, final byte[] value,
4010 final int valueOffset, final int valueLength, final long cfHandle)
4011 throws RocksDBException;
4012 private native void merge(final long handle, final long writeOptHandle,
4013 final byte[] key, final int keyOffset, final int keyLength,
4014 final byte[] value, final int valueOffset, final int valueLength)
4015 throws RocksDBException;
4016 private native void merge(final long handle, final long writeOptHandle,
4017 final byte[] key, final int keyOffset, final int keyLength,
4018 final byte[] value, final int valueOffset, final int valueLength,
4019 final long cfHandle) throws RocksDBException;
4020 private native void write0(final long handle, final long writeOptHandle,
4021 final long wbHandle) throws RocksDBException;
4022 private native void write1(final long handle, final long writeOptHandle,
4023 final long wbwiHandle) throws RocksDBException;
4024 private native int get(final long handle, final byte[] key,
4025 final int keyOffset, final int keyLength, final byte[] value,
4026 final int valueOffset, final int valueLength) throws RocksDBException;
4027 private native int get(final long handle, final byte[] key,
4028 final int keyOffset, final int keyLength, byte[] value,
4029 final int valueOffset, final int valueLength, final long cfHandle)
4030 throws RocksDBException;
4031 private native int get(final long handle, final long readOptHandle,
4032 final byte[] key, final int keyOffset, final int keyLength,
4033 final byte[] value, final int valueOffset, final int valueLength)
4034 throws RocksDBException;
4035 private native int get(final long handle, final long readOptHandle,
4036 final byte[] key, final int keyOffset, final int keyLength,
4037 final byte[] value, final int valueOffset, final int valueLength,
4038 final long cfHandle) throws RocksDBException;
4039 private native byte[] get(final long handle, byte[] key, final int keyOffset,
4040 final int keyLength) throws RocksDBException;
4041 private native byte[] get(final long handle, final byte[] key,
4042 final int keyOffset, final int keyLength, final long cfHandle)
4043 throws RocksDBException;
4044 private native byte[] get(final long handle, final long readOptHandle,
4045 final byte[] key, final int keyOffset, final int keyLength)
4046 throws RocksDBException;
4047 private native byte[] get(final long handle,
4048 final long readOptHandle, final byte[] key, final int keyOffset,
4049 final int keyLength, final long cfHandle) throws RocksDBException;
4050 private native byte[][] multiGet(final long dbHandle, final byte[][] keys,
4051 final int[] keyOffsets, final int[] keyLengths);
4052 private native byte[][] multiGet(final long dbHandle, final byte[][] keys,
4053 final int[] keyOffsets, final int[] keyLengths,
4054 final long[] columnFamilyHandles);
4055 private native byte[][] multiGet(final long dbHandle, final long rOptHandle,
4056 final byte[][] keys, final int[] keyOffsets, final int[] keyLengths);
4057 private native byte[][] multiGet(final long dbHandle, final long rOptHandle,
4058 final byte[][] keys, final int[] keyOffsets, final int[] keyLengths,
4059 final long[] columnFamilyHandles);
4060 private native boolean keyMayExist(final long handle, final byte[] key,
7c673cae
FG
4061 final int keyOffset, final int keyLength,
4062 final StringBuilder stringBuilder);
494da23a 4063 private native boolean keyMayExist(final long handle, final byte[] key,
7c673cae
FG
4064 final int keyOffset, final int keyLength, final long cfHandle,
4065 final StringBuilder stringBuilder);
494da23a 4066 private native boolean keyMayExist(final long handle,
7c673cae
FG
4067 final long optionsHandle, final byte[] key, final int keyOffset,
4068 final int keyLength, final StringBuilder stringBuilder);
494da23a 4069 private native boolean keyMayExist(final long handle,
7c673cae
FG
4070 final long optionsHandle, final byte[] key, final int keyOffset,
4071 final int keyLength, final long cfHandle,
4072 final StringBuilder stringBuilder);
494da23a
TL
4073 private native long iterator(final long handle);
4074 private native long iterator(final long handle, final long readOptHandle);
4075 private native long iteratorCF(final long handle, final long cfHandle);
4076 private native long iteratorCF(final long handle, final long cfHandle,
4077 final long readOptHandle);
4078 private native long[] iterators(final long handle,
4079 final long[] columnFamilyHandles, final long readOptHandle)
7c673cae 4080 throws RocksDBException;
494da23a
TL
4081 private native long getSnapshot(final long nativeHandle);
4082 private native void releaseSnapshot(
4083 final long nativeHandle, final long snapshotHandle);
4084 private native String getProperty(final long nativeHandle,
4085 final long cfHandle, final String property, final int propertyLength)
7c673cae 4086 throws RocksDBException;
494da23a
TL
4087 private native Map<String, String> getMapProperty(final long nativeHandle,
4088 final long cfHandle, final String property, final int propertyLength)
7c673cae 4089 throws RocksDBException;
494da23a
TL
4090 private native long getLongProperty(final long nativeHandle,
4091 final long cfHandle, final String property, final int propertyLength)
7c673cae 4092 throws RocksDBException;
494da23a 4093 private native void resetStats(final long nativeHandle)
7c673cae 4094 throws RocksDBException;
494da23a
TL
4095 private native long getAggregatedLongProperty(final long nativeHandle,
4096 final String property, int propertyLength) throws RocksDBException;
4097 private native long[] getApproximateSizes(final long nativeHandle,
4098 final long columnFamilyHandle, final long[] rangeSliceHandles,
4099 final byte includeFlags);
4100 private final native long[] getApproximateMemTableStats(
4101 final long nativeHandle, final long columnFamilyHandle,
4102 final long rangeStartSliceHandle, final long rangeLimitSliceHandle);
4103 private native void compactRange(final long handle,
4104 /* @Nullable */ final byte[] begin, final int beginLen,
4105 /* @Nullable */ final byte[] end, final int endLen,
4106 final long compactRangeOptHandle, final long cfHandle)
7c673cae 4107 throws RocksDBException;
494da23a
TL
4108 private native void setOptions(final long handle, final long cfHandle,
4109 final String[] keys, final String[] values) throws RocksDBException;
4110 private native void setDBOptions(final long handle,
4111 final String[] keys, final String[] values) throws RocksDBException;
4112 private native String[] compactFiles(final long handle,
4113 final long compactionOptionsHandle,
4114 final long columnFamilyHandle,
4115 final String[] inputFileNames,
4116 final int outputLevel,
4117 final int outputPathId,
4118 final long compactionJobInfoHandle) throws RocksDBException;
4119 private native void pauseBackgroundWork(final long handle)
7c673cae 4120 throws RocksDBException;
494da23a 4121 private native void continueBackgroundWork(final long handle)
7c673cae 4122 throws RocksDBException;
494da23a
TL
4123 private native void enableAutoCompaction(final long handle,
4124 final long[] columnFamilyHandles) throws RocksDBException;
4125 private native int numberLevels(final long handle,
4126 final long columnFamilyHandle);
4127 private native int maxMemCompactionLevel(final long handle,
4128 final long columnFamilyHandle);
4129 private native int level0StopWriteTrigger(final long handle,
4130 final long columnFamilyHandle);
4131 private native String getName(final long handle);
4132 private native long getEnv(final long handle);
4133 private native void flush(final long handle, final long flushOptHandle,
4134 /* @Nullable */ final long[] cfHandles) throws RocksDBException;
4135 private native void flushWal(final long handle, final boolean sync)
7c673cae 4136 throws RocksDBException;
494da23a
TL
4137 private native void syncWal(final long handle) throws RocksDBException;
4138 private native long getLatestSequenceNumber(final long handle);
4139 private native boolean setPreserveDeletesSequenceNumber(final long handle,
4140 final long sequenceNumber);
4141 private native void disableFileDeletions(long handle) throws RocksDBException;
4142 private native void enableFileDeletions(long handle, boolean force)
7c673cae 4143 throws RocksDBException;
494da23a
TL
4144 private native String[] getLiveFiles(final long handle,
4145 final boolean flushMemtable) throws RocksDBException;
4146 private native LogFile[] getSortedWalFiles(final long handle)
7c673cae 4147 throws RocksDBException;
494da23a
TL
4148 private native long getUpdatesSince(final long handle,
4149 final long sequenceNumber) throws RocksDBException;
4150 private native void deleteFile(final long handle, final String name)
7c673cae 4151 throws RocksDBException;
494da23a
TL
4152 private native LiveFileMetaData[] getLiveFilesMetaData(final long handle);
4153 private native ColumnFamilyMetaData getColumnFamilyMetaData(
4154 final long handle, final long columnFamilyHandle);
4155 private native void ingestExternalFile(final long handle,
4156 final long columnFamilyHandle, final String[] filePathList,
4157 final int filePathListLen, final long ingestExternalFileOptionsHandle)
7c673cae 4158 throws RocksDBException;
494da23a
TL
4159 private native void verifyChecksum(final long handle) throws RocksDBException;
4160 private native long getDefaultColumnFamily(final long handle);
4161 private native Map<String, TableProperties> getPropertiesOfAllTables(
4162 final long handle, final long columnFamilyHandle) throws RocksDBException;
4163 private native Map<String, TableProperties> getPropertiesOfTablesInRange(
4164 final long handle, final long columnFamilyHandle,
4165 final long[] rangeSliceHandles);
4166 private native long[] suggestCompactRange(final long handle,
4167 final long columnFamilyHandle) throws RocksDBException;
4168 private native void promoteL0(final long handle,
4169 final long columnFamilyHandle, final int tragetLevel)
7c673cae 4170 throws RocksDBException;
494da23a
TL
4171 private native void startTrace(final long handle, final long maxTraceFileSize,
4172 final long traceWriterHandle) throws RocksDBException;
4173 private native void endTrace(final long handle) throws RocksDBException;
4174
4175
11fdf7f2
TL
4176 private native static void destroyDB(final String path,
4177 final long optionsHandle) throws RocksDBException;
494da23a 4178
7c673cae
FG
4179 protected DBOptionsInterface options_;
4180}