1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
8 import java
.nio
.ByteBuffer
;
11 * <p>Defines the interface for a Write Batch which
12 * holds a collection of updates to apply atomically to a DB.</p>
14 public interface WriteBatchInterface
{
17 * Returns the number of updates in the batch.
19 * @return number of items in WriteBatch
24 * <p>Store the mapping "key->value" in the database.</p>
26 * @param key the specified key to be inserted.
27 * @param value the value associated with the specified key.
28 * @throws RocksDBException thrown if error happens in underlying native library.
30 void put(byte[] key
, byte[] value
) throws RocksDBException
;
33 * <p>Store the mapping "key->value" within given column
36 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
38 * @param key the specified key to be inserted.
39 * @param value the value associated with the specified key.
40 * @throws RocksDBException thrown if error happens in underlying native library.
42 void put(ColumnFamilyHandle columnFamilyHandle
,
43 byte[] key
, byte[] value
) throws RocksDBException
;
46 * <p>Store the mapping "key->value" within given column
49 * @param key the specified key to be inserted. It is using position and limit.
50 * Supports direct buffer only.
51 * @param value the value associated with the specified key. It is using position and limit.
52 * Supports direct buffer only.
53 * @throws RocksDBException
55 void put(ByteBuffer key
, ByteBuffer value
) throws RocksDBException
;
58 * <p>Store the mapping "key->value" within given column
61 * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
63 * @param key the specified key to be inserted. It is using position and limit.
64 * Supports direct buffer only.
65 * @param value the value associated with the specified key. It is using position and limit.
66 * Supports direct buffer only.
67 * @throws RocksDBException
69 void put(ColumnFamilyHandle columnFamilyHandle
, ByteBuffer key
, ByteBuffer value
)
70 throws RocksDBException
;
73 * <p>Merge "value" with the existing value of "key" in the database.
74 * "key->merge(existing, value)"</p>
76 * @param key the specified key to be merged.
77 * @param value the value to be merged with the current value for
79 * @throws RocksDBException thrown if error happens in underlying native library.
81 void merge(byte[] key
, byte[] value
) throws RocksDBException
;
84 * <p>Merge "value" with the existing value of "key" in given column family.
85 * "key->merge(existing, value)"</p>
87 * @param columnFamilyHandle {@link ColumnFamilyHandle} instance
88 * @param key the specified key to be merged.
89 * @param value the value to be merged with the current value for
91 * @throws RocksDBException thrown if error happens in underlying native library.
93 void merge(ColumnFamilyHandle columnFamilyHandle
,
94 byte[] key
, byte[] value
) throws RocksDBException
;
97 * <p>If the database contains a mapping for "key", erase it. Else do nothing.</p>
99 * @param key Key to delete within database
101 * @deprecated Use {@link #delete(byte[])}
102 * @throws RocksDBException thrown if error happens in underlying native library.
105 void remove(byte[] key
) throws RocksDBException
;
108 * <p>If column family contains a mapping for "key", erase it. Else do nothing.</p>
110 * @param columnFamilyHandle {@link ColumnFamilyHandle} instance
111 * @param key Key to delete within database
113 * @deprecated Use {@link #delete(ColumnFamilyHandle, byte[])}
114 * @throws RocksDBException thrown if error happens in underlying native library.
117 void remove(ColumnFamilyHandle columnFamilyHandle
, byte[] key
)
118 throws RocksDBException
;
121 * <p>If the database contains a mapping for "key", erase it. Else do nothing.</p>
123 * @param key Key to delete within database
124 * @throws RocksDBException thrown if error happens in underlying native library.
126 void delete(byte[] key
) throws RocksDBException
;
129 * <p>If column family contains a mapping for "key", erase it. Else do nothing.</p>
131 * @param columnFamilyHandle {@link ColumnFamilyHandle} instance
132 * @param key Key to delete within database
133 * @throws RocksDBException thrown if error happens in underlying native library.
135 void delete(ColumnFamilyHandle columnFamilyHandle
, byte[] key
)
136 throws RocksDBException
;
139 * Remove the database entry for {@code key}. Requires that the key exists
140 * and was not overwritten. It is not an error if the key did not exist
143 * If a key is overwritten (by calling {@link #put(byte[], byte[])} multiple
144 * times), then the result of calling SingleDelete() on this key is undefined.
145 * SingleDelete() only behaves correctly if there has been only one Put()
146 * for this key since the previous call to SingleDelete() for this key.
148 * This feature is currently an experimental performance optimization
149 * for a very specific workload. It is up to the caller to ensure that
150 * SingleDelete is only used for a key that is not deleted using Delete() or
151 * written using Merge(). Mixing SingleDelete operations with Deletes and
152 * Merges can result in undefined behavior.
154 * @param key Key to delete within database
156 * @throws RocksDBException thrown if error happens in underlying
159 @Experimental("Performance optimization for a very specific workload")
160 void singleDelete(final byte[] key
) throws RocksDBException
;
163 * Remove the database entry for {@code key}. Requires that the key exists
164 * and was not overwritten. It is not an error if the key did not exist
167 * If a key is overwritten (by calling {@link #put(byte[], byte[])} multiple
168 * times), then the result of calling SingleDelete() on this key is undefined.
169 * SingleDelete() only behaves correctly if there has been only one Put()
170 * for this key since the previous call to SingleDelete() for this key.
172 * This feature is currently an experimental performance optimization
173 * for a very specific workload. It is up to the caller to ensure that
174 * SingleDelete is only used for a key that is not deleted using Delete() or
175 * written using Merge(). Mixing SingleDelete operations with Deletes and
176 * Merges can result in undefined behavior.
178 * @param columnFamilyHandle The column family to delete the key from
179 * @param key Key to delete within database
181 * @throws RocksDBException thrown if error happens in underlying
184 @Experimental("Performance optimization for a very specific workload")
185 void singleDelete(final ColumnFamilyHandle columnFamilyHandle
,
186 final byte[] key
) throws RocksDBException
;
189 * <p>If column family contains a mapping for "key", erase it. Else do nothing.</p>
191 * @param key Key to delete within database. It is using position and limit.
192 * Supports direct buffer only.
193 * @throws RocksDBException
195 void remove(ByteBuffer key
) throws RocksDBException
;
198 * <p>If column family contains a mapping for "key", erase it. Else do nothing.</p>
200 * @param columnFamilyHandle {@link ColumnFamilyHandle} instance
201 * @param key Key to delete within database. It is using position and limit.
202 * Supports direct buffer only.
203 * @throws RocksDBException
205 void remove(ColumnFamilyHandle columnFamilyHandle
, ByteBuffer key
) throws RocksDBException
;
208 * Removes the database entries in the range ["beginKey", "endKey"), i.e.,
209 * including "beginKey" and excluding "endKey". a non-OK status on error. It
210 * is not an error if no keys exist in the range ["beginKey", "endKey").
212 * Delete the database entry (if any) for "key". Returns OK on success, and a
213 * non-OK status on error. It is not an error if "key" did not exist in the
217 * First key to delete within database (included)
219 * Last key to delete within database (excluded)
220 * @throws RocksDBException thrown if error happens in underlying native library.
222 void deleteRange(byte[] beginKey
, byte[] endKey
) throws RocksDBException
;
225 * Removes the database entries in the range ["beginKey", "endKey"), i.e.,
226 * including "beginKey" and excluding "endKey". a non-OK status on error. It
227 * is not an error if no keys exist in the range ["beginKey", "endKey").
229 * Delete the database entry (if any) for "key". Returns OK on success, and a
230 * non-OK status on error. It is not an error if "key" did not exist in the
233 * @param columnFamilyHandle {@link ColumnFamilyHandle} instance
235 * First key to delete within database (included)
237 * Last key to delete within database (excluded)
238 * @throws RocksDBException thrown if error happens in underlying native library.
240 void deleteRange(ColumnFamilyHandle columnFamilyHandle
, byte[] beginKey
,
241 byte[] endKey
) throws RocksDBException
;
244 * Append a blob of arbitrary size to the records in this batch. The blob will
245 * be stored in the transaction log but not in any other file. In particular,
246 * it will not be persisted to the SST files. When iterating over this
247 * WriteBatch, WriteBatch::Handler::LogData will be called with the contents
248 * of the blob as it is encountered. Blobs, puts, deletes, and merges will be
249 * encountered in the same order in thich they were inserted. The blob will
250 * NOT consume sequence number(s) and will NOT increase the count of the batch
252 * Example application: add timestamps to the transaction log for use in
255 * @param blob binary object to be inserted
256 * @throws RocksDBException thrown if error happens in underlying native library.
258 void putLogData(byte[] blob
) throws RocksDBException
;
261 * Clear all updates buffered in this batch
266 * Records the state of the batch for future calls to RollbackToSavePoint().
267 * May be called multiple times to set multiple save points.
272 * Remove all entries in this batch (Put, Merge, Delete, PutLogData) since
273 * the most recent call to SetSavePoint() and removes the most recent save
276 * @throws RocksDBException if there is no previous call to SetSavePoint()
278 void rollbackToSavePoint() throws RocksDBException
;
281 * Pop the most recent save point.
283 * That is to say that it removes the last save point,
284 * which was set by {@link #setSavePoint()}.
286 * @throws RocksDBException If there is no previous call to
287 * {@link #setSavePoint()}, an exception with
288 * {@link Status.Code#NotFound} will be thrown.
290 void popSavePoint() throws RocksDBException
;
293 * Set the maximum size of the write batch.
295 * @param maxBytes the maximum size in bytes.
297 void setMaxBytes(long maxBytes
);
300 * Get the underlying Write Batch.
302 * @return the underlying WriteBatch.
304 WriteBatch
getWriteBatch();