Skip to content

Commit

Permalink
Change push index from async to sync
Browse files Browse the repository at this point in the history
  • Loading branch information
710leo committed Jun 29, 2020
1 parent 982fc6a commit 3c1ed52
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/modules/tsdb/index/update_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,10 @@ import (
"github.com/didi/nightingale/src/modules/tsdb/backend/rpc"
"github.com/didi/nightingale/src/toolkits/stats"

"github.com/toolkits/pkg/concurrent/semaphore"
"github.com/toolkits/pkg/logger"
)

var (
semaUpdateIndexAll *semaphore.Semaphore
)

func StartUpdateIndexTask() {
if rpc.Config.MaxConns != 0 {
semaUpdateIndexAll = semaphore.NewSemaphore(rpc.Config.MaxConns / 2)
} else {
semaUpdateIndexAll = semaphore.NewSemaphore(10)
}

t1 := time.NewTicker(time.Duration(Config.RebuildInterval) * time.Second)
for {
Expand Down Expand Up @@ -73,22 +63,13 @@ func RebuildAllIndex(params ...[]string) error {
i = i + 1

if i == aggrNum {
semaUpdateIndexAll.Acquire()
go func(items []*dataobj.TsdbItem) {
defer semaUpdateIndexAll.Release()
rpc.Push2Index(rpc.ALLINDEX, items, addrs)
}(tmpList)

rpc.Push2Index(rpc.ALLINDEX, tmpList, addrs)
i = 0
}
}

if i != 0 {
semaUpdateIndexAll.Acquire()
go func(items []*dataobj.TsdbItem) {
defer semaUpdateIndexAll.Release()
rpc.Push2Index(rpc.ALLINDEX, items, addrs)
}(tmpList[:i])
rpc.Push2Index(rpc.ALLINDEX, tmpList[:i], addrs)
}
}

Expand Down

0 comments on commit 3c1ed52

Please sign in to comment.