Skip to content

Commit

Permalink
Remove snapshot from shardnode
Browse files Browse the repository at this point in the history
  • Loading branch information
aminst committed Oct 23, 2023
1 parent 36aa1f7 commit e57e4e9
Showing 1 changed file with 6 additions and 111 deletions.
117 changes: 6 additions & 111 deletions pkg/shardnode/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,123 +305,18 @@ func (fsm *shardNodeFSM) Apply(rLog *raft.Log) interface{} {
return nil
}

func (fsm *shardNodeFSM) Snapshot() (raft.FSMSnapshot, error) {
fsm.mu.Lock()
defer fsm.mu.Unlock()
shardNodeSnapshot := shardNodeSnapshot{}
type snapshotNoop struct{}

shardNodeSnapshot.RequestLog = make(map[string][]string)
for requestID, log := range fsm.requestLog {
shardNodeSnapshot.RequestLog[requestID] = append(shardNodeSnapshot.RequestLog[requestID], log...)
}
shardNodeSnapshot.PathMap = make(map[string]int)
for requestID, path := range fsm.pathMap {
shardNodeSnapshot.PathMap[requestID] = path
}
shardNodeSnapshot.StorageIDMap = make(map[string]int)
for requestID, storageID := range fsm.storageIDMap {
shardNodeSnapshot.StorageIDMap[requestID] = storageID
}
shardNodeSnapshot.ResponseMap = make(map[string]string)
for requestID, response := range fsm.responseMap {
shardNodeSnapshot.ResponseMap[requestID] = response
}
shardNodeSnapshot.Stash = make(map[string]stashState)
for block, value := range fsm.stash {
shardNodeSnapshot.Stash[block] = value
}

shardNodeSnapshot.Acks = make(map[string][]string)
for requestID, blocks := range fsm.acks {
shardNodeSnapshot.Acks[requestID] = append(shardNodeSnapshot.Acks[requestID], blocks...)
}
shardNodeSnapshot.Nacks = make(map[string][]string)
for requestID, blocks := range fsm.nacks {
shardNodeSnapshot.Nacks[requestID] = append(shardNodeSnapshot.Nacks[requestID], blocks...)
}
func (sn snapshotNoop) Persist(_ raft.SnapshotSink) error { return nil }
func (sn snapshotNoop) Release() {}

shardNodeSnapshot.PositionMap = make(map[string]positionState)
for block, pos := range fsm.positionMap {
shardNodeSnapshot.PositionMap[block] = pos
}

return shardNodeSnapshot, nil
func (fsm *shardNodeFSM) Snapshot() (raft.FSMSnapshot, error) {
return snapshotNoop{}, nil
}

func (fsm *shardNodeFSM) Restore(rc io.ReadCloser) error {
fsm.mu.Lock()
defer fsm.mu.Unlock()
b, err := io.ReadAll(rc)
if err != nil {
return fmt.Errorf("could not read snapshot from io.ReadCloser; %s", err)
}
var snapshot shardNodeSnapshot
err = msgpack.Unmarshal(b, &snapshot)
if err != nil {
return fmt.Errorf("could not unmarshal snapshot; %s", err)
}

fsm.requestLog = make(map[string][]string)
for requestID, log := range snapshot.RequestLog {
fsm.requestLog[requestID] = append(fsm.requestLog[requestID], log...)
}
fsm.pathMap = make(map[string]int)
for requestID, path := range snapshot.PathMap {
fsm.pathMap[requestID] = path
}
fsm.storageIDMap = make(map[string]int)
for requestID, storageID := range snapshot.StorageIDMap {
fsm.storageIDMap[requestID] = storageID
}
fsm.responseMap = make(map[string]string)
for requestID, response := range snapshot.ResponseMap {
fsm.responseMap[requestID] = response
}
fsm.stash = make(map[string]stashState)
for block, value := range snapshot.Stash {
fsm.stash[block] = value
}

fsm.acks = make(map[string][]string)
for requestID, blocks := range snapshot.Acks {
fsm.acks[requestID] = append(fsm.acks[requestID], blocks...)
}
fsm.nacks = make(map[string][]string)
for requestID, blocks := range snapshot.Nacks {
fsm.nacks[requestID] = append(fsm.nacks[requestID], blocks...)
}

fsm.positionMap = make(map[string]positionState)
for block, pos := range snapshot.PositionMap {
fsm.positionMap[block] = pos
}

return nil
}

type shardNodeSnapshot struct {
RequestLog map[string][]string
PathMap map[string]int
StorageIDMap map[string]int
ResponseMap map[string]string
Stash map[string]stashState
Acks map[string][]string
Nacks map[string][]string
PositionMap map[string]positionState
}

func (sn shardNodeSnapshot) Persist(sink raft.SnapshotSink) error {
b, err := msgpack.Marshal(sn)
if err != nil {
return fmt.Errorf("could not marshal snapshot for writing to disk; %s", err)
}
_, err = sink.Write(b)
if err != nil {
return fmt.Errorf("could not write marshalled snapshot to disk; %s", err)
}
return sink.Close()
return fmt.Errorf("not implemented yet")
}
func (sn shardNodeSnapshot) Release() {}

func startRaftServer(isFirst bool, ip string, replicaID int, raftPort int, raftDir string, shardshardNodeFSM *shardNodeFSM) (*raft.Raft, error) {

Expand Down

0 comments on commit e57e4e9

Please sign in to comment.