Merge pull request #654 from adamretter/remove-emptyvalue-compactionfilter
RemoveEmptyValueCompactionFiltermain
commit
f39cbcb0a5
@ -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>
|
@ -0,0 +1,27 @@ |
||||
// 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.
|
||||
|
||||
#include <jni.h> |
||||
|
||||
#include "include/org_rocksdb_RemoveEmptyValueCompactionFilter.h" |
||||
#include "utilities/compaction_filters/remove_emptyvalue_compactionfilter.h" |
||||
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_RemoveEmptyValueCompactionFilter |
||||
* Method: createNewRemoveEmptyValueCompactionFilter0 |
||||
* Signature: ()V |
||||
*/ |
||||
void Java_org_rocksdb_RemoveEmptyValueCompactionFilter_createNewRemoveEmptyValueCompactionFilter0( |
||||
JNIEnv* env, jobject jobj) { |
||||
const rocksdb::RemoveEmptyValueCompactionFilter* compaction_filter = |
||||
new rocksdb::RemoveEmptyValueCompactionFilter(); |
||||
|
||||
// set the native handle to our native compaction filter
|
||||
static jclass jclazz = |
||||
env->FindClass("org/rocksdb/RemoveEmptyValueCompactionFilter"); |
||||
static jfieldID fid = env->GetFieldID(jclazz, "nativeHandle_", "J"); |
||||
env->SetLongField(jobj, fid, reinterpret_cast<jlong>(compaction_filter)); |
||||
} |
@ -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); |
||||
} |
@ -0,0 +1,18 @@ |
||||
// Copyright (c) 2014, 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; |
||||
|
||||
/** |
||||
* Just a Java wrapper around EmptyValueCompactionFilter implemented in C++ |
||||
*/ |
||||
public class RemoveEmptyValueCompactionFilter extends AbstractCompactionFilter<Slice> { |
||||
public RemoveEmptyValueCompactionFilter() { |
||||
super(); |
||||
createNewRemoveEmptyValueCompactionFilter0(); |
||||
} |
||||
|
||||
private native void createNewRemoveEmptyValueCompactionFilter0(); |
||||
} |
@ -0,0 +1,30 @@ |
||||
// 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.
|
||||
|
||||
#ifndef ROCKSDB_LITE |
||||
|
||||
#include <string> |
||||
|
||||
#include "rocksdb/slice.h" |
||||
#include "utilities/compaction_filters/remove_emptyvalue_compactionfilter.h" |
||||
|
||||
namespace rocksdb { |
||||
|
||||
const char* RemoveEmptyValueCompactionFilter::Name() const { |
||||
return "RemoveEmptyValueCompactionFilter"; |
||||
} |
||||
|
||||
bool RemoveEmptyValueCompactionFilter::Filter(int level, |
||||
const Slice& key, |
||||
const Slice& existing_value, |
||||
std::string* new_value, |
||||
bool* value_changed) const { |
||||
|
||||
// remove kv pairs that have empty values
|
||||
return existing_value.empty(); |
||||
} |
||||
|
||||
} // namespace rocksdb
|
||||
#endif // !ROCKSDB_LITE
|
@ -0,0 +1,27 @@ |
||||
// 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.
|
||||
|
||||
#ifndef ROCKSDB_LITE |
||||
|
||||
#pragma once |
||||
|
||||
#include <string> |
||||
|
||||
#include "rocksdb/compaction_filter.h" |
||||
#include "rocksdb/slice.h" |
||||
|
||||
namespace rocksdb { |
||||
|
||||
class RemoveEmptyValueCompactionFilter : public CompactionFilter { |
||||
public: |
||||
const char* Name() const override; |
||||
bool Filter(int level, |
||||
const Slice& key, |
||||
const Slice& existing_value, |
||||
std::string* new_value, |
||||
bool* value_changed) const override; |
||||
}; |
||||
} // namespace rocksdb
|
||||
#endif // !ROCKSDB_LITE
|
Loading…
Reference in new issue