Hello! My friends and I are trying to work through the challenges at Challenge #2: Unique ID Generation · Fly Docs and we’re stuck on the second problem:
Code:
package main
import (
"log"
"github.com/google/uuid"
maelstrom "github.com/jepsen-io/maelstrom/demo/go"
)
func main() {
n := maelstrom.NewNode()
n.Handle("generate", func(msg maelstrom.Message) error {
var body map[string]any = make(map[string]any)
// if err := json.Unmarshal(msg.Body, &body); err != nil {
// return err
// }
id := uuid.New().String()
body["type"] = "generate_ok"
body["id"] = id
return n.Reply(msg, body)
})
if err := n.Run(); err != nil {
log.Fatal(err)
}
}
We’re getting this error:
WARN [2023-02-22 15:38:55,267] jepsen test runner - jepsen.core Test crashed!
clojure.lang.ExceptionInfo: Node n2 crashed with exit status 1. Before crashing, it wrote to STDOUT:
{"src":"n2","dest":"c1","body":{"in_reply_to":1,"type":"init_ok"}}
And to STDERR:
2023/02/22 15:38:24 Received {c1 n2 {"type":"init","node_id":"n2","node_ids":["n0","n1","n2"],"msg_id":1}}
2023/02/22 15:38:24 Node n2 initialized
2023/02/22 15:38:24 Sent {"src":"n2","dest":"c1","body":{"in_reply_to":1,"type":"init_ok"}}
2023/02/22 15:38:24 Received {c7 n2 {"type":"generate","msg_id":1}}
2023/02/22 15:38:24 No handler for {"id":8,"src":"c7","dest":"n2","body":{"type":"generate","msg_id":1}}
Full STDERR logs are available in /Users/bkane/Code/dist-sys/maelstrom/store/unique-ids/20230222T153822.085-0800/node-logs/n2.log
Tthe STDERR logs mentioned above contain:
2023/02/22 15:38:24 Received {c1 n2 {"type":"init","node_id":"n2","node_ids":["n0","n1","n2"],"msg_id":1}}
2023/02/22 15:38:24 Node n2 initialized
2023/02/22 15:38:24 Sent {"src":"n2","dest":"c1","body":{"in_reply_to":1,"type":"init_ok"}}
2023/02/22 15:38:24 Received {c7 n2 {"type":"generate","msg_id":1}}
2023/02/22 15:38:24 No handler for {"id":8,"src":"c7","dest":"n2","body":{"type":"generate","msg_id":1}}
However, when we run the code locally and type in the JSON, we get the expected response:
$ go run .
{"id":8,"src":"c7","dest":"n2","body":{"type":"generate","msg_id":1}}
2023/02/22 15:54:55 Received {c7 n2 {"type":"generate","msg_id":1}}
2023/02/22 15:54:55 Sent {"dest":"c7","body":{"id":"95fd3289-550e-467f-9f6d-0c55d76142b8","in_reply_to":1,"type":"generate_ok"}}
{"dest":"c7","body":{"id":"95fd3289-550e-467f-9f6d-0c55d76142b8","in_reply_to":1,"type":"generate_ok"}}
Is there somethng obvious we’re doing incorrectly? We’re new to both distributed systems and Go. Thank you!