Integrated feedback from ankgup87

Test Plan: tested using unit tests

Reviewers: ankgup87

Differential Revision: https://reviews.facebook.net/D24573
main
Vlad Balan 10 years ago
parent a40ce219b9
commit 2ef3ed86f3
  1. 8
      java/org/rocksdb/MergeOperator.java
  2. 10
      java/org/rocksdb/Options.java
  3. 5
      java/org/rocksdb/RocksDB.java
  4. 12
      java/org/rocksdb/StringAppendOperator.java
  5. 3
      java/org/rocksdb/test/MergeTest.java
  6. 10
      java/rocksjni/merge_operator.cc
  7. 4
      java/rocksjni/options.cc

@ -9,11 +9,9 @@ import java.util.*;
/**
* MergeOperator holds an operator to be applied when compacting
* two values held under the same key in order to obtain a single
* two merge operands held under the same key in order to obtain a single
* value.
*/
public abstract class MergeOperator {
abstract protected long newMergeOperatorHandle();
public interface MergeOperator {
public long newMergeOperatorHandle();
}

@ -2235,13 +2235,16 @@ public class Options extends RocksObject {
long handle, int minPartialMergeOperands);
/**
* Set the merge operator to be used for merging two different key/value
* pairs that share the same key. The merge function is invoked during
* Set the merge operator to be used for merging two merge operands
* of the same key. The merge function is invoked during
* compaction and at lookup time, if multiple key/value pairs belonging
* to the same key are found in the database.
*
* @param name the name of the merge function, as defined by
* the MergeOperators factory (see utilities/MergeOperators.h)
* The merge function is specified by name and must be one of the
* standard merge operators provided by RocksDB. The available
* operators are "put", "uint64add", "stringappend" and "stringappendtest".
* @return the reference to the current option.
*/
public Options setMergeOperatorName(String name) {
@ -2257,8 +2260,7 @@ public class Options extends RocksObject {
* compaction and at lookup time, if multiple key/value pairs belonging
* to the same key are found in the database.
*
* @param name the name of the merge function, as defined by
* the MergeOperators factory (see utilities/MergeOperators.h)
* @param a {@link MergeOperator} object
* @return the reference to the current option.
*/
public Options setMergeOperator(MergeOperator mergeOperator) {

@ -473,7 +473,7 @@ public class RocksDB extends RocksObject {
}
/**
* Set the database entry for "key" to "value".
* Add merge operand for key/value pair.
*
* @param key the specified key to be merged.
* @param value the value to be nerged with the current value for
@ -484,8 +484,9 @@ public class RocksDB extends RocksObject {
}
/**
* Merge the database entry for "key" with "value".
* Add merge operand for key/value pair.
*
* @param writeOpts {@link WriteOptions} for this write.
* @param key the specified key to be merged.
* @param value the value to be merged with the current value for
* the specified key.

@ -6,16 +6,12 @@
package org.rocksdb;
/**
* MergeOperator holds an operator to be applied when compacting
* two values held under the same key in order to obtain a single
* value.
* StringAppendOperator is a merge operator that concatenates
* two strings.
*/
public class StringAppendOperator extends MergeOperator {
@Override protected long newMergeOperatorHandle() {
public class StringAppendOperator implements MergeOperator {
@Override public long newMergeOperatorHandle() {
return newMergeOperatorHandleImpl();
}
private native long newMergeOperatorHandleImpl();
}

@ -43,7 +43,6 @@ public class MergeTest {
assert(strValue.equals("aa,bb"));
System.out.println("Merge function string option passed!");
}
public static void testOperatorOption()
@ -76,13 +75,11 @@ public class MergeTest {
assert(strValue.equals("aa,bb"));
System.out.println("Merge function operator option passed!");
}
public static void main(String[] args)
throws InterruptedException, RocksDBException {
testStringOption();
testOperatorOption();
}
}

@ -3,7 +3,8 @@
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
//
// This file implements the "bridge" between Java and C++ for rocksdb::MergeOperator.
// This file implements the "bridge" between Java and C++
// for rocksdb::MergeOperator.
#include <stdio.h>
#include <stdlib.h>
@ -27,9 +28,10 @@
* Method: newMergeOperatorHandle
* Signature: ()J
*/
jlong Java_org_rocksdb_StringAppendOperator_newMergeOperatorHandleImpl(JNIEnv* env, jobject jobj) {
std::shared_ptr<rocksdb::MergeOperator> *op = new std::shared_ptr<rocksdb::MergeOperator>();
jlong Java_org_rocksdb_StringAppendOperator_newMergeOperatorHandleImpl
(JNIEnv* env, jobject jobj) {
std::shared_ptr<rocksdb::MergeOperator> *op =
new std::shared_ptr<rocksdb::MergeOperator>();
*op = rocksdb::MergeOperators::CreateFromStringId("stringappend");
return reinterpret_cast<jlong>(op);
}

@ -1625,7 +1625,8 @@ void Java_org_rocksdb_Options_setMergeOperatorName(
void Java_org_rocksdb_Options_setMergeOperator(
JNIEnv* env, jobject jobj, jlong jhandle, jlong mergeOperatorHandle) {
reinterpret_cast<rocksdb::Options*>(jhandle)->merge_operator =
*(reinterpret_cast<std::shared_ptr<rocksdb::MergeOperator>*> (mergeOperatorHandle));
*(reinterpret_cast<std::shared_ptr<rocksdb::MergeOperator>*>
(mergeOperatorHandle));
}
//////////////////////////////////////////////////////////////////////////////
@ -1784,4 +1785,3 @@ void Java_org_rocksdb_ReadOptions_setTailing(
reinterpret_cast<rocksdb::ReadOptions*>(jhandle)->tailing =
static_cast<bool>(jtailing);
}

Loading…
Cancel
Save