An Eventually Consistent Data Model For Erlang (and Riak)
CAP理论指出:一个分布式系统不可能同时满足一致性(Consistency)、可用性(Availibility)和分区容忍性(Partition Tolerance)这三个需求,最多只能同时满足其中的两个。在Riak强调的是Availibility和Partition Tolerance,它的Consistency是指eventually consistent,在一些concurrency的场合,你会发现你的data model会有inconsistent的情况出现,可以使用statebox去解决这个问题,下面用statebox_riak去实现博客互粉的功能:
statebox_riak的github地址:点击打开链接riakc_pb_socket:set_bucket(Pid, ?BUCKET, [{allow_mult, true}])
{ok, Pid} = riakc_pb_socket:start_link("127.0.0.1", 8087),
S = statebox_riak:new([{riakc_pb_socket, Pid}, {max_queue, 20}]),
statebox_riak:apply_bucket_ops(?BUCKET,
[
{[list_to_binary(FromId)], statebox_orddict:f_union(following, [list_to_binary(ToId)])},
{[list_to_binary(ToId)], statebox_orddict:f_union(followers, [list_to_binary(FromId)])}
], S),
riakc_pb_socket:stop(Pid).
更多信息可以看看这篇文章 点击打开链接
An Eventually Consistent Data Model For Erlang (and Riak)
CAP理论指出:一个分布式系统不可能同时满足一致性(Consistency)、可用性(Availibility)和分区容忍性(Partition Tolerance)这三个需求,最多只能同时满足其中的两个。在Riak强调的是Availibility和Partition Tolerance,它的Consistency是指eventually consistent,在一些concurrency的场合,你会发现你的data model会有inconsistent的情况出现,可以使用statebox去解决这个问题,下面用statebox_riak去实现博客互粉的功能:
statebox_riak的github地址:点击打开链接riakc_pb_socket:set_bucket(Pid, ?BUCKET, [{allow_mult, true}])
{ok, Pid} = riakc_pb_socket:start_link("127.0.0.1", 8087),
S = statebox_riak:new([{riakc_pb_socket, Pid}, {max_queue, 20}]),
statebox_riak:apply_bucket_ops(?BUCKET,
[
{[list_to_binary(FromId)], statebox_orddict:f_union(following, [list_to_binary(ToId)])},
{[list_to_binary(ToId)], statebox_orddict:f_union(followers, [list_to_binary(FromId)])}
], S),
riakc_pb_socket:stop(Pid).
更多信息可以看看这篇文章 点击打开链接