Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kvdb
rocksdb
提交
c46c2be8
R
rocksdb
项目概览
kvdb
/
rocksdb
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
c46c2be8
编写于
11月 17, 2014
作者:
Y
Yueh-Hsuan Chiang
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #397 from fyrz/RocksJava-GetIntProperty
[RocksJava] GetIntProperty in RocksDB
上级
db59eeb6
8efd4bb4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
142 addition
and
2 deletion
+142
-2
java/org/rocksdb/RocksDB.java
java/org/rocksdb/RocksDB.java
+60
-0
java/org/rocksdb/test/ColumnFamilyTest.java
java/org/rocksdb/test/ColumnFamilyTest.java
+2
-1
java/org/rocksdb/test/RocksDBTest.java
java/org/rocksdb/test/RocksDBTest.java
+33
-0
java/rocksjni/rocksjni.cc
java/rocksjni/rocksjni.cc
+47
-1
未找到文件。
java/org/rocksdb/RocksDB.java
浏览文件 @
c46c2be8
...
...
@@ -1032,6 +1032,62 @@ public class RocksDB extends RocksObject {
return
getProperty0
(
nativeHandle_
,
property
,
property
.
length
());
}
/**
* <p> Similar to GetProperty(), but only works for a subset of properties whose
* return value is a numerical value. Return the value as long.</p>
*
* <p><strong>Note</strong>: As the returned property is of type
* {@code uint64_t} on C++ side the returning value can be negative
* because Java supports in Java 7 only signed long values.</p>
*
* <p><strong>Java 7</strong>: To mitigate the problem of the non
* existent unsigned long tpye, values should be encapsulated using
* {@link java.math.BigInteger} to reflect the correct value. The correct
* behavior is guaranteed if {@code 2^64} is added to negative values.</p>
*
* <p><strong>Java 8</strong>: In Java 8 the value should be treated as
* unsigned long using provided methods of type {@link Long}.</p>
*
* @param property to be fetched.
*
* @return numerical property value.
*
* @throws RocksDBException if an error happens in the underlying native code.
*/
public
long
getLongProperty
(
String
property
)
throws
RocksDBException
{
return
getLongProperty
(
nativeHandle_
,
property
,
property
.
length
());
}
/**
* <p> Similar to GetProperty(), but only works for a subset of properties whose
* return value is a numerical value. Return the value as long.</p>
*
* <p><strong>Note</strong>: As the returned property is of type
* {@code uint64_t} on C++ side the returning value can be negative
* because Java supports in Java 7 only signed long values.</p>
*
* <p><strong>Java 7</strong>: To mitigate the problem of the non
* existent unsigned long tpye, values should be encapsulated using
* {@link java.math.BigInteger} to reflect the correct value. The correct
* behavior is guaranteed if {@code 2^64} is added to negative values.</p>
*
* <p><strong>Java 8</strong>: In Java 8 the value should be treated as
* unsigned long using provided methods of type {@link Long}.</p>
*
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
* instance
* @param property to be fetched.
*
* @return numerical property value
*
* @throws RocksDBException if an error happens in the underlying native code.
*/
public
long
getLongProperty
(
ColumnFamilyHandle
columnFamilyHandle
,
String
property
)
throws
RocksDBException
{
return
getLongProperty
(
nativeHandle_
,
columnFamilyHandle
.
nativeHandle_
,
property
,
property
.
length
());
}
/**
* Return a heap-allocated iterator over the contents of the database.
* The result of newIterator() is initially invalid (caller must
...
...
@@ -1297,6 +1353,10 @@ public class RocksDB extends RocksObject {
String
property
,
int
propertyLength
)
throws
RocksDBException
;
protected
native
String
getProperty0
(
long
nativeHandle
,
long
cfHandle
,
String
property
,
int
propertyLength
)
throws
RocksDBException
;
protected
native
long
getLongProperty
(
long
nativeHandle
,
String
property
,
int
propertyLength
)
throws
RocksDBException
;
protected
native
long
getLongProperty
(
long
nativeHandle
,
long
cfHandle
,
String
property
,
int
propertyLength
)
throws
RocksDBException
;
protected
native
long
iterator0
(
long
handle
);
protected
native
long
iterator0
(
long
handle
,
long
cfHandle
);
protected
native
long
[]
iterators
(
long
handle
,
...
...
java/org/rocksdb/test/ColumnFamilyTest.java
浏览文件 @
c46c2be8
...
...
@@ -351,7 +351,6 @@ public class ColumnFamilyTest {
}
}
@Test
public
void
properties
()
throws
RocksDBException
{
RocksDB
db
=
null
;
...
...
@@ -371,6 +370,8 @@ public class ColumnFamilyTest {
cfNames
,
columnFamilyHandleList
);
assertThat
(
db
.
getProperty
(
"rocksdb.estimate-num-keys"
)).
isNotNull
();
assertThat
(
db
.
getLongProperty
(
columnFamilyHandleList
.
get
(
0
),
"rocksdb.estimate-num-keys"
)).
isGreaterThanOrEqualTo
(
0
);
assertThat
(
db
.
getProperty
(
"rocksdb.stats"
)).
isNotNull
();
assertThat
(
db
.
getProperty
(
columnFamilyHandleList
.
get
(
0
),
"rocksdb.sstables"
)).
isNotNull
();
...
...
java/org/rocksdb/test/RocksDBTest.java
浏览文件 @
c46c2be8
...
...
@@ -279,4 +279,37 @@ public class RocksDBTest {
}
}
}
@Test
public
void
getIntProperty
()
throws
RocksDBException
{
RocksDB
db
=
null
;
Options
options
=
null
;
WriteOptions
wOpt
=
null
;
try
{
options
=
new
Options
();
wOpt
=
new
WriteOptions
();
// Setup options
options
.
setCreateIfMissing
(
true
);
options
.
setMaxWriteBufferNumber
(
10
);
options
.
setMinWriteBufferNumberToMerge
(
10
);
wOpt
.
setDisableWAL
(
true
);
db
=
RocksDB
.
open
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
db
.
put
(
wOpt
,
"key1"
.
getBytes
(),
"value1"
.
getBytes
());
db
.
put
(
wOpt
,
"key2"
.
getBytes
(),
"value2"
.
getBytes
());
db
.
put
(
wOpt
,
"key3"
.
getBytes
(),
"value3"
.
getBytes
());
db
.
put
(
wOpt
,
"key4"
.
getBytes
(),
"value4"
.
getBytes
());
assertThat
(
db
.
getLongProperty
(
"rocksdb.num-entries-active-mem-table"
)).
isGreaterThan
(
0
);
assertThat
(
db
.
getLongProperty
(
"rocksdb.cur-size-active-mem-table"
)).
isGreaterThan
(
0
);
}
finally
{
if
(
db
!=
null
)
{
db
.
close
();
}
if
(
options
!=
null
)
{
options
.
dispose
();
}
if
(
wOpt
!=
null
)
{
wOpt
.
dispose
();
}
}
}
}
java/rocksjni/rocksjni.cc
浏览文件 @
c46c2be8
...
...
@@ -1289,6 +1289,53 @@ jstring Java_org_rocksdb_RocksDB_getProperty0__JJLjava_lang_String_2I(
return
env
->
NewStringUTF
(
property_value
.
data
());
}
/*
* Class: org_rocksdb_RocksDB
* Method: getLongProperty
* Signature: (JLjava/lang/String;I)L;
*/
jlong
Java_org_rocksdb_RocksDB_getLongProperty__JLjava_lang_String_2I
(
JNIEnv
*
env
,
jobject
jdb
,
jlong
db_handle
,
jstring
jproperty
,
jint
jproperty_len
)
{
auto
db
=
reinterpret_cast
<
rocksdb
::
DB
*>
(
db_handle
);
const
char
*
property
=
env
->
GetStringUTFChars
(
jproperty
,
0
);
rocksdb
::
Slice
property_slice
(
property
,
jproperty_len
);
uint64_t
property_value
=
0
;
bool
retCode
=
db
->
GetIntProperty
(
property_slice
,
&
property_value
);
env
->
ReleaseStringUTFChars
(
jproperty
,
property
);
if
(
!
retCode
)
{
rocksdb
::
RocksDBExceptionJni
::
ThrowNew
(
env
,
rocksdb
::
Status
::
NotFound
());
}
return
property_value
;
}
/*
* Class: org_rocksdb_RocksDB
* Method: getLongProperty
* Signature: (JJLjava/lang/String;I)L;
*/
jlong
Java_org_rocksdb_RocksDB_getLongProperty__JJLjava_lang_String_2I
(
JNIEnv
*
env
,
jobject
jdb
,
jlong
db_handle
,
jlong
jcf_handle
,
jstring
jproperty
,
jint
jproperty_len
)
{
auto
db
=
reinterpret_cast
<
rocksdb
::
DB
*>
(
db_handle
);
auto
cf_handle
=
reinterpret_cast
<
rocksdb
::
ColumnFamilyHandle
*>
(
jcf_handle
);
const
char
*
property
=
env
->
GetStringUTFChars
(
jproperty
,
0
);
rocksdb
::
Slice
property_slice
(
property
,
jproperty_len
);
uint64_t
property_value
;
bool
retCode
=
db
->
GetIntProperty
(
cf_handle
,
property_slice
,
&
property_value
);
env
->
ReleaseStringUTFChars
(
jproperty
,
property
);
if
(
!
retCode
)
{
rocksdb
::
RocksDBExceptionJni
::
ThrowNew
(
env
,
rocksdb
::
Status
::
NotFound
());
}
return
property_value
;
}
//////////////////////////////////////////////////////////////////////////////
// rocksdb::DB::Flush
...
...
@@ -1332,4 +1379,3 @@ void Java_org_rocksdb_RocksDB_flush__JJJ(
auto
cf_handle
=
reinterpret_cast
<
rocksdb
::
ColumnFamilyHandle
*>
(
jcf_handle
);
rocksdb_flush_helper
(
env
,
db
,
*
flush_options
,
cf_handle
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录