LoginSignup
3
3

More than 5 years have passed since last update.

強い整合性

Last updated at Posted at 2013-12-19

この前の記事の通り、Riakは結果整合性(Eventual Consistency)にもとづき取り扱う。
これに加えてRiak2.0では、強い整合性(Strong Consistency)が設定可能になる予定だ。

Strong Consistency

2.0のriak.confには、以下の記述がある。

riak.conf
# Enable consensus subsystem (tech preview feature)
## Set to true to enable the consensus subsystem used for strongly
## consistent Riak operations.
## enable_consensus = true

このenable_consensus = trueをアンコメントして再起動すれば、強い整合性を設定可能になる。
Riak Meetup Tokyo #3でのスライドを引用して、実際に強い整合性を使ってみた。

riak.confを修正・再起動して設定を有効にした後、対象Bucketに強い整合性を設定する。

➜  riak git:(a12d5a2) ✗ rel/riak/bin/riak-admin bucket-type \
> create sc '{"props": {"consistent": true}}'
sc created
➜  riak git:(a12d5a2) ✗ rel/riak/bin/riak-admin bucket-type activate sc
sc has been activated

そうしたら、あとは実際にデータを投げてみる。

➜  riak git:(a12d5a2) ✗ curl -XPUT http://localhost:8098/types/sc/buckets/mybucket/keys/mykey -d "data1"
➜  riak git:(a12d5a2) ✗ curl -XPUT http://localhost:8098/types/sc/buckets/mybucket/keys/mykey -d "data2"
<html><head><title>412 Precondition Failed</title></head><body><h1>Precondition Failed</h1>Precondition Failed<p><hr><address>mochiweb+webmachine web server</address></body></html>

結果整合の時とは異なり、Siblingではなくエラーが返って来た。
書き込まれていない。
GETでVClockの値を読んで、それを使ってPUSHすれば、値の上書きができる。

➜  riak git:(a12d5a2) ✗ curl -v http://localhost:8098/types/sc/buckets/mybucket/keys/mykey
* Adding handle: conn: 0x7f84ab004000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7f84ab004000) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 8098 (#0)
*   Trying ::1...
*   Trying fe80::1...
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8098 (#0)
> GET /types/sc/buckets/mybucket/keys/mykey HTTP/1.1
> User-Agent: curl/7.30.0
> Host: localhost:8098
> Accept: */*
>
< HTTP/1.1 200 OK
< X-Riak-Vclock: a85hYGBgzGBKYWBJLU4tzGDKY2Vo4gUKAWlLLfUzfFkA
< Vary: Accept-Encoding
* Server MochiWeb/1.1 WebMachine/1.10.5 (jokes are better explained) is not blacklisted
< Server: MochiWeb/1.1 WebMachine/1.10.5 (jokes are better explained)
< Link: </buckets/mybucket>; rel="up"
< Last-Modified: Thu, 19 Dec 2013 08:28:41 GMT
< ETag: "7Xmuz8KIPEqAGDUJVstdqc"
< Date: Thu, 19 Dec 2013 08:30:49 GMT
< Content-Type: application/x-www-form-urlencoded
< Content-Length: 5
<
* Connection #0 to host localhost left intact
data1

➜  riak git:(a12d5a2) ✗ curl -XPUT http://localhost:8098/types/sc/buckets/mybucket/keys/mykey\
> -H 'X-Riak-Vclock: a85hYGBgzGBKYWBJLU4tzGDKY2Vo4gUKAWlLLfUzfFkA' -d "data3"

➜  riak git:(a12d5a2) ✗ curl -v http://localhost:8098/types/sc/buckets/mybucket/keys/mykey
data3

この設定はバケット毎にBucket Typeで行うので、同じRiakクラスタ内で、Bucket毎でデータの特性にあわせて整合性の使い分けが可能だ。

アプリケーションでSiblingの解決の手間が省けるので良いといえば良いのだが、現段階ではTeck Previewであるので、実用にはまだ検証が必要なのかもしれない。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3