Skip to content

Commit

Permalink
feat: add some detail for store.go
Browse files Browse the repository at this point in the history
  • Loading branch information
sjcsjc123 committed Jul 9, 2023
1 parent e882bb9 commit f9307ed
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion cluster/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ package store

import (
"github.com/ByteStorage/FlyDB/cluster/region"
"github.com/hashicorp/raft"
"sync"
)

// The store component is responsible for managing the division and merging of region partitions.
// All regions under the store share a port number.
// Each region under the store is in a raftGroups, and the region clusters in the raftGroups communicate through grpc
// store stores the data of a store.
type store struct {
id uint64 // store id
id string // store id
addr string // store address
regionList map[uint64]*region.Region // region list, to store the regions in the store.
size int64 // size
mu sync.RWMutex // mutex, to protect the store.
raft *raft.Raft // raft, to store the raft group.
}

// Store is the interface of store.
Expand All @@ -31,3 +36,34 @@ type Store interface {
// GetSize gets the total size of the store.
GetSize() int64
}

// newRaftNode creates a new raft node for the store.
func (s *store) newRaftNode() error {
// All new methods below can add other return values as needed, such as err

// setup Raft configuration
config := s.newDefaultConfig()

// setup Raft communication
t := newTransport()

// create the snapshot store. This allows the Raft to truncate the log.
snapshots := newSnapshot()

// create the log store and stable store
logStore := newRaftLog()
stableStore := newStableLog()

// create a new finite state machine
f := newFSM()

// instantiate the Raft system
r, err := raft.NewRaft(config, f, logStore, stableStore, snapshots, t)
if err != nil {
return err
}

s.raft = r

return nil
}

0 comments on commit f9307ed

Please sign in to comment.