Skip to content

Commit

Permalink
introduce db lock for reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
moogacs committed May 16, 2024
1 parent ff3af72 commit 18af693
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cluster/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ type Store struct {

nodeID string
host string
dbLock sync.Mutex
db *localDB
log *logrus.Logger
logLevel string
Expand Down Expand Up @@ -918,14 +919,19 @@ func (st *Store) reloadDBFromSnapshot() bool {
}

func (st *Store) reloadDBFromSchema() {
st.dbLock.Lock()
defer st.dbLock.Unlock()

classes := st.db.Schema.MetaClasses()
st.log.Info("reload local db: update schema ...")
cs := make([]command.UpdateClassRequest, st.db.Schema.len())

cs := make([]command.UpdateClassRequest, len(classes))
i := 0
for _, v := range classes {
cs[i] = command.UpdateClassRequest{Class: &v.Class, State: &v.Sharding}
i++
}

st.log.Info("reload local db: update schema ...")
st.db.store.ReloadLocalDB(context.Background(), cs)
st.dbLoaded.Store(true)
st.lastAppliedIndexOnStart.Store(0)
Expand Down

0 comments on commit 18af693

Please sign in to comment.