]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/rocksdb/java/src/main/java/org/rocksdb/Transaction.java
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / Transaction.java
index f176701fa01e8181c4ceaa86b909c328322ef28e..b2cc8a9326a7e06d70a948d0fe55eed58f2ec3fb 100644 (file)
@@ -5,6 +5,8 @@
 
 package org.rocksdb;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -45,7 +47,7 @@ public class Transaction extends RocksObject {
 
   /**
    * If a transaction has a snapshot set, the transaction will ensure that
-   * any keys successfully written(or fetched via {@link #getForUpdate}) have
+   * any keys successfully written (or fetched via {@link #getForUpdate}) have
    * not been modified outside of this transaction since the time the snapshot
    * was set.
    *
@@ -176,7 +178,7 @@ public class Transaction extends RocksObject {
   /**
    * Prepare the current transaction for 2PC
    */
-  void prepare() throws RocksDBException {
+  public void prepare() throws RocksDBException {
     //TODO(AR) consider a Java'ish version of this function, which returns an AutoCloseable (commit)
     assert(isOwningHandle());
     prepare(nativeHandle_);
@@ -310,7 +312,7 @@ public class Transaction extends RocksObject {
 
   /**
    * This function is similar to
-   * {@link RocksDB#multiGet(ReadOptions, List, List)} except it will
+   * {@link RocksDB#multiGetAsList} except it will
    * also read pending changes in this transaction.
    * Currently, this function will return Status::MergeInProgress if the most
    * recent write to the queried key in this batch is a Merge.
@@ -336,9 +338,10 @@ public class Transaction extends RocksObject {
    * @throws IllegalArgumentException thrown if the size of passed keys is not
    *    equal to the amount of passed column family handles.
    */
+  @Deprecated
   public byte[][] multiGet(final ReadOptions readOptions,
-      final List<ColumnFamilyHandle> columnFamilyHandles,
-      final byte[][] keys) throws RocksDBException {
+      final List<ColumnFamilyHandle> columnFamilyHandles, final byte[][] keys)
+      throws RocksDBException {
     assert(isOwningHandle());
     // Check if key size equals cfList size. If not a exception must be
     // thrown. If not a Segmentation fault happens.
@@ -360,7 +363,57 @@ public class Transaction extends RocksObject {
 
   /**
    * This function is similar to
-   * {@link RocksDB#multiGet(ReadOptions, List)} except it will
+   * {@link RocksDB#multiGetAsList(ReadOptions, List, List)} except it will
+   * also read pending changes in this transaction.
+   * Currently, this function will return Status::MergeInProgress if the most
+   * recent write to the queried key in this batch is a Merge.
+   *
+   * If {@link ReadOptions#snapshot()} is not set, the current version of the
+   * key will be read. Calling {@link #setSnapshot()} does not affect the
+   * version of the data returned.
+   *
+   * Note that setting {@link ReadOptions#setSnapshot(Snapshot)} will affect
+   * what is read from the DB but will NOT change which keys are read from this
+   * transaction (the keys in this transaction do not yet belong to any snapshot
+   * and will be fetched regardless).
+   *
+   * @param readOptions Read options.
+   * @param columnFamilyHandles {@link java.util.List} containing
+   *     {@link org.rocksdb.ColumnFamilyHandle} instances.
+   * @param keys of keys for which values need to be retrieved.
+   *
+   * @return Array of values, one for each key
+   *
+   * @throws RocksDBException thrown if error happens in underlying
+   *    native library.
+   * @throws IllegalArgumentException thrown if the size of passed keys is not
+   *    equal to the amount of passed column family handles.
+   */
+
+  public List<byte[]> multiGetAsList(final ReadOptions readOptions,
+      final List<ColumnFamilyHandle> columnFamilyHandles, final List<byte[]> keys)
+      throws RocksDBException {
+    assert (isOwningHandle());
+    // Check if key size equals cfList size. If not a exception must be
+    // thrown. If not a Segmentation fault happens.
+    if (keys.size() != columnFamilyHandles.size()) {
+      throw new IllegalArgumentException("For each key there must be a ColumnFamilyHandle.");
+    }
+    if (keys.size() == 0) {
+      return new ArrayList<>(0);
+    }
+    final byte[][] keysArray = keys.toArray(new byte[keys.size()][]);
+    final long[] cfHandles = new long[columnFamilyHandles.size()];
+    for (int i = 0; i < columnFamilyHandles.size(); i++) {
+      cfHandles[i] = columnFamilyHandles.get(i).nativeHandle_;
+    }
+
+    return Arrays.asList(multiGet(nativeHandle_, readOptions.nativeHandle_, keysArray, cfHandles));
+  }
+
+  /**
+   * This function is similar to
+   * {@link RocksDB#multiGetAsList} except it will
    * also read pending changes in this transaction.
    * Currently, this function will return Status::MergeInProgress if the most
    * recent write to the queried key in this batch is a Merge.
@@ -383,8 +436,9 @@ public class Transaction extends RocksObject {
    * @throws RocksDBException thrown if error happens in underlying
    *    native library.
    */
-  public byte[][] multiGet(final ReadOptions readOptions,
-      final byte[][] keys) throws RocksDBException {
+  @Deprecated
+  public byte[][] multiGet(final ReadOptions readOptions, final byte[][] keys)
+      throws RocksDBException {
     assert(isOwningHandle());
     if(keys.length == 0) {
       return new byte[0][0];
@@ -394,6 +448,41 @@ public class Transaction extends RocksObject {
         keys);
   }
 
+  /**
+   * This function is similar to
+   * {@link RocksDB#multiGetAsList} except it will
+   * also read pending changes in this transaction.
+   * Currently, this function will return Status::MergeInProgress if the most
+   * recent write to the queried key in this batch is a Merge.
+   *
+   * If {@link ReadOptions#snapshot()} is not set, the current version of the
+   * key will be read. Calling {@link #setSnapshot()} does not affect the
+   * version of the data returned.
+   *
+   * Note that setting {@link ReadOptions#setSnapshot(Snapshot)} will affect
+   * what is read from the DB but will NOT change which keys are read from this
+   * transaction (the keys in this transaction do not yet belong to any snapshot
+   * and will be fetched regardless).
+   *
+   * @param readOptions Read options.=
+   *     {@link org.rocksdb.ColumnFamilyHandle} instances.
+   * @param keys of keys for which values need to be retrieved.
+   *
+   * @return Array of values, one for each key
+   *
+   * @throws RocksDBException thrown if error happens in underlying
+   *    native library.
+   */
+  public List<byte[]> multiGetAsList(final ReadOptions readOptions, final List<byte[]> keys)
+      throws RocksDBException {
+    if (keys.size() == 0) {
+      return new ArrayList<>(0);
+    }
+    final byte[][] keysArray = keys.toArray(new byte[keys.size()][]);
+
+    return Arrays.asList(multiGet(nativeHandle_, readOptions.nativeHandle_, keysArray));
+  }
+
   /**
    * Read this key and ensure that this transaction will only
    * be able to be committed if this key is not written outside this
@@ -541,9 +630,10 @@ public class Transaction extends RocksObject {
    * @throws RocksDBException thrown if error happens in underlying
    *    native library.
    */
+  @Deprecated
   public byte[][] multiGetForUpdate(final ReadOptions readOptions,
-      final List<ColumnFamilyHandle> columnFamilyHandles,
-      final byte[][] keys) throws RocksDBException {
+      final List<ColumnFamilyHandle> columnFamilyHandles, final byte[][] keys)
+      throws RocksDBException {
     assert(isOwningHandle());
     // Check if key size equals cfList size. If not a exception must be
     // thrown. If not a Segmentation fault happens.
@@ -562,6 +652,43 @@ public class Transaction extends RocksObject {
         keys, cfHandles);
   }
 
+  /**
+   * A multi-key version of
+   * {@link #getForUpdate(ReadOptions, ColumnFamilyHandle, byte[], boolean)}.
+   *
+   *
+   * @param readOptions Read options.
+   * @param columnFamilyHandles {@link org.rocksdb.ColumnFamilyHandle}
+   *     instances
+   * @param keys the keys to retrieve the values for.
+   *
+   * @return Array of values, one for each key
+   *
+   * @throws RocksDBException thrown if error happens in underlying
+   *    native library.
+   */
+  public List<byte[]> multiGetForUpdateAsList(final ReadOptions readOptions,
+      final List<ColumnFamilyHandle> columnFamilyHandles, final List<byte[]> keys)
+      throws RocksDBException {
+    assert (isOwningHandle());
+    // Check if key size equals cfList size. If not a exception must be
+    // thrown. If not a Segmentation fault happens.
+    if (keys.size() != columnFamilyHandles.size()) {
+      throw new IllegalArgumentException("For each key there must be a ColumnFamilyHandle.");
+    }
+    if (keys.size() == 0) {
+      return new ArrayList<>();
+    }
+    final byte[][] keysArray = keys.toArray(new byte[keys.size()][]);
+
+    final long[] cfHandles = new long[columnFamilyHandles.size()];
+    for (int i = 0; i < columnFamilyHandles.size(); i++) {
+      cfHandles[i] = columnFamilyHandles.get(i).nativeHandle_;
+    }
+    return Arrays.asList(
+        multiGetForUpdate(nativeHandle_, readOptions.nativeHandle_, keysArray, cfHandles));
+  }
+
   /**
    * A multi-key version of {@link #getForUpdate(ReadOptions, byte[], boolean)}.
    *
@@ -574,8 +701,9 @@ public class Transaction extends RocksObject {
    * @throws RocksDBException thrown if error happens in underlying
    *    native library.
    */
-  public byte[][] multiGetForUpdate(final ReadOptions readOptions,
-      final byte[][] keys) throws RocksDBException {
+  @Deprecated
+  public byte[][] multiGetForUpdate(final ReadOptions readOptions, final byte[][] keys)
+      throws RocksDBException {
     assert(isOwningHandle());
     if(keys.length == 0) {
       return new byte[0][0];
@@ -585,6 +713,30 @@ public class Transaction extends RocksObject {
         readOptions.nativeHandle_, keys);
   }
 
+  /**
+   * A multi-key version of {@link #getForUpdate(ReadOptions, byte[], boolean)}.
+   *
+   *
+   * @param readOptions Read options.
+   * @param keys the keys to retrieve the values for.
+   *
+   * @return List of values, one for each key
+   *
+   * @throws RocksDBException thrown if error happens in underlying
+   *    native library.
+   */
+  public List<byte[]> multiGetForUpdateAsList(
+      final ReadOptions readOptions, final List<byte[]> keys) throws RocksDBException {
+    assert (isOwningHandle());
+    if (keys.size() == 0) {
+      return new ArrayList<>(0);
+    }
+
+    final byte[][] keysArray = keys.toArray(new byte[keys.size()][]);
+
+    return Arrays.asList(multiGetForUpdate(nativeHandle_, readOptions.nativeHandle_, keysArray));
+  }
+
   /**
    * Returns an iterator that will iterate on all keys in the default
    * column family including both keys in the DB and uncommitted keys in this
@@ -611,9 +763,9 @@ public class Transaction extends RocksObject {
   }
 
   /**
-   * Returns an iterator that will iterate on all keys in the default
-   * column family including both keys in the DB and uncommitted keys in this
-   * transaction.
+   * Returns an iterator that will iterate on all keys in the column family
+   * specified by {@code columnFamilyHandle} including both keys in the DB
+   * and uncommitted keys in this transaction.
    *
    * Setting {@link ReadOptions#setSnapshot(Snapshot)} will affect what is read
    * from the DB but will NOT change which keys are read from this transaction
@@ -1068,7 +1220,7 @@ public class Transaction extends RocksObject {
    * @param columnFamilyHandle The column family to delete the key/value from
    * @param key the specified key to be deleted.
    * @param assumeTracked true when it is expected that the key is already
-   *     tracked. More specifically, it means the the key was previous tracked
+   *     tracked. More specifically, it means the key was previously tracked
    *     in the same savepoint, with the same exclusive flag, and at a lower
    *     sequence number. If valid then it skips ValidateSnapshot,
    *     throws an error otherwise.
@@ -1152,7 +1304,7 @@ public class Transaction extends RocksObject {
    * @param columnFamilyHandle The column family to delete the key/value from
    * @param keyParts the specified key to be deleted.
    * @param assumeTracked true when it is expected that the key is already
-   *     tracked. More specifically, it means the the key was previous tracked
+   *     tracked. More specifically, it means the key was previously tracked
    *     in the same savepoint, with the same exclusive flag, and at a lower
    *     sequence number. If valid then it skips ValidateSnapshot,
    *     throws an error otherwise.