Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
azagrebin committed Jan 31, 2019
1 parent 94f52f9 commit 4055f77
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 24 deletions.
2 changes: 2 additions & 0 deletions java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ set(NATIVE_JAVA_CLASSES
org.rocksdb.SstFileWriter
org.rocksdb.Statistics
org.rocksdb.StringAppendOperator
org.rocksdb.StringAppendOperatorWithVariableDelimitor
org.rocksdb.TableFormatConfig
org.rocksdb.Transaction
org.rocksdb.TransactionDB
Expand Down Expand Up @@ -260,6 +261,7 @@ add_jar(
src/main/java/org/rocksdb/StatsLevel.java
src/main/java/org/rocksdb/Status.java
src/main/java/org/rocksdb/StringAppendOperator.java
src/main/java/org/rocksdb/StringAppendOperatorWithVariableDelimitor.java
src/main/java/org/rocksdb/TableFormatConfig.java
src/main/java/org/rocksdb/TickerType.java
src/main/java/org/rocksdb/TransactionalDB.java
Expand Down
1 change: 1 addition & 0 deletions java/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ NATIVE_JAVA_CLASSES = org.rocksdb.AbstractCompactionFilter\
org.rocksdb.VectorMemTableConfig\
org.rocksdb.Snapshot\
org.rocksdb.StringAppendOperator\
org.rocksdb.StringAppendOperatorWithVariableDelimitor\
org.rocksdb.WriteBatch\
org.rocksdb.WriteBatch.Handler\
org.rocksdb.WriteOptions\
Expand Down
30 changes: 22 additions & 8 deletions java/rocksjni/merge_operator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <string>

#include "include/org_rocksdb_StringAppendOperator.h"
#include "include/org_rocksdb_StringAppendOperatorWithVariableDelimitor.h"
#include "rocksdb/db.h"
#include "rocksdb/memtablerep.h"
#include "rocksdb/merge_operator.h"
Expand All @@ -37,10 +38,23 @@ jlong Java_org_rocksdb_StringAppendOperator_newSharedStringAppendOperator(

/*
* Class: org_rocksdb_StringAppendOperator
* Method: disposeInternal
* Signature: (J)V
*/
void Java_org_rocksdb_StringAppendOperator_disposeInternal(JNIEnv* /*env*/,
jobject /*jobj*/,
jlong jhandle) {
auto* sptr_string_append_op =
reinterpret_cast<std::shared_ptr<rocksdb::MergeOperator>*>(jhandle);
delete sptr_string_append_op; // delete std::shared_ptr
}

/*
* Class: org_rocksdb_StringAppendOperatorWithVariableDelimitor
* Method: newSharedStringAppendTESTOperator
* Signature: ([B)J
*/
jlong Java_org_rocksdb_StringAppendOperator_newSharedStringAppendTESTOperator(
jlong Java_org_rocksdb_StringAppendOperatorWithVariableDelimitor_newSharedStringAppendTESTOperator(
JNIEnv* env, jclass /*jclazz*/, jbyteArray jdelim) {
jboolean has_exception = JNI_FALSE;
std::string delim = rocksdb::JniUtil::byteString<std::string>(
Expand All @@ -58,14 +72,14 @@ jlong Java_org_rocksdb_StringAppendOperator_newSharedStringAppendTESTOperator(
}

/*
* Class: org_rocksdb_StringAppendOperator
* Class: org_rocksdb_StringAppendOperatorWithVariableDelimitor
* Method: disposeInternal
* Signature: (J)V
*/
void Java_org_rocksdb_StringAppendOperator_disposeInternal(JNIEnv* /*env*/,
jobject /*jobj*/,
jlong jhandle) {
auto* sptr_string_append_op =
reinterpret_cast<std::shared_ptr<rocksdb::MergeOperator>*>(jhandle);
delete sptr_string_append_op; // delete std::shared_ptr
void Java_org_rocksdb_StringAppendOperatorWithVariableDelimitor_disposeInternal(JNIEnv* /*env*/,
jobject /*jobj*/,
jlong jhandle) {
auto* sptr_string_append_test_op =
reinterpret_cast<std::shared_ptr<rocksdb::MergeOperator>*>(jhandle);
delete sptr_string_append_test_op; // delete std::shared_ptr
}
15 changes: 0 additions & 15 deletions java/src/main/java/org/rocksdb/StringAppendOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.rocksdb;

import java.nio.charset.Charset;

/**
* StringAppendOperator is a merge operator that concatenates
* two strings.
Expand All @@ -20,19 +18,6 @@ public StringAppendOperator(char delim) {
super(newSharedStringAppendOperator(delim));
}

public StringAppendOperator(byte[] delim) {
super(newSharedStringAppendTESTOperator(delim));
}

public StringAppendOperator(String delim) {
this(delim.getBytes());
}

public StringAppendOperator(String delim, Charset charset) {
this(delim.getBytes(charset));
}

private native static long newSharedStringAppendOperator(final char delim);
private native static long newSharedStringAppendTESTOperator(final byte[] delim);
@Override protected final native void disposeInternal(final long handle);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.rocksdb;

import java.nio.charset.Charset;

/**
* Merge operator that concatenates two strings with a delimiter of variable length, string or byte array.
*/
public class StringAppendOperatorWithVariableDelimitor extends MergeOperator {
public StringAppendOperatorWithVariableDelimitor() {
this(',');
}

public StringAppendOperatorWithVariableDelimitor(char delim) {
this(Character.toString(delim));
}

public StringAppendOperatorWithVariableDelimitor(byte[] delim) {
super(newSharedStringAppendTESTOperator(delim));
}

public StringAppendOperatorWithVariableDelimitor(String delim) {
this(delim.getBytes());
}

public StringAppendOperatorWithVariableDelimitor(String delim, Charset charset) {
this(delim.getBytes(charset));
}

private native static long newSharedStringAppendTESTOperator(final byte[] delim);
@Override protected final native void disposeInternal(final long handle);
}
2 changes: 1 addition & 1 deletion java/src/test/java/org/rocksdb/MergeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void stringDelimiter() throws RocksDBException {
}

private void stringDelimiter(String delim) throws RocksDBException {
try (final StringAppendOperator stringAppendOperator = new StringAppendOperator(delim.getBytes());
try (final MergeOperator stringAppendOperator = new StringAppendOperatorWithVariableDelimitor(delim.getBytes());
final Options opt = new Options()
.setCreateIfMissing(true)
.setMergeOperator(stringAppendOperator);
Expand Down

0 comments on commit 4055f77

Please sign in to comment.