]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/main/java/org/rocksdb/WriteOptions.java
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / WriteOptions.java
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.
5
6 package org.rocksdb;
7
8 /**
9 * Options that control write operations.
10 *
11 * Note that developers should call WriteOptions.dispose() to release the
12 * c++ side memory before a WriteOptions instance runs out of scope.
13 */
14 public class WriteOptions extends RocksObject {
15 /**
16 * Construct WriteOptions instance.
17 */
18 public WriteOptions() {
19 super(newWriteOptions());
20
21 }
22
23 /**
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
27 * slower.
28 *
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.
33 *
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()".
38 *
39 * Default: false
40 *
41 * @param flag a boolean flag to indicate whether a write
42 * should be synchronized.
43 * @return the instance of the current WriteOptions.
44 */
45 public WriteOptions setSync(final boolean flag) {
46 setSync(nativeHandle_, flag);
47 return this;
48 }
49
50 /**
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
54 * slower.
55 *
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.
60 *
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()".
65 *
66 * @return boolean value indicating if sync is active.
67 */
68 public boolean sync() {
69 return sync(nativeHandle_);
70 }
71
72 /**
73 * If true, writes will not first go to the write ahead log,
74 * and the write may got lost after a crash.
75 *
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.
79 */
80 public WriteOptions setDisableWAL(final boolean flag) {
81 setDisableWAL(nativeHandle_, flag);
82 return this;
83 }
84
85 /**
86 * If true, writes will not first go to the write ahead log,
87 * and the write may got lost after a crash.
88 *
89 * @return boolean value indicating if WAL is disabled.
90 */
91 public boolean disableWAL() {
92 return disableWAL(nativeHandle_);
93 }
94
95 /**
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.
99 *
100 * Default: false
101 *
102 * @param ignoreMissingColumnFamilies true to ignore writes to column families
103 * which don't exist
104 * @return the instance of the current WriteOptions.
105 */
106 public WriteOptions setIgnoreMissingColumnFamilies(
107 final boolean ignoreMissingColumnFamilies) {
108 setIgnoreMissingColumnFamilies(nativeHandle_, ignoreMissingColumnFamilies);
109 return this;
110 }
111
112 /**
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.
116 *
117 * Default: false
118 *
119 * @return true if writes to column families which don't exist are ignored
120 */
121 public boolean ignoreMissingColumnFamilies() {
122 return ignoreMissingColumnFamilies(nativeHandle_);
123 }
124
125 /**
126 * If true and we need to wait or sleep for the write request, fails
127 * immediately with {@link Status.Code#Incomplete}.
128 *
129 * @param noSlowdown true to fail write requests if we need to wait or sleep
130 * @return the instance of the current WriteOptions.
131 */
132 public WriteOptions setNoSlowdown(final boolean noSlowdown) {
133 setNoSlowdown(nativeHandle_, noSlowdown);
134 return this;
135 }
136
137 /**
138 * If true and we need to wait or sleep for the write request, fails
139 * immediately with {@link Status.Code#Incomplete}.
140 *
141 * @return true when write requests are failed if we need to wait or sleep
142 */
143 public boolean noSlowdown() {
144 return noSlowdown(nativeHandle_);
145 }
146
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);
159 }