]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/rocksdb/java/src/main/java/org/rocksdb/ComparatorOptions.java
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / ComparatorOptions.java
index 3a05befa4483c2d16b31ac760b0bc66ba81bffd5..8c31628583c3177c434e105ae2b34910ba58a3d2 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
+//  This source code is licensed under both the GPLv2 (found in the
+//  COPYING file in the root directory) and Apache 2.0 License
+//  (found in the LICENSE.Apache file in the root directory).
 package org.rocksdb;
 
 /**
@@ -14,38 +18,116 @@ public class ComparatorOptions extends RocksObject {
   }
 
   /**
-   * Use adaptive mutex, which spins in the user space before resorting
-   * to kernel. This could reduce context switch when the mutex is not
-   * heavily contended. However, if the mutex is hot, we could end up
-   * wasting spin time.
-   * Default: false
+   * Get the synchronisation type used to guard the reused buffers.
+   * Only used if {@link #maxReusedBufferSize()} > 0
+   * Default: {@link ReusedSynchronisationType#ADAPTIVE_MUTEX}
    *
-   * @return true if adaptive mutex is used.
+   * @return the synchronisation type
    */
-  public boolean useAdaptiveMutex() {
+  public ReusedSynchronisationType reusedSynchronisationType() {
     assert(isOwningHandle());
-    return useAdaptiveMutex(nativeHandle_);
+    return ReusedSynchronisationType.getReusedSynchronisationType(
+        reusedSynchronisationType(nativeHandle_));
   }
 
   /**
-   * Use adaptive mutex, which spins in the user space before resorting
-   * to kernel. This could reduce context switch when the mutex is not
-   * heavily contended. However, if the mutex is hot, we could end up
-   * wasting spin time.
-   * Default: false
+   * Set the synchronisation type used to guard the reused buffers.
+   * Only used if {@link #maxReusedBufferSize()} > 0
+   * Default: {@link ReusedSynchronisationType#ADAPTIVE_MUTEX}
+   *
+   * @param reusedSynchronisationType the synchronisation type
    *
-   * @param useAdaptiveMutex true if adaptive mutex is used.
    * @return the reference to the current comparator options.
    */
-  public ComparatorOptions setUseAdaptiveMutex(final boolean useAdaptiveMutex) {
+  public ComparatorOptions setReusedSynchronisationType(
+      final ReusedSynchronisationType reusedSynchronisationType) {
     assert (isOwningHandle());
-    setUseAdaptiveMutex(nativeHandle_, useAdaptiveMutex);
+    setReusedSynchronisationType(nativeHandle_,
+        reusedSynchronisationType.getValue());
+    return this;
+  }
+
+  /**
+   * Indicates if a direct byte buffer (i.e. outside of the normal
+   * garbage-collected heap) is used, as opposed to a non-direct byte buffer
+   * which is a wrapper around an on-heap byte[].
+   *
+   * Default: true
+   *
+   * @return true if a direct byte buffer will be used, false otherwise
+   */
+  public boolean useDirectBuffer() {
+    assert(isOwningHandle());
+    return useDirectBuffer(nativeHandle_);
+  }
+
+  /**
+   * Controls whether a direct byte buffer (i.e. outside of the normal
+   * garbage-collected heap) is used, as opposed to a non-direct byte buffer
+   * which is a wrapper around an on-heap byte[].
+   *
+   * Default: true
+   *
+   * @param useDirectBuffer true if a direct byte buffer should be used,
+   *     false otherwise
+   * @return the reference to the current comparator options.
+   */
+  public ComparatorOptions setUseDirectBuffer(final boolean useDirectBuffer) {
+    assert(isOwningHandle());
+    setUseDirectBuffer(nativeHandle_, useDirectBuffer);
+    return this;
+  }
+
+  /**
+   * Maximum size of a buffer (in bytes) that will be reused.
+   * Comparators will use 5 of these buffers,
+   * so the retained memory size will be 5 * max_reused_buffer_size.
+   * When a buffer is needed for transferring data to a callback,
+   * if it requires less than {@code maxReuseBufferSize}, then an
+   * existing buffer will be reused, else a new buffer will be
+   * allocated just for that callback.
+   *
+   * Default: 64 bytes
+   *
+   * @return the maximum size of a buffer which is reused,
+   *     or 0 if reuse is disabled
+   */
+  public int maxReusedBufferSize() {
+    assert(isOwningHandle());
+    return maxReusedBufferSize(nativeHandle_);
+  }
+
+  /**
+   * Sets the maximum size of a buffer (in bytes) that will be reused.
+   * Comparators will use 5 of these buffers,
+   * so the retained memory size will be 5 * max_reused_buffer_size.
+   * When a buffer is needed for transferring data to a callback,
+   * if it requires less than {@code maxReuseBufferSize}, then an
+   * existing buffer will be reused, else a new buffer will be
+   * allocated just for that callback.
+   *
+   * Default: 64 bytes
+   *
+   * @param maxReusedBufferSize the maximum size for a buffer to reuse, or 0 to
+   *     disable reuse
+   *
+   * @return the maximum size of a buffer which is reused
+   */
+  public ComparatorOptions setMaxReusedBufferSize(final int maxReusedBufferSize) {
+    assert(isOwningHandle());
+    setMaxReusedBufferSize(nativeHandle_, maxReusedBufferSize);
     return this;
   }
 
   private native static long newComparatorOptions();
-  private native boolean useAdaptiveMutex(final long handle);
-  private native void setUseAdaptiveMutex(final long handle,
-      final boolean useAdaptiveMutex);
+  private native byte reusedSynchronisationType(final long handle);
+  private native void setReusedSynchronisationType(final long handle,
+      final byte reusedSynchronisationType);
+  private native boolean useDirectBuffer(final long handle);
+  private native void setUseDirectBuffer(final long handle,
+      final boolean useDirectBuffer);
+  private native int maxReusedBufferSize(final long handle);
+  private native void setMaxReusedBufferSize(final long handle,
+      final int maxReuseBufferSize);
   @Override protected final native void disposeInternal(final long handle);
 }