6.5840/src/raftapi/raftapi.go
Frans Kaashoek c8e7d779c2 update
2025-02-18 07:04:18 -05:00

41 lines
1.2 KiB
Go

package raftapi
// The Raft interface
type Raft interface {
// Start agreement on a new log entry, and return the log index
// for that entry, the term, and whether the peer is the leader.
Start(command interface{}) (int, int, bool)
// Ask a Raft for its current term, and whether it thinks it is
// leader
GetState() (int, bool)
// For Snaphots (3D)
Snapshot(index int, snapshot []byte)
PersistBytes() int
// For the tester to indicate to your code that is should cleanup
// any long-running go routines.
Kill()
}
// As each Raft peer becomes aware that successive log entries are
// committed, the peer should send an ApplyMsg to the service (or
// tester) on the same server, via the applyCh passed to Make(). set
// CommandValid to true to indicate that the ApplyMsg contains a newly
// committed log entry.
//
// In Lab 3 you'll want to send other kinds of messages (e.g.,
// snapshots) on the applyCh; at that point you can add fields to
// ApplyMsg, but set CommandValid to false for these other uses.
type ApplyMsg struct {
CommandValid bool
Command interface{}
CommandIndex int
SnapshotValid bool
Snapshot []byte
SnapshotTerm int
SnapshotIndex int
}