From e57e4e9e7a04b47c0cf8fcc5bc7bfca83013a95a Mon Sep 17 00:00:00 2001 From: aminst Date: Mon, 23 Oct 2023 17:40:12 -0400 Subject: [PATCH] Remove snapshot from shardnode --- pkg/shardnode/raft.go | 117 +++--------------------------------------- 1 file changed, 6 insertions(+), 111 deletions(-) diff --git a/pkg/shardnode/raft.go b/pkg/shardnode/raft.go index 8c8af7d..9b48cc5 100644 --- a/pkg/shardnode/raft.go +++ b/pkg/shardnode/raft.go @@ -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) {