Fix lock usage in DataCoord compaction (#26032)

See also: #26009

Signed-off-by: yangxuan <xuan.yang@zilliz.com>
pull/26046/head
XuanYang-cn 2023-08-01 08:55:04 +08:00 committed by GitHub
parent f615cc5404
commit 35f3e263cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -299,12 +299,13 @@ func (c *compactionPlanHandler) getCompaction(planID int64) *compactionTask {
// expireCompaction set the compaction state to expired
func (c *compactionPlanHandler) updateCompaction(ts Timestamp) error {
// Get executing tasks before GetCompactionState from DataNode to prevent false failure,
// for DC might add new task while GetCompactionState.
tasks := c.getExecutingCompactions()
planStates := c.sessions.GetCompactionState()
c.mu.Lock()
defer c.mu.Unlock()
tasks := c.getExecutingCompactions()
for _, task := range tasks {
stateResult, ok := planStates[task.plan.PlanID]
state := stateResult.GetState()
@ -381,6 +382,8 @@ func (c *compactionPlanHandler) isFull() bool {
}
func (c *compactionPlanHandler) getExecutingCompactions() []*compactionTask {
c.mu.RLock()
defer c.mu.RUnlock()
tasks := make([]*compactionTask, 0, len(c.plans))
for _, plan := range c.plans {
if plan.state == executing {