The ability to specify a compaction filter via the Java API

This commit is contained in:
Adam Retter 2015-07-14 17:44:51 +01:00
parent 62dec0e2b7
commit 3d00271e40
6 changed files with 78 additions and 1 deletions

View File

@ -1,4 +1,5 @@
NATIVE_JAVA_CLASSES = org.rocksdb.AbstractComparator\
NATIVE_JAVA_CLASSES = org.rocksdb.AbstractCompactionFilter\
org.rocksdb.AbstractComparator\
org.rocksdb.AbstractSlice\
org.rocksdb.BackupableDB\
org.rocksdb.BackupableDBOptions\

View File

@ -0,0 +1,24 @@
// Copyright (c) 2015, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// 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::CompactionFilter.
#include <jni.h>
#include "rocksdb/compaction_filter.h"
// <editor-fold desc="org.rocksdb.AbstractCompactionFilter">
/*
* Class: org_rocksdb_AbstractCompactionFilter
* Method: disposeInternal
* Signature: (J)V
*/
void Java_org_rocksdb_AbstractCompactionFilter_disposeInternal(
JNIEnv* env, jobject jobj, jlong handle) {
delete reinterpret_cast<rocksdb::CompactionFilter*>(handle);
}
// </editor-fold>

View File

@ -2053,6 +2053,19 @@ void Java_org_rocksdb_ColumnFamilyOptions_setMergeOperator(
(mergeOperatorHandle));
}
/*
* Class: org_rocksdb_ColumnFamilyOptions
* Method: setCompactionFilterHandle
* Signature: (JJ)V
*/
void Java_org_rocksdb_ColumnFamilyOptions_setCompactionFilterHandle__JJ(
JNIEnv* env, jobject jobj, jlong jopt_handle,
jlong jcompactionfilter_handle) {
reinterpret_cast<rocksdb::ColumnFamilyOptions*>(jopt_handle)->
compaction_filter = reinterpret_cast<rocksdb::CompactionFilter*>
(jcompactionfilter_handle);
}
/*
* Class: org_rocksdb_ColumnFamilyOptions
* Method: setWriteBufferSize

View File

@ -0,0 +1,29 @@
// Copyright (c) 2015, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// 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.
package org.rocksdb;
/**
* A CompactionFilter allows an application to modify/delete a key-value at
* the time of compaction.
*
* At present we just permit an overriding Java class to wrap a C++ implementation
*/
public abstract class AbstractCompactionFilter<T extends AbstractSlice<?>>
extends RocksObject {
/**
* Deletes underlying C++ comparator pointer.
*
* Note that this function should be called only after all
* RocksDB instances referencing the comparator are closed.
* Otherwise an undefined behavior will occur.
*/
@Override protected void disposeInternal() {
assert(isInitialized());
disposeInternal(nativeHandle_);
}
private native void disposeInternal(long handle);
}

View File

@ -145,6 +145,13 @@ public class ColumnFamilyOptions extends RocksObject
return this;
}
public ColumnFamilyOptions setCompactionFilter(
final AbstractCompactionFilter<? extends AbstractSlice<?>> compactionFilter) {
setCompactionFilterHandle(nativeHandle_, compactionFilter.nativeHandle_);
compactionFilter_ = compactionFilter;
return this;
}
@Override
public ColumnFamilyOptions setWriteBufferSize(final long writeBufferSize) {
assert(isInitialized());
@ -680,6 +687,7 @@ public class ColumnFamilyOptions extends RocksObject
long handle, String name);
private native void setMergeOperator(
long handle, long mergeOperatorHandle);
private native void setCompactionFilterHandle(long handle, long compactionFilterHandle);
private native void setWriteBufferSize(long handle, long writeBufferSize)
throws IllegalArgumentException;
private native long writeBufferSize(long handle);
@ -803,4 +811,5 @@ public class ColumnFamilyOptions extends RocksObject
MemTableConfig memTableConfig_;
TableFormatConfig tableFormatConfig_;
AbstractComparator<? extends AbstractSlice<?>> comparator_;
AbstractCompactionFilter<? extends AbstractSlice<?>> compactionFilter_;
}

1
src.mk
View File

@ -246,6 +246,7 @@ JNI_NATIVE_SOURCES = \
java/rocksjni/backupablejni.cc \
java/rocksjni/checkpoint.cc \
java/rocksjni/columnfamilyhandle.cc \
java/rocksjni/compaction_filter.cc \
java/rocksjni/comparator.cc \
java/rocksjni/comparatorjnicallback.cc \
java/rocksjni/env.cc \