Refactor snapshot of timestamp statistics (#6600)

Signed-off-by: dragondriver <jiquan.long@zilliz.com>
pull/6600/merge
dragondriver 2021-07-17 16:31:29 +08:00 committed by GitHub
parent a7b27db63e
commit 0e2329c7ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 5 deletions

View File

@ -205,7 +205,7 @@ type DdTaskQueue struct {
type pChanStatInfo struct { type pChanStatInfo struct {
pChanStatistics pChanStatistics
refCnt int tsSet map[Timestamp]struct{}
} }
type DmTaskQueue struct { type DmTaskQueue struct {
@ -258,7 +258,9 @@ func (queue *DmTaskQueue) addPChanStats(t task) error {
if !ok { if !ok {
info = &pChanStatInfo{ info = &pChanStatInfo{
pChanStatistics: stat, pChanStatistics: stat,
refCnt: 1, tsSet: map[Timestamp]struct{}{
stat.minTs: {},
},
} }
queue.pChanStatisticsInfos[cName] = info queue.pChanStatisticsInfos[cName] = info
} else { } else {
@ -268,7 +270,7 @@ func (queue *DmTaskQueue) addPChanStats(t task) error {
if info.maxTs < stat.maxTs { if info.maxTs < stat.maxTs {
queue.pChanStatisticsInfos[cName].maxTs = stat.maxTs queue.pChanStatisticsInfos[cName].maxTs = stat.maxTs
} }
queue.pChanStatisticsInfos[cName].refCnt++ queue.pChanStatisticsInfos[cName].tsSet[info.minTs] = struct{}{}
} }
} }
queue.statsLock.Unlock() queue.statsLock.Unlock()
@ -288,9 +290,17 @@ func (queue *DmTaskQueue) popPChanStats(t task) error {
for _, cName := range channels { for _, cName := range channels {
info, ok := queue.pChanStatisticsInfos[cName] info, ok := queue.pChanStatisticsInfos[cName]
if ok { if ok {
info.refCnt-- delete(queue.pChanStatisticsInfos[cName].tsSet, info.minTs)
if info.refCnt <= 0 { if len(queue.pChanStatisticsInfos[cName].tsSet) <= 0 {
delete(queue.pChanStatisticsInfos, cName) delete(queue.pChanStatisticsInfos, cName)
} else if queue.pChanStatisticsInfos[cName].minTs == info.minTs {
minTs := info.maxTs
for ts := range queue.pChanStatisticsInfos[cName].tsSet {
if ts < minTs {
minTs = ts
}
}
queue.pChanStatisticsInfos[cName].minTs = minTs
} }
} }
} }