]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Added SstFileWriter construtor without explicit comparator to JNI api
authorMikhail Antonov <antonov@apache.org>
Thu, 30 Mar 2017 00:13:43 +0000 (17:13 -0700)
committerIslam AbdelRahman <tec@fb.com>
Tue, 4 Apr 2017 00:47:05 +0000 (17:47 -0700)
Summary:
Adding API missing after https://github.com/facebook/rocksdb/commit/1ffbdfd9a7637b6517053842386d71df2cd00d9b#diff-b94146418eed4a9c1bf324041b95b279.

adamretter  IslamAbdelRahman

Tested locally.
Closes https://github.com/facebook/rocksdb/pull/2028

Differential Revision: D4762817

Pulled By: IslamAbdelRahman

fbshipit-source-id: 833f478

java/rocksjni/sst_file_writerjni.cc
java/src/main/java/org/rocksdb/SstFileWriter.java
java/src/test/java/org/rocksdb/SstFileWriterTest.java

index fe3ec39403643a3d3be948fc747962998f34796b..879f93e07818fb2caaad1eb1569155fca0d3a34b 100644 (file)
@@ -22,7 +22,7 @@
  * Method:    newSstFileWriter
  * Signature: (JJJ)J
  */
-jlong Java_org_rocksdb_SstFileWriter_newSstFileWriter(JNIEnv *env, jclass jcls,
+jlong Java_org_rocksdb_SstFileWriter_newSstFileWriter__JJJ(JNIEnv *env, jclass jcls,
                                                       jlong jenvoptions,
                                                       jlong joptions,
                                                       jlong jcomparator) {
@@ -35,6 +35,22 @@ jlong Java_org_rocksdb_SstFileWriter_newSstFileWriter(JNIEnv *env, jclass jcls,
   return reinterpret_cast<jlong>(sst_file_writer);
 }
 
+/*
+ * Class:     org_rocksdb_SstFileWriter
+ * Method:    newSstFileWriter
+ * Signature: (JJ)J
+ */
+jlong Java_org_rocksdb_SstFileWriter_newSstFileWriter__JJ(JNIEnv *env, jclass jcls,
+                                                      jlong jenvoptions,
+                                                      jlong joptions) {
+  auto *env_options =
+      reinterpret_cast<const rocksdb::EnvOptions *>(jenvoptions);
+  auto *options = reinterpret_cast<const rocksdb::Options *>(joptions);
+  rocksdb::SstFileWriter *sst_file_writer =
+      new rocksdb::SstFileWriter(*env_options, *options);
+  return reinterpret_cast<jlong>(sst_file_writer);
+}
+
 /*
  * Class:     org_rocksdb_SstFileWriter
  * Method:    open
index 38d819aaa5bc5501873e07d63dd687ebc97ce340..130a496203f5f06cb5287d8c6c039bca05a1973e 100644 (file)
@@ -16,6 +16,11 @@ public class SstFileWriter extends RocksObject {
         envOptions.nativeHandle_, options.nativeHandle_, comparator.getNativeHandle()));
   }
 
+  public SstFileWriter(final EnvOptions envOptions, final Options options) {
+    super(newSstFileWriter(
+        envOptions.nativeHandle_, options.nativeHandle_));
+  }
+
   public void open(final String filePath) throws RocksDBException {
     open(nativeHandle_, filePath);
   }
@@ -35,6 +40,9 @@ public class SstFileWriter extends RocksObject {
   private native static long newSstFileWriter(
       final long envOptionsHandle, final long optionsHandle, final long userComparatorHandle);
 
+  private native static long newSstFileWriter(final long envOptionsHandle,
+      final long optionsHandle);
+
   private native void open(final long handle, final String filePath) throws RocksDBException;
 
   private native void add(final long handle, final long keyHandle, final long valueHandle)
index eb8c76d3491419a6abe1ffc12667753385230f04..5f2a4b10ef00c6382f51cc5eb446147716874a17 100644 (file)
@@ -27,13 +27,23 @@ public class SstFileWriterTest {
 
   @Rule public TemporaryFolder parentFolder = new TemporaryFolder();
 
-  private File newSstFile(final TreeMap<String, String> keyValues)
+  private File newSstFile(final TreeMap<String, String> keyValues,
+      boolean useJavaBytewiseComparator)
       throws IOException, RocksDBException {
     final EnvOptions envOptions = new EnvOptions();
-    final ComparatorOptions comparatorOptions = new ComparatorOptions();
-    final BytewiseComparator comparator = new BytewiseComparator(comparatorOptions);
-    final Options options = new Options().setComparator(comparator);
-    final SstFileWriter sstFileWriter = new SstFileWriter(envOptions, options, comparator);
+    final Options options = new Options();
+    SstFileWriter sstFileWriter = null;
+    ComparatorOptions comparatorOptions = null;
+    BytewiseComparator comparator = null;
+    if (useJavaBytewiseComparator) {
+      comparatorOptions = new ComparatorOptions();
+      comparator = new BytewiseComparator(comparatorOptions);
+      options.setComparator(comparator);
+      sstFileWriter = new SstFileWriter(envOptions, options, comparator);
+    } else {
+      sstFileWriter = new SstFileWriter(envOptions, options);
+    }
+
     final File sstFile = parentFolder.newFile(SST_FILE_NAME);
     try {
       sstFileWriter.open(sstFile.getAbsolutePath());
@@ -50,18 +60,30 @@ public class SstFileWriterTest {
       sstFileWriter.close();
       options.close();
       envOptions.close();
-      comparatorOptions.close();
-      comparator.close();
+      if (comparatorOptions != null) {
+        comparatorOptions.close();
+      }
+      if (comparator != null) {
+        comparator.close();
+      }
     }
     return sstFile;
   }
 
   @Test
-  public void generateSstFile() throws RocksDBException, IOException {
+  public void generateSstFileWithJavaComparator() throws RocksDBException, IOException {
+    final TreeMap<String, String> keyValues = new TreeMap<>();
+    keyValues.put("key1", "value1");
+    keyValues.put("key2", "value2");
+    newSstFile(keyValues, true);
+  }
+
+  @Test
+  public void generateSstFileWithNativeComparator() throws RocksDBException, IOException {
     final TreeMap<String, String> keyValues = new TreeMap<>();
     keyValues.put("key1", "value1");
     keyValues.put("key2", "value2");
-    newSstFile(keyValues);
+    newSstFile(keyValues, false);
   }
 
   @Test
@@ -69,7 +91,7 @@ public class SstFileWriterTest {
     final TreeMap<String, String> keyValues = new TreeMap<>();
     keyValues.put("key1", "value1");
     keyValues.put("key2", "value2");
-    final File sstFile = newSstFile(keyValues);
+    final File sstFile = newSstFile(keyValues, false);
     final File dbFolder = parentFolder.newFolder(DB_DIRECTORY_NAME);
     final Options options = new Options().setCreateIfMissing(true);
     final RocksDB db = RocksDB.open(options, dbFolder.getAbsolutePath());