]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/main/java/org/rocksdb/SstFileWriter.java
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / SstFileWriter.java
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5
6 package org.rocksdb;
7
8 import java.nio.ByteBuffer;
9
10 /**
11 * SstFileWriter is used to create sst files that can be added to the
12 * database later. All keys in files generated by SstFileWriter will have
13 * sequence number = 0.
14 */
15 public class SstFileWriter extends RocksObject {
16 static {
17 RocksDB.loadLibrary();
18 }
19
20 /**
21 * SstFileWriter Constructor.
22 *
23 * @param envOptions {@link org.rocksdb.EnvOptions} instance.
24 * @param options {@link org.rocksdb.Options} instance.
25 */
26 public SstFileWriter(final EnvOptions envOptions, final Options options) {
27 super(newSstFileWriter(
28 envOptions.nativeHandle_, options.nativeHandle_));
29 }
30
31 /**
32 * Prepare SstFileWriter to write to a file.
33 *
34 * @param filePath the location of file
35 *
36 * @throws RocksDBException thrown if error happens in underlying
37 * native library.
38 */
39 public void open(final String filePath) throws RocksDBException {
40 open(nativeHandle_, filePath);
41 }
42
43 /**
44 * Add a Put key with value to currently opened file.
45 *
46 * @param key the specified key to be inserted.
47 * @param value the value associated with the specified key.
48 *
49 * @throws RocksDBException thrown if error happens in underlying
50 * native library.
51 */
52 public void put(final Slice key, final Slice value) throws RocksDBException {
53 put(nativeHandle_, key.getNativeHandle(), value.getNativeHandle());
54 }
55
56 /**
57 * Add a Put key with value to currently opened file.
58 *
59 * @param key the specified key to be inserted.
60 * @param value the value associated with the specified key.
61 *
62 * @throws RocksDBException thrown if error happens in underlying
63 * native library.
64 */
65 public void put(final DirectSlice key, final DirectSlice value)
66 throws RocksDBException {
67 put(nativeHandle_, key.getNativeHandle(), value.getNativeHandle());
68 }
69
70 /**
71 * Add a Put key with value to currently opened file.
72 *
73 * @param key the specified key to be inserted.
74 * @param value the value associated with the specified key.
75 *
76 * @throws RocksDBException thrown if error happens in underlying
77 * native library.
78 */
79 public void put(final ByteBuffer key, final ByteBuffer value) throws RocksDBException {
80 assert key.isDirect() && value.isDirect();
81 putDirect(nativeHandle_, key, key.position(), key.remaining(), value, value.position(),
82 value.remaining());
83 key.position(key.limit());
84 value.position(value.limit());
85 }
86
87 /**
88 * Add a Put key with value to currently opened file.
89 *
90 * @param key the specified key to be inserted.
91 * @param value the value associated with the specified key.
92 *
93 * @throws RocksDBException thrown if error happens in underlying
94 * native library.
95 */
96 public void put(final byte[] key, final byte[] value) throws RocksDBException {
97 put(nativeHandle_, key, value);
98 }
99
100 /**
101 * Add a Merge key with value to currently opened file.
102 *
103 * @param key the specified key to be merged.
104 * @param value the value to be merged with the current value for
105 * the specified key.
106 *
107 * @throws RocksDBException thrown if error happens in underlying
108 * native library.
109 */
110 public void merge(final Slice key, final Slice value)
111 throws RocksDBException {
112 merge(nativeHandle_, key.getNativeHandle(), value.getNativeHandle());
113 }
114
115 /**
116 * Add a Merge key with value to currently opened file.
117 *
118 * @param key the specified key to be merged.
119 * @param value the value to be merged with the current value for
120 * the specified key.
121 *
122 * @throws RocksDBException thrown if error happens in underlying
123 * native library.
124 */
125 public void merge(final byte[] key, final byte[] value)
126 throws RocksDBException {
127 merge(nativeHandle_, key, value);
128 }
129
130 /**
131 * Add a Merge key with value to currently opened file.
132 *
133 * @param key the specified key to be merged.
134 * @param value the value to be merged with the current value for
135 * the specified key.
136 *
137 * @throws RocksDBException thrown if error happens in underlying
138 * native library.
139 */
140 public void merge(final DirectSlice key, final DirectSlice value)
141 throws RocksDBException {
142 merge(nativeHandle_, key.getNativeHandle(), value.getNativeHandle());
143 }
144
145 /**
146 * Add a deletion key to currently opened file.
147 *
148 * @param key the specified key to be deleted.
149 *
150 * @throws RocksDBException thrown if error happens in underlying
151 * native library.
152 */
153 public void delete(final Slice key) throws RocksDBException {
154 delete(nativeHandle_, key.getNativeHandle());
155 }
156
157 /**
158 * Add a deletion key to currently opened file.
159 *
160 * @param key the specified key to be deleted.
161 *
162 * @throws RocksDBException thrown if error happens in underlying
163 * native library.
164 */
165 public void delete(final DirectSlice key) throws RocksDBException {
166 delete(nativeHandle_, key.getNativeHandle());
167 }
168
169 /**
170 * Add a deletion key to currently opened file.
171 *
172 * @param key the specified key to be deleted.
173 *
174 * @throws RocksDBException thrown if error happens in underlying
175 * native library.
176 */
177 public void delete(final byte[] key) throws RocksDBException {
178 delete(nativeHandle_, key);
179 }
180
181 /**
182 * Finish the process and close the sst file.
183 *
184 * @throws RocksDBException thrown if error happens in underlying
185 * native library.
186 */
187 public void finish() throws RocksDBException {
188 finish(nativeHandle_);
189 }
190
191 /**
192 * Return the current file size.
193 *
194 * @return the current file size.
195 * @throws RocksDBException thrown if error happens in underlying
196 * native library.
197 */
198 public long fileSize() throws RocksDBException {
199 return fileSize(nativeHandle_);
200 }
201
202 private native static long newSstFileWriter(
203 final long envOptionsHandle, final long optionsHandle,
204 final long userComparatorHandle, final byte comparatorType);
205
206 private native static long newSstFileWriter(final long envOptionsHandle,
207 final long optionsHandle);
208
209 private native void open(final long handle, final String filePath)
210 throws RocksDBException;
211
212 private native void put(final long handle, final long keyHandle,
213 final long valueHandle) throws RocksDBException;
214
215 private native void put(final long handle, final byte[] key,
216 final byte[] value) throws RocksDBException;
217
218 private native void putDirect(long handle, ByteBuffer key, int keyOffset, int keyLength,
219 ByteBuffer value, int valueOffset, int valueLength) throws RocksDBException;
220
221 private native long fileSize(long handle) throws RocksDBException;
222
223 private native void merge(final long handle, final long keyHandle,
224 final long valueHandle) throws RocksDBException;
225
226 private native void merge(final long handle, final byte[] key,
227 final byte[] value) throws RocksDBException;
228
229 private native void delete(final long handle, final long keyHandle)
230 throws RocksDBException;
231
232 private native void delete(final long handle, final byte[] key)
233 throws RocksDBException;
234
235 private native void finish(final long handle) throws RocksDBException;
236
237 @Override protected final native void disposeInternal(final long handle);
238 }