如何向 Riak v2.0+ 添加复制挂钩

How to add a replication hook to Riak v2.0+

背景

Riak v2.0 更改了配置系统:

至:

问题

Multi-Data-Center-Replication-Hooks 中,Riak v2.0+ 文档仍然引用:

Add a -pa argument to your vm.args file to specify the path where your compiled .beam file lives:

Shell -pa /path/to/replication/hook Finally, add a -run argument to your vm.args file to register the hook:

Shell -run riak_repl_hook_sample register

-pa 和 -运行 参数的 riak.conf 或 advanced.config 版本是什么?


注意:我知道在文档中:Upgrading Your Configuration System我们可以:

Keep your configuration files from the older system, which are still recognized in Riak 2.0.

但我们想迁移到新的配置系统,因为它给了我们更多的可见性。

在您的 advanced.config 文件中,尝试这样的操作:

[
 {riak_kv, [
            {add_paths, ["/path/to/replication/hook"]}
           ]},
 {vm_args, [
            {'-run riak_repl_hook_sample register', ""}
           ]}
].

我知道启动一个应用程序是可行的,我正在使用这个:

[
 {riak_kv, [
            {add_paths, ["/path/to/my/beams/"]}
           ]},
 {vm_args, [
            {'-s my_app', ""}
           ]}
].

因此,只要稍作调整,您应该就能让它工作:)

可能的解决方案

注意:如果您想了解 riak.conf 设置如何映射到 vm.args,下面的文件非常有用,但是请注意,如果您不使用下面的文件设置你将在生成的 vm.args 文件中得到空白条目:

/var/lib/riak/generated.configs/vm..args

-pa
-run

用于配置的 Riak v2.0+ 模式文件

原来在 riak lib 目录中有一个很好的模式文件,可以扩展它以添加任何缺少的 erlang 标志,对我来说这是:

/usr/lib64/riak/lib/10-riak.schema

为此我添加了:

%% Add the replication hook directory to the code path 
{mapping, "repl.hook.path", "vm_args.-pa", [   
  {default, ""} 
]}.

%% Call Module:start/0 
{mapping, "repl.hook.run", "vm_args.-run", [
  {default, ""} 
]}.

然后我在riak.conf文件中添加:

# add the repl hook path and register it
repl.hook.path = /path/to/replication/hook
repl.hook.run = riak_repl_hook_sample register

之后我需要重新启动节点。