]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/rocksdb/java/src/main/java/org/rocksdb/SstFileWriter.java
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / SstFileWriter.java
index 447e41ea9db64581a5722c2a6f56a66831d94b0d..6d9c559bf8f7a2fb119634e582424a74613e9ae6 100644 (file)
@@ -5,6 +5,8 @@
 
 package org.rocksdb;
 
+import java.nio.ByteBuffer;
+
 /**
  * SstFileWriter is used to create sst files that can be added to the
  * database later. All keys in files generated by SstFileWriter will have
@@ -28,7 +30,7 @@ public class SstFileWriter extends RocksObject {
    */
   @Deprecated
   public SstFileWriter(final EnvOptions envOptions, final Options options,
-      final AbstractComparator<? extends AbstractSlice<?>> comparator) {
+      final AbstractComparator comparator) {
     super(newSstFileWriter(
         envOptions.nativeHandle_, options.nativeHandle_, comparator.nativeHandle_,
         comparator.getComparatorType().getValue()));
@@ -118,6 +120,23 @@ public class SstFileWriter extends RocksObject {
     put(nativeHandle_, key.getNativeHandle(), value.getNativeHandle());
   }
 
+  /**
+   * Add a Put key with value to currently opened file.
+   *
+   * @param key the specified key to be inserted.
+   * @param value the value associated with the specified key.
+   *
+   * @throws RocksDBException thrown if error happens in underlying
+   *    native library.
+   */
+  public void put(final ByteBuffer key, final ByteBuffer value) throws RocksDBException {
+    assert key.isDirect() && value.isDirect();
+    putDirect(nativeHandle_, key, key.position(), key.remaining(), value, value.position(),
+        value.remaining());
+    key.position(key.limit());
+    value.position(value.limit());
+  }
+
  /**
    * Add a Put key with value to currently opened file.
    *
@@ -127,10 +146,9 @@ public class SstFileWriter extends RocksObject {
    * @throws RocksDBException thrown if error happens in underlying
    *    native library.
    */
-public void put(final byte[] key, final byte[] value)
-    throws RocksDBException {
-  put(nativeHandle_, key, value);
-}
+  public void put(final byte[] key, final byte[] value) throws RocksDBException {
+    put(nativeHandle_, key, value);
+  }
 
   /**
    * Add a Merge key with value to currently opened file.
@@ -223,6 +241,16 @@ public void put(final byte[] key, final byte[] value)
     finish(nativeHandle_);
   }
 
+  /**
+   * Return the current file size.
+   *
+   * @throws RocksDBException thrown if error happens in underlying
+   *    native library.
+   */
+  public long fileSize() throws RocksDBException {
+    return fileSize(nativeHandle_);
+  }
+
   private native static long newSstFileWriter(
       final long envOptionsHandle, final long optionsHandle,
       final long userComparatorHandle, final byte comparatorType);
@@ -239,6 +267,11 @@ public void put(final byte[] key, final byte[] value)
   private native void put(final long handle, final byte[] key,
       final byte[] value) throws RocksDBException;
 
+  private native void putDirect(long handle, ByteBuffer key, int keyOffset, int keyLength,
+      ByteBuffer value, int valueOffset, int valueLength) throws RocksDBException;
+
+  private native long fileSize(long handle) throws RocksDBException;
+
   private native void merge(final long handle, final long keyHandle,
       final long valueHandle) throws RocksDBException;