forked from jepsen-io/maelstrom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlin_kv_proxy.rb
More file actions
executable file
·44 lines (34 loc) · 889 Bytes
/
lin_kv_proxy.rb
File metadata and controls
executable file
·44 lines (34 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/ruby
# A linearizable key-value store which works by proxying all requests to a
# Maelstrom-provided linearizable kv store.
require_relative 'node.rb'
class LinKVNode
def initialize
@node = Node.new
@node.on "read" do |msg|
proxy! msg
end
@node.on "write" do |msg|
proxy! msg
end
@node.on "cas" do |msg|
proxy! msg
end
end
# Takes a client request, proxies the body to lin_kv, and sends the response
# back to the client.
def proxy!(req_msg)
proxy_body = req_msg[:body].clone
proxy_body.delete :msg_id
# Replace with seq-kv or lww-kv to see linearization failures!
# @node.rpc! "seq-kv", proxy_body do |res|
@node.rpc! "lin-kv", proxy_body do |res|
res[:body].delete :msg_id
@node.reply! req_msg, res[:body]
end
end
def main!
@node.main!
end
end
LinKVNode.new.main!