Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Commit

Permalink
add snapshot_request.go
Browse files Browse the repository at this point in the history
  • Loading branch information
xiang90 committed Jun 5, 2013
1 parent 842aa1a commit 718ef79
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions snapshot_request.go
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,
}
}

0 comments on commit 718ef79

Please sign in to comment.