Created
July 19, 2023 08:17
-
-
Save palash25/397866ebfe1c15747aa820240eaf0fb5 to your computer and use it in GitHub Desktop.
gcounter challenge first pass deadlock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maelstrom test -w g-counter --bin ~/go/bin/gcounter --node-count 3 --rate 100 --time-limit 20 --nemesis partition | |
WARNING: abs already refers to: #'clojure.core/abs in namespace: clojure.core.matrix.impl.mathsops, being replaced by: #'clojure.core.matrix.impl.mathsops/abs | |
Warning: protocol #'clojure.core.matrix.protocols/PMathsFunctions is overwriting function abs | |
WARNING: abs already refers to: #'clojure.core/abs in namespace: clojure.core.matrix.protocols, being replaced by: #'clojure.core.matrix.protocols/abs | |
WARNING: abs already refers to: #'clojure.core/abs in namespace: clojure.core.matrix, being replaced by: #'clojure.core.matrix/abs | |
WARNING: abs already refers to: #'clojure.core/abs in namespace: clojure.core.matrix.dataset, being replaced by: #'clojure.core.matrix/abs | |
WARNING: abs already refers to: #'clojure.core/abs in namespace: incanter.core, being replaced by: #'incanter.core/abs | |
INFO [2023-07-19 13:44:38,857] main - jepsen.cli Test options: | |
{:args [], | |
:log-net-send false, | |
:node-count 3, | |
:availability nil, | |
:max-txn-length 4, | |
:concurrency 3, | |
:max-writes-per-key 16, | |
:leave-db-running? false, | |
:logging-json? false, | |
:nemesis-interval 10, | |
:log-stderr false, | |
:ssh | |
{:dummy? false, | |
:username "root", | |
:password "root", | |
:strict-host-key-checking false, | |
:private-key-path nil}, | |
:rate 100.0, | |
:argv | |
("test" | |
"-w" | |
"g-counter" | |
"--bin" | |
"/home/palash/go/bin/gcounter" | |
"--node-count" | |
"3" | |
"--rate" | |
"100" | |
"--time-limit" | |
"20" | |
"--nemesis" | |
"partition"), | |
:nemesis #{:partition}, | |
:nodes ["n0" "n1" "n2"], | |
:test-count 1, | |
:latency {:mean 0, :dist :constant}, | |
:bin "/home/palash/go/bin/gcounter", | |
:log-net-recv false, | |
:time-limit 20, | |
:workload :g-counter, | |
:consistency-models [:strict-serializable], | |
:topology :grid} | |
INFO [2023-07-19 13:44:38,881] jepsen test runner - jepsen.core Command line: | |
lein run test -w g-counter --bin /home/palash/go/bin/gcounter --node-count 3 --rate 100 --time-limit 20 --nemesis partition | |
INFO [2023-07-19 13:44:38,949] jepsen test runner - jepsen.core Running test: | |
{:args [] | |
:remote | |
#jepsen.control.retry.Remote{:remote #jepsen.control.scp.Remote{:cmd-remote #jepsen.control.sshj.SSHJRemote{:concurrency-limit 6, | |
:conn-spec nil, | |
:client nil, | |
:semaphore nil}, | |
:conn-spec nil}, | |
:conn nil} | |
:log-net-send false | |
:node-count 3 | |
:availability nil | |
:max-txn-length 4 | |
:concurrency 3 | |
:db | |
#object[maelstrom.db$db$reify__16142 | |
"0x3c634a04" | |
"maelstrom.db$db$reify__16142@3c634a04"] | |
:max-writes-per-key 16 | |
:leave-db-running? false | |
:name "g-counter" | |
:logging-json? false | |
:start-time | |
#object[org.joda.time.DateTime "0x10c26161" "2023-07-19T13:44:38.865+05:30"] | |
:nemesis-interval 10 | |
:net | |
#object[maelstrom.net$jepsen_net$reify__15251 | |
"0x1ef6977b" | |
"maelstrom.net$jepsen_net$reify__15251@1ef6977b"] | |
:client | |
#object[maelstrom.workload.pn_counter$client$reify__19540 | |
"0x674cd2da" | |
"maelstrom.workload.pn_counter$client$reify__19540@674cd2da"] | |
:barrier | |
#object[java.util.concurrent.CyclicBarrier | |
"0x686279e0" | |
"java.util.concurrent.CyclicBarrier@686279e0"] | |
:log-stderr false | |
:pure-generators true | |
:ssh {:dummy? true} | |
:rate 100.0 | |
:checker | |
#object[jepsen.checker$compose$reify__11881 | |
"0x6b28d4e4" | |
"jepsen.checker$compose$reify__11881@6b28d4e4"] | |
:argv | |
("test" | |
"-w" | |
"g-counter" | |
"--bin" | |
"/home/palash/go/bin/gcounter" | |
"--node-count" | |
"3" | |
"--rate" | |
"100" | |
"--time-limit" | |
"20" | |
"--nemesis" | |
"partition") | |
:nemesis | |
(jepsen.nemesis.ReflCompose | |
{:fm {:start-partition 0, | |
:stop-partition 0, | |
:kill 1, | |
:start 1, | |
:pause 1, | |
:resume 1}, | |
:nemeses [#unprintable "jepsen.nemesis.combined$partition_nemesis$reify__16416@41cfcbb5" | |
#unprintable "jepsen.nemesis.combined$db_nemesis$reify__16397@40941b54"]}) | |
:nodes ["n0" "n1" "n2"] | |
:test-count 1 | |
:latency {:mean 0, :dist :constant} | |
:bin "/home/palash/go/bin/gcounter" | |
:generator | |
((jepsen.generator.Synchronize | |
{:gen (jepsen.generator.TimeLimit | |
{:limit 20000000000, | |
:cutoff nil, | |
:gen (jepsen.generator.Any | |
{:gens [(jepsen.generator.OnThreads | |
{:f #{:nemesis}, | |
:context-filter #object[jepsen.generator.context$make_thread_filter$lazy_filter__9167 | |
"0xd15f98a" | |
"jepsen.generator.context$make_thread_filter$lazy_filter__9167@d15f98a"], | |
:gen (jepsen.generator.Stagger | |
{:dt 20000000000, | |
:next-time nil, | |
:gen (jepsen.generator.FlipFlop | |
{:gens [#object[jepsen.nemesis.combined$partition_package$start__16420 | |
"0x704c3ca2" | |
"jepsen.nemesis.combined$partition_package$start__16420@704c3ca2"] | |
({:type :info, | |
:f :stop-partition, | |
:value nil} | |
{:type :info, | |
:f :stop-partition, | |
:value nil} | |
{:type :info, | |
:f :stop-partition, | |
:value nil} | |
{:type :info, | |
:f :stop-partition, | |
:value nil} | |
{:type :info, | |
:f :stop-partition, | |
:value nil} | |
{:type :info, | |
:f :stop-partition, | |
:value nil} | |
{:type :info, | |
:f :stop-partition, | |
:value nil} | |
{:type :info, | |
:f :stop-partition, | |
:value nil} | |
...)], | |
:i 0})})}) | |
(jepsen.generator.OnThreads | |
{:f #jepsen.generator.context.AllBut{:element :nemesis}, | |
:context-filter #object[jepsen.generator.context$make_thread_filter$lazy_filter__9167 | |
"0x2a2f7a61" | |
"jepsen.generator.context$make_thread_filter$lazy_filter__9167@2a2f7a61"], | |
:gen (jepsen.generator.Stagger | |
{:dt 20000000, | |
:next-time nil, | |
:gen (jepsen.generator.Filter | |
{:f #object[maelstrom.workload.g_counter$workload$fn__19599 | |
"0x8d40f07" | |
"maelstrom.workload.g_counter$workload$fn__19599@8d40f07"], | |
:gen (jepsen.generator.Mix | |
{:i 0, | |
:gens [#object[maelstrom.workload.pn_counter$workload$fn__19572 | |
"0x196c8b93" | |
"maelstrom.workload.pn_counter$workload$fn__19572@196c8b93"] | |
({:f :read} | |
{:f :read} | |
{:f :read} | |
{:f :read} | |
{:f :read} | |
{:f :read} | |
{:f :read} | |
{:f :read} | |
...)]})})})})]})})}) | |
(jepsen.generator.Synchronize | |
{:gen (jepsen.generator.OnThreads | |
{:f #{:nemesis}, | |
:context-filter #object[jepsen.generator.context$make_thread_filter$lazy_filter__9167 | |
"0x307ca947" | |
"jepsen.generator.context$make_thread_filter$lazy_filter__9167@307ca947"], | |
:gen ({:type :info, :f :stop-partition, :value nil})})}) | |
(jepsen.generator.Synchronize | |
{:gen {:type :log, :value "Waiting for recovery..."}}) | |
(jepsen.generator.Synchronize {:gen {:type :sleep, :value 10}}) | |
(jepsen.generator.Synchronize | |
{:gen (jepsen.generator.OnThreads | |
{:f #jepsen.generator.context.AllBut{:element :nemesis}, | |
:context-filter #object[jepsen.generator.context$make_thread_filter$lazy_filter__9167 | |
"0x61d1315b" | |
"jepsen.generator.context$make_thread_filter$lazy_filter__9167@61d1315b"], | |
:gen (jepsen.generator.EachThread | |
{:fresh-gen {:f :read, :final? true}, | |
:context-filters #object[clojure.core$promise$reify__8591 | |
"0x49d5b651" | |
{:status :pending, :val nil}], | |
:gens {}})})})) | |
:log-net-recv false | |
:os | |
#object[maelstrom.net$jepsen_os$reify__15254 | |
"0x34989ceb" | |
"maelstrom.net$jepsen_os$reify__15254@34989ceb"] | |
:time-limit 20 | |
:workload :g-counter | |
:consistency-models [:strict-serializable] | |
:topology :grid} | |
INFO [2023-07-19 13:44:40,692] jepsen node n0 - maelstrom.net Starting Maelstrom network | |
INFO [2023-07-19 13:44:40,692] jepsen test runner - jepsen.db Tearing down DB | |
INFO [2023-07-19 13:44:40,694] jepsen test runner - jepsen.db Setting up DB | |
INFO [2023-07-19 13:44:40,694] jepsen node n2 - maelstrom.db Setting up n2 | |
INFO [2023-07-19 13:44:40,694] jepsen node n1 - maelstrom.db Setting up n1 | |
INFO [2023-07-19 13:44:40,695] jepsen node n1 - maelstrom.process launching /home/palash/go/bin/gcounter [] | |
INFO [2023-07-19 13:44:40,695] jepsen node n2 - maelstrom.process launching /home/palash/go/bin/gcounter [] | |
INFO [2023-07-19 13:44:40,696] jepsen node n0 - maelstrom.service Starting services: (lin-kv lin-tso lww-kv seq-kv) | |
INFO [2023-07-19 13:44:40,697] jepsen node n0 - maelstrom.db Setting up n0 | |
INFO [2023-07-19 13:44:40,698] jepsen node n0 - maelstrom.process launching /home/palash/go/bin/gcounter [] | |
WARN [2023-07-19 13:44:40,714] n0 stdout - maelstrom.process Error! | |
clojure.lang.ExceptionInfo: Malformed network message. Node n0 tried to send the following message via STDOUT: | |
{:dest "seq-kv", | |
:body | |
{:create_if_not_exists true, | |
:from 0, | |
:key "counter", | |
:msg_id 1, | |
:to 0, | |
:type "cas"}} | |
This is malformed because: | |
{:src missing-required-key} | |
See doc/protocol.md for more guidance. | |
at slingshot.support$stack_trace.invoke(support.clj:201) | |
at maelstrom.process$parse_msg.invokeStatic(process.clj:57) | |
at maelstrom.process$parse_msg.invoke(process.clj:35) | |
at maelstrom.process$stdout_thread$fn__15878$fn__15879$fn__15881.invoke(process.clj:146) | |
at maelstrom.process$stdout_thread$fn__15878$fn__15879.invoke(process.clj:146) | |
at maelstrom.process$stdout_thread$fn__15878.invoke(process.clj:140) | |
at clojure.core$binding_conveyor_fn$fn__5823.invoke(core.clj:2047) | |
at clojure.lang.AFn.call(AFn.java:18) | |
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317) | |
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) | |
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) | |
at java.base/java.lang.Thread.run(Thread.java:1589) | |
WARN [2023-07-19 13:44:40,715] n2 stdout - maelstrom.process Error! | |
clojure.lang.ExceptionInfo: Malformed network message. Node n2 tried to send the following message via STDOUT: | |
{:dest "seq-kv", | |
:body | |
{:create_if_not_exists true, | |
:from 0, | |
:key "counter", | |
:msg_id 1, | |
:to 0, | |
:type "cas"}} | |
This is malformed because: | |
{:src missing-required-key} | |
See doc/protocol.md for more guidance. | |
at slingshot.support$stack_trace.invoke(support.clj:201) | |
at maelstrom.process$parse_msg.invokeStatic(process.clj:57) | |
at maelstrom.process$parse_msg.invoke(process.clj:35) | |
at maelstrom.process$stdout_thread$fn__15878$fn__15879$fn__15881.invoke(process.clj:146) | |
at maelstrom.process$stdout_thread$fn__15878$fn__15879.invoke(process.clj:146) | |
at maelstrom.process$stdout_thread$fn__15878.invoke(process.clj:140) | |
at clojure.core$binding_conveyor_fn$fn__5823.invoke(core.clj:2047) | |
at clojure.lang.AFn.call(AFn.java:18) | |
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317) | |
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) | |
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) | |
at java.base/java.lang.Thread.run(Thread.java:1589) | |
WARN [2023-07-19 13:44:40,714] n1 stdout - maelstrom.process Error! | |
clojure.lang.ExceptionInfo: Malformed network message. Node n1 tried to send the following message via STDOUT: | |
{:dest "seq-kv", | |
:body | |
{:create_if_not_exists true, | |
:from 0, | |
:key "counter", | |
:msg_id 1, | |
:to 0, | |
:type "cas"}} | |
This is malformed because: | |
{:src missing-required-key} | |
See doc/protocol.md for more guidance. | |
at slingshot.support$stack_trace.invoke(support.clj:201) | |
at maelstrom.process$parse_msg.invokeStatic(process.clj:57) | |
at maelstrom.process$parse_msg.invoke(process.clj:35) | |
at maelstrom.process$stdout_thread$fn__15878$fn__15879$fn__15881.invoke(process.clj:146) | |
at maelstrom.process$stdout_thread$fn__15878$fn__15879.invoke(process.clj:146) | |
at maelstrom.process$stdout_thread$fn__15878.invoke(process.clj:140) | |
at clojure.core$binding_conveyor_fn$fn__5823.invoke(core.clj:2047) | |
at clojure.lang.AFn.call(AFn.java:18) | |
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317) | |
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) | |
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) | |
at java.base/java.lang.Thread.run(Thread.java:1589) | |
INFO [2023-07-19 13:44:50,714] jepsen node n2 - maelstrom.db Tearing down n2 | |
INFO [2023-07-19 13:44:50,714] jepsen node n1 - maelstrom.db Tearing down n1 | |
INFO [2023-07-19 13:44:50,714] jepsen node n0 - maelstrom.db Tearing down n0 | |
INFO [2023-07-19 13:44:51,718] jepsen node n0 - maelstrom.net Shutting down Maelstrom network | |
WARN [2023-07-19 13:44:51,720] jepsen test runner - jepsen.core Test crashed! | |
clojure.lang.ExceptionInfo: Node n0 crashed with exit status 2. Before crashing, it wrote to STDOUT: | |
And to STDERR: | |
2023/07/19 13:44:40 Sent {"dest":"seq-kv","body":{"create_if_not_exists":true,"from":0,"key":"counter","msg_id":1,"to":0,"type":"cas"}} | |
fatal error: all goroutines are asleep - deadlock! | |
goroutine 1 [select]: | |
github.com/jepsen-io/maelstrom/demo/go.(*Node).SyncRPC(0x4e1440?, {0x510cb8, 0xc0000180a8}, {0x4e9c98, 0x6}, {0x4e1440, 0xc00010e000}) | |
/home/palash/go/pkg/mod/github.com/jepsen-io/maelstrom/demo/[email protected]/node.go:271 +0x17d | |
github.com/jepsen-io/maelstrom/demo/go.(*KV).CompareAndSwap(0xc000010030, {0x510cb8, 0xc0000180a8}, {0x4e9e79?, 0x60?}, {0x4d2180?, 0x510168?}, {0x4d2180?, 0x510168?}, 0x1) | |
/home/palash/go/pkg/mod/github.com/jepsen-io/maelstrom/demo/[email protected]/kv.go:97 +0x112 | |
main.main() | |
/home/palash/dev/tuts/gossip-glomers/gcounter/main.go:16 +0x16d | |
Full STDERR logs are available in /home/palash/dev/tuts/gossip-glomers/gcounter/store/g-counter/20230719T134438.865+0530/node-logs/n0.log | |
at slingshot.support$stack_trace.invoke(support.clj:201) | |
at maelstrom.process$stop_node_BANG_.invokeStatic(process.clj:239) | |
at maelstrom.process$stop_node_BANG_.invoke(process.clj:217) | |
at maelstrom.db$db$reify__16142.teardown_BANG_(db.clj:75) | |
at jepsen.db$fn__8744$G__8725__8748.invoke(db.clj:12) | |
at jepsen.db$fn__8744$G__8724__8753.invoke(db.clj:12) | |
at clojure.core$partial$fn__5908.invoke(core.clj:2642) | |
at jepsen.control$on_nodes$fn__8599.invoke(control.clj:314) | |
at clojure.lang.AFn.applyToHelper(AFn.java:154) | |
at clojure.lang.AFn.applyTo(AFn.java:144) | |
at clojure.core$apply.invokeStatic(core.clj:667) | |
at clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1990) | |
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1990) | |
at clojure.lang.RestFn.applyTo(RestFn.java:142) | |
at clojure.core$apply.invokeStatic(core.clj:671) | |
at clojure.core$bound_fn_STAR_$fn__5818.doInvoke(core.clj:2020) | |
at clojure.lang.RestFn.invoke(RestFn.java:408) | |
at dom_top.core$real_pmap_helper$build_thread__211$fn__212.invoke(core.clj:163) | |
at clojure.lang.AFn.applyToHelper(AFn.java:152) | |
at clojure.lang.AFn.applyTo(AFn.java:144) | |
at clojure.core$apply.invokeStatic(core.clj:667) | |
at clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1990) | |
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1990) | |
at clojure.lang.RestFn.invoke(RestFn.java:425) | |
at clojure.lang.AFn.applyToHelper(AFn.java:156) | |
at clojure.lang.RestFn.applyTo(RestFn.java:132) | |
at clojure.core$apply.invokeStatic(core.clj:671) | |
at clojure.core$bound_fn_STAR_$fn__5818.doInvoke(core.clj:2020) | |
at clojure.lang.RestFn.invoke(RestFn.java:397) | |
at clojure.lang.AFn.run(AFn.java:22) | |
at java.base/java.lang.Thread.run(Thread.java:1589) | |
ERROR [2023-07-19 13:44:51,721] main - jepsen.cli Oh jeez, I'm sorry, Jepsen broke. Here's why: | |
clojure.lang.ExceptionInfo: Node n0 crashed with exit status 2. Before crashing, it wrote to STDOUT: | |
And to STDERR: | |
2023/07/19 13:44:40 Sent {"dest":"seq-kv","body":{"create_if_not_exists":true,"from":0,"key":"counter","msg_id":1,"to":0,"type":"cas"}} | |
fatal error: all goroutines are asleep - deadlock! | |
goroutine 1 [select]: | |
github.com/jepsen-io/maelstrom/demo/go.(*Node).SyncRPC(0x4e1440?, {0x510cb8, 0xc0000180a8}, {0x4e9c98, 0x6}, {0x4e1440, 0xc00010e000}) | |
/home/palash/go/pkg/mod/github.com/jepsen-io/maelstrom/demo/[email protected]/node.go:271 +0x17d | |
github.com/jepsen-io/maelstrom/demo/go.(*KV).CompareAndSwap(0xc000010030, {0x510cb8, 0xc0000180a8}, {0x4e9e79?, 0x60?}, {0x4d2180?, 0x510168?}, {0x4d2180?, 0x510168?}, 0x1) | |
/home/palash/go/pkg/mod/github.com/jepsen-io/maelstrom/demo/[email protected]/kv.go:97 +0x112 | |
main.main() | |
/home/palash/dev/tuts/gossip-glomers/gcounter/main.go:16 +0x16d | |
Full STDERR logs are available in /home/palash/dev/tuts/gossip-glomers/gcounter/store/g-counter/20230719T134438.865+0530/node-logs/n0.log | |
at slingshot.support$stack_trace.invoke(support.clj:201) | |
at maelstrom.process$stop_node_BANG_.invokeStatic(process.clj:239) | |
at maelstrom.process$stop_node_BANG_.invoke(process.clj:217) | |
at maelstrom.db$db$reify__16142.teardown_BANG_(db.clj:75) | |
at jepsen.db$fn__8744$G__8725__8748.invoke(db.clj:12) | |
at jepsen.db$fn__8744$G__8724__8753.invoke(db.clj:12) | |
at clojure.core$partial$fn__5908.invoke(core.clj:2642) | |
at jepsen.control$on_nodes$fn__8599.invoke(control.clj:314) | |
at clojure.lang.AFn.applyToHelper(AFn.java:154) | |
at clojure.lang.AFn.applyTo(AFn.java:144) | |
at clojure.core$apply.invokeStatic(core.clj:667) | |
at clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1990) | |
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1990) | |
at clojure.lang.RestFn.applyTo(RestFn.java:142) | |
at clojure.core$apply.invokeStatic(core.clj:671) | |
at clojure.core$bound_fn_STAR_$fn__5818.doInvoke(core.clj:2020) | |
at clojure.lang.RestFn.invoke(RestFn.java:408) | |
at dom_top.core$real_pmap_helper$build_thread__211$fn__212.invoke(core.clj:163) | |
at clojure.lang.AFn.applyToHelper(AFn.java:152) | |
at clojure.lang.AFn.applyTo(AFn.java:144) | |
at clojure.core$apply.invokeStatic(core.clj:667) | |
at clojure.core$with_bindings_STAR_.invokeStatic(core.clj:1990) | |
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1990) | |
at clojure.lang.RestFn.invoke(RestFn.java:425) | |
at clojure.lang.AFn.applyToHelper(AFn.java:156) | |
at clojure.lang.RestFn.applyTo(RestFn.java:132) | |
at clojure.core$apply.invokeStatic(core.clj:671) | |
at clojure.core$bound_fn_STAR_$fn__5818.doInvoke(core.clj:2020) | |
at clojure.lang.RestFn.invoke(RestFn.java:397) | |
at clojure.lang.AFn.run(AFn.java:22) | |
at java.base/java.lang.Thread.run(Thread.java:1589) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"encoding/json" | |
"log" | |
maelstrom "github.com/jepsen-io/maelstrom/demo/go" | |
) | |
func main() { | |
n := maelstrom.NewNode() | |
kv := maelstrom.NewSeqKV(n) | |
ctx := context.Background() | |
key := "counter" | |
err := kv.CompareAndSwap(ctx, key, 0, 0, true) | |
if err != nil { | |
log.Fatal(err) | |
} | |
n.Handle("add", func(msg maelstrom.Message) error { | |
var body map[string]any | |
err := json.Unmarshal(msg.Body, &body) | |
if err != nil { | |
return err | |
} | |
delta := body["delta"] | |
val, err := kv.ReadInt(ctx, key) | |
if err != nil { | |
return err | |
} | |
err = kv.Write(ctx, key, val+delta.(int)) | |
if err != nil { | |
return err | |
} | |
body["type"] = "add_ok" | |
return n.Reply(msg, body) | |
}) | |
n.Handle("read", func(msg maelstrom.Message) error { | |
var body map[string]any | |
err := json.Unmarshal(msg.Body, &body) | |
if err != nil { | |
return err | |
} | |
val, err := kv.ReadInt(ctx, key) | |
if err != nil { | |
return err | |
} | |
body["value"] = val | |
body["type"] = "read_ok" | |
return n.Reply(msg, body) | |
}) | |
if err := n.Run(); err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment