Skip to content

Commit

Permalink
fix: Search/Query may failed during updating delegator cache.
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Liu <[email protected]>
  • Loading branch information
weiliu1031 committed Oct 24, 2024
1 parent 8902e22 commit d81c067
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/proxy/meta_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,15 +996,6 @@ func (m *MetaCache) GetShards(ctx context.Context, withCache bool, database, col
idx: atomic.NewInt64(0),
}

// lock leader
m.leaderMut.Lock()
if _, ok := m.collLeader[database]; !ok {
m.collLeader[database] = make(map[string]*shardLeaders)
}

m.collLeader[database][collectionName] = newShardLeaders
m.leaderMut.Unlock()

iterator := newShardLeaders.GetReader()
ret := iterator.Shuffle()

Expand All @@ -1016,6 +1007,15 @@ func (m *MetaCache) GetShards(ctx context.Context, withCache bool, database, col
// and create new client for new leaders
_ = m.shardMgr.UpdateShardLeaders(oldLeaders, ret)

// lock leader, update client manager first, then update cache
m.leaderMut.Lock()
if _, ok := m.collLeader[database]; !ok {
m.collLeader[database] = make(map[string]*shardLeaders)
}

m.collLeader[database][collectionName] = newShardLeaders
m.leaderMut.Unlock()

metrics.ProxyUpdateCacheLatency.WithLabelValues(fmt.Sprint(paramtable.GetNodeID()), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
return ret, nil
}
Expand Down

0 comments on commit d81c067

Please sign in to comment.