This repository has been archived by the owner on Sep 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package raft | ||
|
||
// The request sent to a server to start from the snapshot. | ||
type SnapshotRequest struct { | ||
LeaderName string `json:"leaderName"` | ||
LastIndex uint64 `json:"lastTerm"` | ||
LastTerm uint64 `json:"lastIndex"` | ||
MachineState int `json:"machineState"` | ||
} | ||
|
||
// The response returned from a server appending entries to the log. | ||
type SnapshotResponse struct { | ||
Term uint64 `json:"term"` | ||
Success bool `json:"success"` | ||
CommitIndex uint64 `json:"commitIndex"` | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
// | ||
// Constructors | ||
// | ||
//------------------------------------------------------------------------------ | ||
|
||
// Creates a new Snapshot request. | ||
func NewSnapshotRequest(leaderName string, snapshot *Snapshot) *SnapshotRequest { | ||
return &SnapshotRequest{ | ||
LeaderName: leaderName, | ||
LastIndex: snapshot.lastIndex, | ||
LastTerm: snapshot.lastTerm, | ||
MachineState: snapshot.machineState, | ||
} | ||
} | ||
|
||
// Creates a new Snapshot response. | ||
func NewSnapshotResponse(term uint64, success bool, commitIndex uint64) *SnapshotResponse { | ||
return &SnapshotResponse{ | ||
Term: term, | ||
Success: success, | ||
CommitIndex: commitIndex, | ||
} | ||
} |