]>
git.proxmox.com Git - ceph.git/blob - 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).
8 import java
.nio
.ByteBuffer
;
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.
15 public class SstFileWriter
extends RocksObject
{
17 RocksDB
.loadLibrary();
21 * SstFileWriter Constructor.
23 * @param envOptions {@link org.rocksdb.EnvOptions} instance.
24 * @param options {@link org.rocksdb.Options} instance.
26 public SstFileWriter(final EnvOptions envOptions
, final Options options
) {
27 super(newSstFileWriter(
28 envOptions
.nativeHandle_
, options
.nativeHandle_
));
32 * Prepare SstFileWriter to write to a file.
34 * @param filePath the location of file
36 * @throws RocksDBException thrown if error happens in underlying
39 public void open(final String filePath
) throws RocksDBException
{
40 open(nativeHandle_
, filePath
);
44 * Add a Put key with value to currently opened file.
46 * @param key the specified key to be inserted.
47 * @param value the value associated with the specified key.
49 * @throws RocksDBException thrown if error happens in underlying
52 public void put(final Slice key
, final Slice value
) throws RocksDBException
{
53 put(nativeHandle_
, key
.getNativeHandle(), value
.getNativeHandle());
57 * Add a Put key with value to currently opened file.
59 * @param key the specified key to be inserted.
60 * @param value the value associated with the specified key.
62 * @throws RocksDBException thrown if error happens in underlying
65 public void put(final DirectSlice key
, final DirectSlice value
)
66 throws RocksDBException
{
67 put(nativeHandle_
, key
.getNativeHandle(), value
.getNativeHandle());
71 * Add a Put key with value to currently opened file.
73 * @param key the specified key to be inserted.
74 * @param value the value associated with the specified key.
76 * @throws RocksDBException thrown if error happens in underlying
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(),
83 key
.position(key
.limit());
84 value
.position(value
.limit());
88 * Add a Put key with value to currently opened file.
90 * @param key the specified key to be inserted.
91 * @param value the value associated with the specified key.
93 * @throws RocksDBException thrown if error happens in underlying
96 public void put(final byte[] key
, final byte[] value
) throws RocksDBException
{
97 put(nativeHandle_
, key
, value
);
101 * Add a Merge key with value to currently opened file.
103 * @param key the specified key to be merged.
104 * @param value the value to be merged with the current value for
107 * @throws RocksDBException thrown if error happens in underlying
110 public void merge(final Slice key
, final Slice value
)
111 throws RocksDBException
{
112 merge(nativeHandle_
, key
.getNativeHandle(), value
.getNativeHandle());
116 * Add a Merge key with value to currently opened file.
118 * @param key the specified key to be merged.
119 * @param value the value to be merged with the current value for
122 * @throws RocksDBException thrown if error happens in underlying
125 public void merge(final byte[] key
, final byte[] value
)
126 throws RocksDBException
{
127 merge(nativeHandle_
, key
, value
);
131 * Add a Merge key with value to currently opened file.
133 * @param key the specified key to be merged.
134 * @param value the value to be merged with the current value for
137 * @throws RocksDBException thrown if error happens in underlying
140 public void merge(final DirectSlice key
, final DirectSlice value
)
141 throws RocksDBException
{
142 merge(nativeHandle_
, key
.getNativeHandle(), value
.getNativeHandle());
146 * Add a deletion key to currently opened file.
148 * @param key the specified key to be deleted.
150 * @throws RocksDBException thrown if error happens in underlying
153 public void delete(final Slice key
) throws RocksDBException
{
154 delete(nativeHandle_
, key
.getNativeHandle());
158 * Add a deletion key to currently opened file.
160 * @param key the specified key to be deleted.
162 * @throws RocksDBException thrown if error happens in underlying
165 public void delete(final DirectSlice key
) throws RocksDBException
{
166 delete(nativeHandle_
, key
.getNativeHandle());
170 * Add a deletion key to currently opened file.
172 * @param key the specified key to be deleted.
174 * @throws RocksDBException thrown if error happens in underlying
177 public void delete(final byte[] key
) throws RocksDBException
{
178 delete(nativeHandle_
, key
);
182 * Finish the process and close the sst file.
184 * @throws RocksDBException thrown if error happens in underlying
187 public void finish() throws RocksDBException
{
188 finish(nativeHandle_
);
192 * Return the current file size.
194 * @return the current file size.
195 * @throws RocksDBException thrown if error happens in underlying
198 public long fileSize() throws RocksDBException
{
199 return fileSize(nativeHandle_
);
202 private native static long newSstFileWriter(
203 final long envOptionsHandle
, final long optionsHandle
,
204 final long userComparatorHandle
, final byte comparatorType
);
206 private native static long newSstFileWriter(final long envOptionsHandle
,
207 final long optionsHandle
);
209 private native void open(final long handle
, final String filePath
)
210 throws RocksDBException
;
212 private native void put(final long handle
, final long keyHandle
,
213 final long valueHandle
) throws RocksDBException
;
215 private native void put(final long handle
, final byte[] key
,
216 final byte[] value
) throws RocksDBException
;
218 private native void putDirect(long handle
, ByteBuffer key
, int keyOffset
, int keyLength
,
219 ByteBuffer value
, int valueOffset
, int valueLength
) throws RocksDBException
;
221 private native long fileSize(long handle
) throws RocksDBException
;
223 private native void merge(final long handle
, final long keyHandle
,
224 final long valueHandle
) throws RocksDBException
;
226 private native void merge(final long handle
, final byte[] key
,
227 final byte[] value
) throws RocksDBException
;
229 private native void delete(final long handle
, final long keyHandle
)
230 throws RocksDBException
;
232 private native void delete(final long handle
, final byte[] key
)
233 throws RocksDBException
;
235 private native void finish(final long handle
) throws RocksDBException
;
237 @Override protected final native void disposeInternal(final long handle
);