Streaming replication framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

98 lines
2.2 KiB

package replication
import "time"
type WALEntry struct {
WALID uint64
Data []byte
}
type App interface {
EncodeCmd(cmd interface{}, entry WALEntry) WALEntry
DecodeCmd(entry WALEntry) (cmd interface{})
Apply(cmds []interface{}) (responseCodes []uint16)
ClearState() error
IterState() (cmdChan chan interface{})
}
type Manager interface {
Apply(cmd interface{}) (responseCode uint16, err error)
ReportFailed(format string, args ...interface{})
}
type Storage interface {
Address() (string, error)
SetAddress(addr string) error
Role() uint64
SetRole(role uint64) error
LeaderID() uint64
SetLeaderID(id uint64) error
FollowerAddress() (string, error)
SetFollowerAddress(addr string) error
// WriteWAL returns the new max wal ID.
WriteWAL(entries []WALEntry) error
// Update the max applied WAL ID.
SetMaxAppliedWAL(id uint64) error
MaxAppliedWAL() (uint64, error)
// The max stored WAL ID.
MaxWAL() (uint64, error)
// The min stored WAL ID.
MinWAL() (uint64, error)
// Remove WAL entries.
ClearWAL() error
TruncateWALBeforeID(id uint64) error
TruncateWALBeforeTime(time.Time) error
}
type Follower interface {
Connect(leaderID uint64, address string) error
MaxAppliedWAL() (id int64, err error)
ClearState(leaderID uint64) (err error)
ApplyState(leaderID uint64, entries []WALEntry) (err error)
ApplyWAL(leaderID uint64, entries []WALEntry) (respCodes []uint16, err error)
}
const (
NodeRoleUnknown = 0
NodeRoleLeader = 1
NodeRoleFollower = 2
NodeRoleForwarder = 3
)
const (
FollowerStateError = -1
FollowerStateNone = 0 // No follower.
FollowerStateNotConnected = 1
FollowerStateSyncingState = 2
FollowerStateSyncingLog = 3
FollowerStateSynchronous = 4
)
type NodeStatus struct {
Address string
Role int8
LeaderID uint64
MaxWAL uint64
MinWAL uint64
MaxAppliedWAL uint64
Follower string
FolowerState int8
}
// Node as seen by the supervisor.
type Node interface {
Status() (NodeStatus, error)
SetRole(nodeRole int8, leaderID uint64) error
SetLeader(address string) error // Empty address => no leader.
SetFollower(address string) error // Empty address => no follower.
Stop() error
}