Repository navigation
feat: add the etcd raft port under ports/raft - #217
Merged
Merged
Conversation
Add raft v3.7.0 as a read-only submodule, a CMake build that links Eo from a sibling checkout and maps raft's module path to this tree, and tests that compare a Go program against its translation. Upstream: b867cf1 (go.etcd.io/raft/v3 v3.7.0) Eo: 5a600b2 (main) Assisted-by: Claude:claude-opus-5-5 Co-authored-by: Jeeyong Um <me@um.je>
The quorum package is translated from upstream, and so is a test program that runs quorum's datadriven tests in Go and in C++. - raft/quorum is the translation of quorum.go, joint.go, majority.go, and voteresult_string.go. - tests/datadriven is a copy of the parts of cockroachdb/datadriven v1.0.2 that read a test file and parse its directives, without testing.T, with its translation. - tests/quorum is quorum's datadriven_test.go as a program, with alternativeMajorityCommittedIndex from quick_test.go, and its translation. It runs the four files of quorum/testdata. Each directive's output matches the file in Go, and C++ prints the same as Go across all 127 directives. Five mutations of the translation were each caught: the quorum position, the vote threshold, the bar of equal indexes, the joint vote rule, and the infinite index's name. The formatter configurations are Eo's. Upstream: b867cf1 (go.etcd.io/raft/v3 v3.7.0) Eo: 04070ff (#181) Assisted-by: Claude:claude-opus-5-5 Co-authored-by: Jeeyong Um <me@um.je>
raftpb's messages come from raft.pb.go, which protoc-gen-go generated, so tools/gen_raftpb.py generates their C++ from it: the enums, the message structs and getters, and each message's size, append, unmarshal, merge, and equality functions in field-number order. The hand-written files, confchange.go, confstate.go, and util.go, are translated by hand, and alias.go's constants are resolved into the header. The runtime under them is shimmed from google.golang.org/protobuf v1.36.11. protowire is translated literally. proto and protoimpl are written from the fast path that Go takes for generated messages, so Marshal, Unmarshal, Size, Clone, and Equal match Go byte for byte: - field order, and nil against empty for pointers, bytes, and messages; - unknown fields and groups, kept and merged; - the recursion limit of 10000, and Go's error text. The build now defaults to RelWithDebInfo. A goroutine runs on a fixed 8 MB stack, and an unoptimized build overflows it before Unmarshal reaches the depth of 10000. tests/raftpb runs raftpb's TestLeaveJoint and TestConfState_Equivalent, edge cases of presence, nil, enums, depth, groups, field numbers, and unknown-field order, and 12000 random records from three seeds, through Go and C++. The outputs are identical. Of 19 mutations of the shim and the generated code, 4 survived the first round; each got a test, and all are now caught. Upstream: b867cf1 (go.etcd.io/raft/v3 v3.7.0) Eo: dce40c8 (#182) Assisted-by: Claude:claude-opus-5-5 Co-authored-by: Jeeyong Um <me@um.je>
The rules write a rune literal as its decimal value anywhere other than
as an operand of a C++ operator, so buf.WriteByte(' ') is
buf->WriteByte(32), not buf->WriteByte(' '). raftpb's
ConfChangesToString and the raftpb test's emit wrote the char. The
output is unchanged.
Upstream: b867cf1 (go.etcd.io/raft/v3 v3.7.0)
Eo: dce40c8 (#182)
Assisted-by: Claude:claude-opus-5-5
Co-authored-by: Jeeyong Um <me@um.je>
tracker's four files are translated by the rules: Inflights' ring buffer and its growth, Progress and its state machine, the ProgressTracker with its config, votes, and committed index, and StateType's names. Progress embeds *Inflights and ProgressTracker embeds Config, so the fields name their types through _eo_package, and the promoted methods are forwarders. Progress's updates of Next and sentCommit use the builtins min and max, which Eo maps since #183. tests/tracker ports progress_test.go and inflights_test.go, fixed ProgressTracker cases, and random sequences of Progress and tracker operations from fixed seeds, through Go and C++. The outputs are identical, including 39 panics with Go's messages. Of 39 mutations, 4 survived the first round. Two were gaps: a clone that shares its buffer, and pendingSnap in String; each got a test and is now caught. Two are equivalent: AckedIndex returning (0, true) for a missing ID, which CommittedIndex treats as 0 either way, and the size of the stack array that sorts IDs. Upstream: b867cf1 (go.etcd.io/raft/v3 v3.7.0) Eo: b2fd00b (#183) Assisted-by: Claude:claude-opus-5-5 Co-authored-by: Jeeyong Um <me@um.je>
confchange's two files are translated by the rules: the Changer, with value receivers, its simple and joint changes, the invariants it checks, and Restore, whose closures capture a loop-local copy of each change. initProgress uses the builtin max. tests/confchange ports datadriven_test.go over upstream's nine test files, quick_test.go and restore_test.go, whose testing/quick inputs come from a seeded generator with the same distributions, and adds cases for each error of checkInvariants and for a Restore that fails. datadriven gains TestData.ScanArgs and *bool destinations, which the test uses. The outputs of Go and C++ are identical. Of 30 mutations, 3 survived the first round. Two were gaps: an invariant that only a hand-built tracker reaches, and a Restore whose change fails; each got a test and is now caught. One is equivalent: LeaveJoint's cfg.AutoLeave = false, because Config.Clone does not copy AutoLeave, so the config that LeaveJoint starts from never has it. Upstream: b867cf1 (go.etcd.io/raft/v3 v3.7.0) Eo: b2fd00b (#183) Assisted-by: Claude:claude-opus-5-5 Co-authored-by: Jeeyong Um <me@um.je>
The raft package's files are translated by the rules, apart from node.go's Node, which waits for a context.Context mapping: node.cpp has only the Ready and SoftState helpers that RawNode uses. The tracker's Visit and QuorumActive become coroutines, because raft passes them closures that call coroutines, and the datadriven runner takes a coroutine callback for the same reason. tests/interaction runs upstream's interaction datadriven files through a translated InteractionEnv. tests/unit translates the package's _test.go files: util, types, storage, log, log_unstable, raft_flow_control, raft_snap, raft_paper, and raft. A hand-written test main runs them against go test's own binary, and their outputs are identical. Five tests are translated but not built, because they need diff_test.go's diffu, which runs diff -u through os/exec and temp files (#199). TestLeaderElectionInOneRoundRPC's raft log order on stderr depends on Go's map order, so only stdout is compared. testify's assert and require are a hand-written shim of the assertions the tests call. Local conventions for test files, which the rules do not cover yet (#198): the declarations go in package_test.h, test-file variables are set by eo_init_test, and the methods that test files declare on raft are declared in package.h. sort.Sort and slices.Concat are file-local stand-ins (#199). Mutations of raft, log, read_only, and tracker: 77 of 85 caught. Upstream's own tests miss each of the 8 survivors too: 3 are equivalent, 4 sit behind conditions that no test reaches, and 1 is caught only by tracker's tests, which the mutation script does not run. This builds against Eo with the PRs below and the still open #193, #194, #195, #196, and #197 (goexit, reflect.DeepEqual, testing.TB, anonymous struct placement, math/rand). Upstream: b867cf1 (go.etcd.io/raft/v3 v3.7.0) Eo: d92442c (#186) Eo: 501f793 (#187) Eo: a650a03 (#188) Eo: 53aad30 (#189) Eo: 343721d (#190) Eo: 621f13a (#191) Eo: e13615f (#192) Assisted-by: Claude:claude-opus-5-5 Co-authored-by: Jeeyong Um <me@um.je>
…h/rand The Eo pull requests that ed451e5 needed while they were open are now merged. The port builds against Eo main at 3bef2c8 without changes, and its seven tests pass there. Upstream: b867cf1 (go.etcd.io/raft/v3 v3.7.0) Eo: 92d3359 (#193) Eo: ac1e2c3 (#194) Eo: 3bef2c8 (#195) Eo: dd11486 (#196) Eo: 5cf9ccf (#197) Assisted-by: Claude:claude-opus-5-5 Co-authored-by: Jeeyong Um <me@um.je>
tests/cluster/node is a raft node, a RawNode on a MemoryStorage, that reads commands on its standard input; node/cpp is its translation. The cluster test, tests/cluster/main.go, starts a process for each node, routes their messages in protobuf's wire format, and drives them through seeded schedules: ticks, proposals, elections, leadership transfers, configuration changes, compaction and snapshots, and messages that are reordered, dropped, or duplicated, then delivers everything until the cluster settles. Elections never time out, so the schedule alone decides each run. Each schedule runs on all-Go, all-C++, and mixed assignments of 3 and 5 nodes, and every node must answer every command the same in each, with no two entries applied at one index and one settled state. All 94 mutations of the earlier mutation runs fail it, including the 8 that the unit tests miss. Upstream: b867cf1 (go.etcd.io/raft/v3 v3.7.0) Eo: 69f7d34 (#200) Assisted-by: Claude:claude-opus-5-5 Co-authored-by: Jeeyong Um <me@um.je>
A node stuck in a loop kept running after a timeout killed the coordinator, and stop waited for it forever. Start each node with a parent-death signal, and kill a node that has not exited 10 seconds after its input closes. Upstream: b867cf1 (go.etcd.io/raft/v3 v3.7.0) Eo: 69f7d34 (#200) Assisted-by: Claude:claude-opus-5-5 Co-authored-by: Jeeyong Um <me@um.je> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WKhFr4YH1YUGTnN1iSi9bQ
The cluster test replays one schedule in lockstep and compares answers. The chaos test runs the same nodes concurrently in real time instead: elections time out on raft's randomized timeouts, a ticker ticks every node, and a network delays, loses, and partitions messages, alongside proposals, leadership transfers, configuration changes, and compaction. Since each run differs, it checks properties: at most one leader per term, the same entry and state at every applied index, snapshots restoring that state, and, once the network heals, a leader that commits a new proposal with every node agreeing. The node takes an optional third argument, the election timeout in ticks. chaos-3 and chaos-5 run every assignment for 5 seconds each. Mutations of the C++ raft that cast two votes in a term, ignore whether the candidate's log is up to date, take leadership without a quorum, or accept appends without a term match are all caught. Committing an entry of an earlier term by counting replicas (Figure 8 of the Raft paper) is not, since it needs a rare interleaving; the cluster test catches it by comparing answers with Go. Upstream: b867cf1 (go.etcd.io/raft/v3 v3.7.0) Eo: 69f7d34 (#200) Assisted-by: Claude:claude-opus-5-5 Co-authored-by: Jeeyong Um <me@um.je> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WKhFr4YH1YUGTnN1iSi9bQ
node.go's Node, the node that runs a RawNode in a goroutine behind channels, is translated, with node_test.go and node_util_test.go. 20 of their 22 tests run and match go test; TestNodeProposeWaitDropped and TestNodeProposeAddLearnerNode need the String methods of raftpb.Message and ConfState, which the protobuf shim does not have yet. The methods that raft_test.go adds to raft were in raft's method table, which a conversion of node to Node now instantiates, so a program that is not a test failed to link. The unit tests now build package raft again, as raft_testing with RAFT_TESTING, which declares those methods, as go test builds a package with its test files. TestNodeProposeAddDuplicateNode logs each Ready, and how the node batches entries into Readys depends on scheduling: go test gave 5 different logs in 20 runs. Its log is dropped by normalization; its result is still compared. The other node tests gave identical output in 8 runs of each side. Of 12 mutations of node.cpp, 7 are caught. The 5 that survive (propc kept after the leader is lost, a Ready populated while one awaits Advance, rd kept after Advance, no filter of responses from unknown nodes, and stepWait returning before the result) also survive go test when applied to node.go, so raft's tests do not cover them. Upstream: b867cf1 (go.etcd.io/raft/v3 v3.7.0) Eo: 79bcc24 (#204) Assisted-by: Claude:claude-opus-5-5 Co-authored-by: Jeeyong Um <me@um.je> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WKhFr4YH1YUGTnN1iSi9bQ
Closing stopChaos did not stop a chaos loop that had already left its select, so it could still partition the network after settle healed it. The cut then stayed, and the cluster could not settle: chaos-3 failed once this way, with a learner that kept leading an old term. The loop now closes a channel when it returns, and settle waits for it. Upstream: b867cf1 (go.etcd.io/raft/v3 v3.7.0) Eo: 79bcc24 (#204) Assisted-by: Claude:claude-opus-5-5 Co-authored-by: Jeeyong Um <me@um.je> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WKhFr4YH1YUGTnN1iSi9bQ
Each generated message gets Go's String method, which writes the single-line text format of prototext as Export.MessageStringOf does: fields in declaration order, enums by name, Go's string escapes, and unknown fields and groups. The text encoder is in the protoimpl shim. Go adds a second space between fields when a hash of its binary is odd; the translation writes one, and the tests compare with one. The raftpb test checks String on edge cases and on every random message. TestNodeProposeWaitDropped and TestNodeProposeAddLearnerNode now run, so all 22 node tests match go test. The log of TestNodeProposeAddLearnerNode varies from run to run in Go too, so it is normalized away like TestNodeProposeAddDuplicateNode's. Also formats the node test files. Upstream: b867cf1 (go.etcd.io/raft/v3 v3.7.0) Eo: 79bcc24 (#204) Assisted-by: Claude:claude-opus-5-5 Co-authored-by: Jeeyong Um <me@um.je> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WKhFr4YH1YUGTnN1iSi9bQ
diffu writes two raft logs to temporary files and runs diff -u on them, through Eo's new os/exec and os.CreateTemp. TestLeaderSyncFollowerLog, TestCandidateConcede, TestOldMessages, TestProposal, and TestProposalByProxy now build and match go test. A failing diffu was checked against Go with a mutant on both sides, which print the same hunk. TestProposal and TestProposalByProxy log peers in the random order of Go's map iteration, so the unit test drops the peer ID from those lines. Upstream: b867cf1 (go.etcd.io/raft/v3 v3.7.0) Eo: cf90a45 (#205) Assisted-by: Claude:claude-opus-5-5 Co-authored-by: Jeeyong Um <me@um.je> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WKhFr4YH1YUGTnN1iSi9bQ
rawnode_test.go runs in the raft unit test, with TestRawNodeStart, whose local appenderStorage interface follows Eo's rule for interfaces declared inside a function. The benchmarks of rawnode_test.go and node_bench_test.go are registered, and run with -test.bench. ExampleNode has no Output comment, so go test only compiles it; it is compiled and not registered. The deferred n.Stop() calls on a raft.Node check the interface value with eo::nil_check. Eo: 441950f (#208), 4d37dba (#210), 6388b38 (#215) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WKhFr4YH1YUGTnN1iSi9bQ
Every remaining _test.go file is translated and compared with go test as unit-<package>: tracker, raftpb, quorum, confchange, and rafttest. Package rafttest's network.go and node.go are translated in raft/rafttest, and node.go's go n.Step(...) on the embedded raft.Node follows Eo's rule for go of an interface method call. quorum's and confchange's quick tests use testing/quick and seeded math/rand; TestConfChangeQuick declares a defined type inside the test function. TestProtoMemorySizes is translated but not run: it compares unsafe.Sizeof with Go's layout. The datadriven tests stay covered by tests/quorum, tests/confchange, and tests/interaction. The normalizer drops the logs of TestConfChangeQuick, whose quick source is seeded with the time, and sorts TestRawNodeStep's subtests, which range over a map. Eo: b96f08e (#212), 14c48e7 (#213), a0b0c66 (#214), 6388b38 (#215) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WKhFr4YH1YUGTnN1iSi9bQ
Brings in the history of the etcd raft v3.7.0 port, which was kept in its own repository until now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WKhFr4YH1YUGTnN1iSi9bQ
The port builds against the Eo of the repository that holds it, keeps raft's Apache License 2.0, and runs in the Raft workflow on main and on pull requests labeled ci:raft. The style check covers it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WKhFr4YH1YUGTnN1iSi9bQ
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brings the etcd raft v3.7.0 port into this repository as
ports/raft, with its history, so that 0.1.0 ships the port its release notes describe.ports/raftis added withgit subtree, so its 17 commits keep theirEo: <hash>trailers. This PR should be merged with a merge commit, not squashed, to keep them.EO_DIRnow defaults to the repository root, so the port builds against the Eo of the same commit. Eo's own build does not include it.upstream/raftsubmodule moves to the top-level.gitmodules, asports/raft/upstream/raft. Eo's Build workflow does not check out submodules and is unchanged.ports/raftcarries raft's Apache License 2.0 inports/raft/LICENSE. The README's Status section links the port and states its license.workflow_dispatch, and on pull requests labeledci:raft. A compile job takes up to about 4 GB (a local-j 4build peaked at 14.7 GB), so the workflow builds with-j 2on the 16 GB runner.portstoo.rawnode_test.cppwas the one file that needed formatting.Locally, the port at this branch builds and passes all 16 of its tests (
ctest, 45 s).🤖 Generated with Claude Code
https://claude.ai/code/session_01WKhFr4YH1YUGTnN1iSi9bQ