Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kvdb
rocksdb
提交
ce2b1f7b
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,发现更多精彩内容 >>
提交
ce2b1f7b
编写于
2月 23, 2014
作者:
T
Thomas Adam
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added a test case for custom merge operator
上级
68248a2a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
60 addition
and
1 deletion
+60
-1
db/c_test.c
db/c_test.c
+60
-1
未找到文件。
db/c_test.c
浏览文件 @
ce2b1f7b
...
...
@@ -154,6 +154,37 @@ unsigned char FilterKeyMatch(
return
fake_filter_result
;
}
// Custom merge operator
static
void
MergeOperatorDestroy
(
void
*
arg
)
{
}
static
const
char
*
MergeOperatorName
(
void
*
arg
)
{
return
"TestMergeOperator"
;
}
static
char
*
MergeOperatorFullMerge
(
void
*
arg
,
const
char
*
key
,
size_t
key_length
,
const
char
*
existing_value
,
size_t
existing_value_length
,
const
char
*
const
*
operands_list
,
const
size_t
*
operands_list_length
,
int
num_operands
,
unsigned
char
*
success
,
size_t
*
new_value_length
)
{
*
new_value_length
=
4
;
*
success
=
1
;
char
*
result
=
malloc
(
4
);
memcpy
(
result
,
"fake"
,
4
);
return
result
;
}
static
char
*
MergeOperatorPartialMerge
(
void
*
arg
,
const
char
*
key
,
size_t
key_length
,
const
char
*
left_operand
,
size_t
left_operand_length
,
const
char
*
right_operand
,
size_t
right_operand_length
,
unsigned
char
*
success
,
size_t
*
new_value_length
)
{
*
new_value_length
=
4
;
*
success
=
1
;
char
*
result
=
malloc
(
4
);
memcpy
(
result
,
"fake"
,
4
);
return
result
;
}
int
main
(
int
argc
,
char
**
argv
)
{
rocksdb_t
*
db
;
rocksdb_comparator_t
*
cmp
;
...
...
@@ -342,7 +373,7 @@ int main(int argc, char** argv) {
rocksdb_filterpolicy_t
*
policy
;
if
(
run
==
0
)
{
policy
=
rocksdb_filterpolicy_create
(
NULL
,
FilterDestroy
,
FilterCreate
,
FilterKeyMatch
,
FilterName
);
NULL
,
FilterDestroy
,
FilterCreate
,
FilterKeyMatch
,
NULL
,
FilterName
);
}
else
{
policy
=
rocksdb_filterpolicy_create_bloom
(
10
);
}
...
...
@@ -376,6 +407,34 @@ int main(int argc, char** argv) {
rocksdb_filterpolicy_destroy
(
policy
);
}
StartPhase
(
"merge_operator"
);
{
rocksdb_mergeoperator_t
*
merge_operator
;
merge_operator
=
rocksdb_mergeoperator_create
(
NULL
,
MergeOperatorDestroy
,
MergeOperatorFullMerge
,
MergeOperatorPartialMerge
,
NULL
,
MergeOperatorName
);
// Create new database
rocksdb_close
(
db
);
rocksdb_destroy_db
(
options
,
dbname
,
&
err
);
rocksdb_options_set_merger_operator
(
options
,
merge_operator
);
db
=
rocksdb_open
(
options
,
dbname
,
&
err
);
CheckNoError
(
err
);
rocksdb_put
(
db
,
woptions
,
"foo"
,
3
,
"foovalue"
,
8
,
&
err
);
CheckNoError
(
err
);
CheckGet
(
db
,
roptions
,
"foo"
,
"foovalue"
);
rocksdb_merge
(
db
,
woptions
,
"foo"
,
3
,
"barvalue"
,
8
,
&
err
);
CheckNoError
(
err
);
CheckGet
(
db
,
roptions
,
"foo"
,
"fake"
);
// Merge of a non-existing value
rocksdb_merge
(
db
,
woptions
,
"bar"
,
3
,
"barvalue"
,
8
,
&
err
);
CheckNoError
(
err
);
CheckGet
(
db
,
roptions
,
"bar"
,
"fake"
);
rocksdb_options_set_merger_operator
(
options
,
NULL
);
rocksdb_mergeoperator_destroy
(
merge_operator
);
}
StartPhase
(
"cleanup"
);
rocksdb_close
(
db
);
rocksdb_options_destroy
(
options
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录