From 3d00271e40ca909597559837b62e59cc385053be Mon Sep 17 00:00:00 2001 From: Adam Retter Date: Tue, 14 Jul 2015 17:44:51 +0100 Subject: [PATCH] The ability to specify a compaction filter via the Java API --- java/Makefile | 3 +- java/rocksjni/compaction_filter.cc | 24 +++++++++++++++ java/rocksjni/options.cc | 13 +++++++++ .../org/rocksdb/AbstractCompactionFilter.java | 29 +++++++++++++++++++ .../java/org/rocksdb/ColumnFamilyOptions.java | 9 ++++++ src.mk | 1 + 6 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 java/rocksjni/compaction_filter.cc create mode 100644 java/src/main/java/org/rocksdb/AbstractCompactionFilter.java diff --git a/java/Makefile b/java/Makefile index 303c46382..fcd441ca4 100644 --- a/java/Makefile +++ b/java/Makefile @@ -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\ diff --git a/java/rocksjni/compaction_filter.cc b/java/rocksjni/compaction_filter.cc new file mode 100644 index 000000000..5fa52c0dc --- /dev/null +++ b/java/rocksjni/compaction_filter.cc @@ -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 + +#include "rocksdb/compaction_filter.h" + +// + +/* + * Class: org_rocksdb_AbstractCompactionFilter + * Method: disposeInternal + * Signature: (J)V + */ +void Java_org_rocksdb_AbstractCompactionFilter_disposeInternal( + JNIEnv* env, jobject jobj, jlong handle) { + delete reinterpret_cast(handle); +} +// diff --git a/java/rocksjni/options.cc b/java/rocksjni/options.cc index c1d30ee16..98ac12bd3 100644 --- a/java/rocksjni/options.cc +++ b/java/rocksjni/options.cc @@ -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(jopt_handle)-> + compaction_filter = reinterpret_cast + (jcompactionfilter_handle); +} + /* * Class: org_rocksdb_ColumnFamilyOptions * Method: setWriteBufferSize diff --git a/java/src/main/java/org/rocksdb/AbstractCompactionFilter.java b/java/src/main/java/org/rocksdb/AbstractCompactionFilter.java new file mode 100644 index 000000000..2b78deddb --- /dev/null +++ b/java/src/main/java/org/rocksdb/AbstractCompactionFilter.java @@ -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> + 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); +} diff --git a/java/src/main/java/org/rocksdb/ColumnFamilyOptions.java b/java/src/main/java/org/rocksdb/ColumnFamilyOptions.java index c916ccbd8..ab0d55161 100644 --- a/java/src/main/java/org/rocksdb/ColumnFamilyOptions.java +++ b/java/src/main/java/org/rocksdb/ColumnFamilyOptions.java @@ -145,6 +145,13 @@ public class ColumnFamilyOptions extends RocksObject return this; } + public ColumnFamilyOptions setCompactionFilter( + final AbstractCompactionFilter> 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> comparator_; + AbstractCompactionFilter> compactionFilter_; } diff --git a/src.mk b/src.mk index f4a16672c..6fc690f32 100644 --- a/src.mk +++ b/src.mk @@ -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 \