Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kvdb
rocksdb
提交
5e797cf0
R
rocksdb
项目概览
kvdb
/
rocksdb
11 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rocksdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5e797cf0
编写于
4月 21, 2014
作者:
A
Ankit Gupta
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change filter implementation
上级
cea2be20
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
138 addition
and
29 deletion
+138
-29
java/Makefile
java/Makefile
+1
-1
java/RocksDBSample.java
java/RocksDBSample.java
+3
-1
java/org/rocksdb/Filter.java
java/org/rocksdb/Filter.java
+50
-0
java/org/rocksdb/Options.java
java/org/rocksdb/Options.java
+5
-15
java/rocksjni/filter.cc
java/rocksjni/filter.cc
+39
-0
java/rocksjni/options.cc
java/rocksjni/options.cc
+6
-12
java/rocksjni/portal.h
java/rocksjni/portal.h
+34
-0
未找到文件。
java/Makefile
浏览文件 @
5e797cf0
NATIVE_JAVA_CLASSES
=
org.rocksdb.RocksDB org.rocksdb.Options org.rocksdb.WriteBatch org.rocksdb.WriteBatchInternal org.rocksdb.WriteBatchTest org.rocksdb.WriteOptions org.rocksdb.BackupableDB org.rocksdb.BackupableDBOptions org.rocksdb.Statistics org.rocksdb.Iterator org.rocksdb.VectorMemTableConfig org.rocksdb.SkipListMemTableConfig org.rocksdb.HashLinkedListMemTableConfig org.rocksdb.HashSkipListMemTableConfig org.rocksdb.PlainTableConfig org.rocksdb.ReadOptions
NATIVE_JAVA_CLASSES
=
org.rocksdb.RocksDB org.rocksdb.Options org.rocksdb.WriteBatch org.rocksdb.WriteBatchInternal org.rocksdb.WriteBatchTest org.rocksdb.WriteOptions org.rocksdb.BackupableDB org.rocksdb.BackupableDBOptions org.rocksdb.Statistics org.rocksdb.Iterator org.rocksdb.VectorMemTableConfig org.rocksdb.SkipListMemTableConfig org.rocksdb.HashLinkedListMemTableConfig org.rocksdb.HashSkipListMemTableConfig org.rocksdb.PlainTableConfig org.rocksdb.ReadOptions
org.rocksdb.Filter
NATIVE_INCLUDE
=
./include
ROCKSDB_JAR
=
rocksdbjni.jar
...
...
java/RocksDBSample.java
浏览文件 @
5e797cf0
...
...
@@ -32,6 +32,7 @@ public class RocksDBSample {
assert
(
db
==
null
);
}
Filter
filter
=
new
Filter
(
10
);
options
.
setCreateIfMissing
(
true
)
.
createStatistics
()
.
setWriteBufferSize
(
8
*
SizeUnit
.
KB
)
...
...
@@ -39,7 +40,7 @@ public class RocksDBSample {
.
setDisableSeekCompaction
(
true
)
.
setBlockSize
(
64
*
SizeUnit
.
KB
)
.
setMaxBackgroundCompactions
(
10
)
.
createBloomFilter
(
10
);
.
setFilter
(
filter
);
Statistics
stats
=
options
.
statisticsPtr
();
assert
(
options
.
createIfMissing
()
==
true
);
...
...
@@ -225,5 +226,6 @@ public class RocksDBSample {
// be sure to dispose c++ pointers
options
.
dispose
();
readOptions
.
dispose
();
filter
.
dispose
();
}
}
java/org/rocksdb/Filter.java
0 → 100644
浏览文件 @
5e797cf0
// 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
;
/**
* Filters are stored in rocksdb and are consulted automatically
* by rocksdb to decide whether or not to read some
* information from disk. In many cases, a filter can cut down the
* number of disk seeks form a handful to a single disk seek per
* DB::Get() call.
*
* This function a new filter policy that uses a bloom filter
* with approximately the specified number of bits per key.
* A good value for bitsPerKey is 10, which yields a filter
* with ~ 1% false positive rate.
*/
public
class
Filter
{
private
long
nativeHandle_
;
public
Filter
(
int
bitsPerKey
)
{
newFilter
(
bitsPerKey
);
}
public
long
getNativeHandle
()
{
return
nativeHandle_
;
}
/**
* Deletes underlying C++ filter pointer.
*/
public
synchronized
void
dispose
()
{
if
(
nativeHandle_
!=
0
)
{
dispose0
(
nativeHandle_
);
}
}
@Override
protected
void
finalize
()
{
dispose
();
}
private
boolean
isInitialized
()
{
return
(
nativeHandle_
!=
0
);
}
private
native
void
newFilter
(
int
bitsPerKey
);
private
native
void
dispose0
(
long
handle
);
}
\ No newline at end of file
java/org/rocksdb/Options.java
浏览文件 @
5e797cf0
...
...
@@ -145,24 +145,14 @@ public class Options {
}
/**
* Filters are stored in rocksdb and are consulted automatically
* by rocksdb to decide whether or not to read some
* information from disk. In many cases, a filter can cut down the
* number of disk seeks form a handful to a single disk seek per
* DB::Get() call.
*
* This function a new filter policy that uses a bloom filter
* with approximately the specified number of bits per key.
* A good value for bitsPerKey is 10, which yields a filter
* with ~ 1% false positive rate.
*
* @param Bits per key for bloom filter.
* Use the specified filter policy to reduce disk reads.
* @param Filter policy java instance.
* @return the instance of the current Options.
* @see RocksDB.open()
*/
public
Options
createBloomFilter
(
int
bitsPerKey
)
{
public
Options
setFilter
(
Filter
filter
)
{
assert
(
isInitialized
());
createBloomFilter0
(
nativeHandle_
,
bitsPerKey
);
setFilter0
(
nativeHandle_
,
filter
.
getNativeHandle
()
);
return
this
;
}
...
...
@@ -1260,7 +1250,7 @@ public class Options {
private
native
void
useFixedLengthPrefixExtractor
(
long
handle
,
int
prefixLength
);
private
native
void
createBloomFilter0
(
long
handle
,
int
bitsPerKey
);
private
native
void
setFilter0
(
long
optHandle
,
long
fpHandle
);
long
nativeHandle_
;
long
cacheSize_
;
...
...
java/rocksjni/filter.cc
0 → 100644
浏览文件 @
5e797cf0
// 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.
//
// This file implements the "bridge" between Java and C++ for rocksdb::Filter.
#include <stdio.h>
#include <stdlib.h>
#include <jni.h>
#include <string>
#include "include/org_rocksdb_Filter.h"
#include "rocksjni/portal.h"
#include "rocksdb/filter_policy.h"
/*
* Class: org_rocksdb_Filter
* Method: newFilter
* Signature: (I)V
*/
void
Java_org_rocksdb_Filter_newFilter
(
JNIEnv
*
env
,
jobject
jobj
,
jint
bits_per_key
)
{
const
rocksdb
::
FilterPolicy
*
fp
=
rocksdb
::
NewBloomFilterPolicy
(
bits_per_key
);
rocksdb
::
FilterJni
::
setHandle
(
env
,
jobj
,
fp
);
}
/*
* Class: org_rocksdb_Filter
* Method: dispose0
* Signature: (J)V
*/
void
Java_org_rocksdb_Filter_dispose0
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
handle
)
{
auto
fp
=
reinterpret_cast
<
rocksdb
::
FilterPolicy
*>
(
handle
);
delete
fp
;
rocksdb
::
FilterJni
::
setHandle
(
env
,
jobj
,
nullptr
);
}
\ No newline at end of file
java/rocksjni/options.cc
浏览文件 @
5e797cf0
...
...
@@ -122,19 +122,13 @@ jlong Java_org_rocksdb_Options_statisticsPtr(
/*
* Class: org_rocksdb_Options
* Method:
createBloom
Filter0
* Signature: (J
I
)V
* Method:
set
Filter0
* Signature: (J
J
)V
*/
void
Java_org_rocksdb_Options_createBloomFilter0
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
jhandle
,
jint
jbits_per_key
)
{
rocksdb
::
Options
*
opt
=
reinterpret_cast
<
rocksdb
::
Options
*>
(
jhandle
);
// Delete previously allocated pointer
if
(
opt
->
filter_policy
)
{
delete
opt
->
filter_policy
;
}
opt
->
filter_policy
=
rocksdb
::
NewBloomFilterPolicy
(
jbits_per_key
);
void
Java_org_rocksdb_Options_setFilter0
(
JNIEnv
*
env
,
jobject
jobj
,
jlong
jopt_handle
,
jlong
jfp_handle
)
{
reinterpret_cast
<
rocksdb
::
Options
*>
(
jopt_handle
)
->
filter_policy
=
reinterpret_cast
<
rocksdb
::
FilterPolicy
*>
(
jfp_handle
);
}
/*
...
...
java/rocksjni/portal.h
浏览文件 @
5e797cf0
...
...
@@ -12,6 +12,7 @@
#include <jni.h>
#include "rocksdb/db.h"
#include "rocksdb/filter_policy.h"
#include "utilities/backupable_db.h"
namespace
rocksdb
{
...
...
@@ -281,5 +282,38 @@ class IteratorJni {
reinterpret_cast
<
jlong
>
(
op
));
}
};
class
FilterJni
{
public:
// Get the java class id of org.rocksdb.Filter.
static
jclass
getJClass
(
JNIEnv
*
env
)
{
static
jclass
jclazz
=
env
->
FindClass
(
"org/rocksdb/Filter"
);
assert
(
jclazz
!=
nullptr
);
return
jclazz
;
}
// Get the field id of the member variable of org.rocksdb.Filter
// that stores the pointer to rocksdb::Iterator.
static
jfieldID
getHandleFieldID
(
JNIEnv
*
env
)
{
static
jfieldID
fid
=
env
->
GetFieldID
(
getJClass
(
env
),
"nativeHandle_"
,
"J"
);
assert
(
fid
!=
nullptr
);
return
fid
;
}
// Get the pointer to rocksdb::Filter.
static
rocksdb
::
FilterPolicy
*
getHandle
(
JNIEnv
*
env
,
jobject
jobj
)
{
return
reinterpret_cast
<
rocksdb
::
FilterPolicy
*>
(
env
->
GetLongField
(
jobj
,
getHandleFieldID
(
env
)));
}
// Pass the rocksdb::Filter pointer to the java side.
static
void
setHandle
(
JNIEnv
*
env
,
jobject
jobj
,
const
rocksdb
::
FilterPolicy
*
op
)
{
env
->
SetLongField
(
jobj
,
getHandleFieldID
(
env
),
reinterpret_cast
<
jlong
>
(
op
));
}
};
}
// namespace rocksdb
#endif // JAVA_ROCKSJNI_PORTAL_H_
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录