1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
9 * Options that control write operations.
11 * Note that developers should call WriteOptions.dispose() to release the
12 * c++ side memory before a WriteOptions instance runs out of scope.
14 public class WriteOptions
extends RocksObject
{
16 * Construct WriteOptions instance.
18 public WriteOptions() {
19 super(newWriteOptions());
24 * If true, the write will be flushed from the operating system
25 * buffer cache (by calling WritableFile::Sync()) before the write
26 * is considered complete. If this flag is true, writes will be
29 * If this flag is false, and the machine crashes, some recent
30 * writes may be lost. Note that if it is just the process that
31 * crashes (i.e., the machine does not reboot), no writes will be
32 * lost even if sync==false.
34 * In other words, a DB write with sync==false has similar
35 * crash semantics as the "write()" system call. A DB write
36 * with sync==true has similar crash semantics to a "write()"
37 * system call followed by "fdatasync()".
41 * @param flag a boolean flag to indicate whether a write
42 * should be synchronized.
43 * @return the instance of the current WriteOptions.
45 public WriteOptions
setSync(final boolean flag
) {
46 setSync(nativeHandle_
, flag
);
51 * If true, the write will be flushed from the operating system
52 * buffer cache (by calling WritableFile::Sync()) before the write
53 * is considered complete. If this flag is true, writes will be
56 * If this flag is false, and the machine crashes, some recent
57 * writes may be lost. Note that if it is just the process that
58 * crashes (i.e., the machine does not reboot), no writes will be
59 * lost even if sync==false.
61 * In other words, a DB write with sync==false has similar
62 * crash semantics as the "write()" system call. A DB write
63 * with sync==true has similar crash semantics to a "write()"
64 * system call followed by "fdatasync()".
66 * @return boolean value indicating if sync is active.
68 public boolean sync() {
69 return sync(nativeHandle_
);
73 * If true, writes will not first go to the write ahead log,
74 * and the write may got lost after a crash.
76 * @param flag a boolean flag to specify whether to disable
77 * write-ahead-log on writes.
78 * @return the instance of the current WriteOptions.
80 public WriteOptions
setDisableWAL(final boolean flag
) {
81 setDisableWAL(nativeHandle_
, flag
);
86 * If true, writes will not first go to the write ahead log,
87 * and the write may got lost after a crash.
89 * @return boolean value indicating if WAL is disabled.
91 public boolean disableWAL() {
92 return disableWAL(nativeHandle_
);
96 * If true and if user is trying to write to column families that don't exist
97 * (they were dropped), ignore the write (don't return an error). If there
98 * are multiple writes in a WriteBatch, other writes will succeed.
102 * @param ignoreMissingColumnFamilies true to ignore writes to column families
104 * @return the instance of the current WriteOptions.
106 public WriteOptions
setIgnoreMissingColumnFamilies(
107 final boolean ignoreMissingColumnFamilies
) {
108 setIgnoreMissingColumnFamilies(nativeHandle_
, ignoreMissingColumnFamilies
);
113 * If true and if user is trying to write to column families that don't exist
114 * (they were dropped), ignore the write (don't return an error). If there
115 * are multiple writes in a WriteBatch, other writes will succeed.
119 * @return true if writes to column families which don't exist are ignored
121 public boolean ignoreMissingColumnFamilies() {
122 return ignoreMissingColumnFamilies(nativeHandle_
);
126 * If true and we need to wait or sleep for the write request, fails
127 * immediately with {@link Status.Code#Incomplete}.
129 * @param noSlowdown true to fail write requests if we need to wait or sleep
130 * @return the instance of the current WriteOptions.
132 public WriteOptions
setNoSlowdown(final boolean noSlowdown
) {
133 setNoSlowdown(nativeHandle_
, noSlowdown
);
138 * If true and we need to wait or sleep for the write request, fails
139 * immediately with {@link Status.Code#Incomplete}.
141 * @return true when write requests are failed if we need to wait or sleep
143 public boolean noSlowdown() {
144 return noSlowdown(nativeHandle_
);
147 private native static long newWriteOptions();
148 private native void setSync(long handle
, boolean flag
);
149 private native boolean sync(long handle
);
150 private native void setDisableWAL(long handle
, boolean flag
);
151 private native boolean disableWAL(long handle
);
152 private native void setIgnoreMissingColumnFamilies(final long handle
,
153 final boolean ignoreMissingColumnFamilies
);
154 private native boolean ignoreMissingColumnFamilies(final long handle
);
155 private native void setNoSlowdown(final long handle
,
156 final boolean noSlowdown
);
157 private native boolean noSlowdown(final long handle
);
158 @Override protected final native void disposeInternal(final long handle
);