mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-02-04 11:18:44 +08:00
This PR cherry-picks the following commits: - Implement task limit control logic in datanode. https://github.com/milvus-io/milvus/pull/32881 - Load bf from storage instead of memory during L0 compaction. https://github.com/milvus-io/milvus/pull/32913 - Remove dependencies on shards (e.g. SyncSegments, injection). https://github.com/milvus-io/milvus/pull/33138 - Rename Compaction interface to CompactionV2. https://github.com/milvus-io/milvus/pull/33858 - Remove the unused residual compaction logic. https://github.com/milvus-io/milvus/pull/33932 issue: https://github.com/milvus-io/milvus/issues/32809 pr: https://github.com/milvus-io/milvus/pull/32881, https://github.com/milvus-io/milvus/pull/32913, https://github.com/milvus-io/milvus/pull/33138, https://github.com/milvus-io/milvus/pull/33858, https://github.com/milvus-io/milvus/pull/33932 --------- Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package syncmgr
|
|
|
|
import (
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/msgpb"
|
|
"github.com/milvus-io/milvus/pkg/util/conc"
|
|
"github.com/milvus-io/milvus/pkg/util/lock"
|
|
)
|
|
|
|
//go:generate mockery --name=Task --structname=MockTask --output=./ --filename=mock_task.go --with-expecter --inpackage
|
|
type Task interface {
|
|
SegmentID() int64
|
|
Checkpoint() *msgpb.MsgPosition
|
|
StartPosition() *msgpb.MsgPosition
|
|
ChannelName() string
|
|
Run() error
|
|
HandleError(error)
|
|
}
|
|
|
|
type keyLockDispatcher[K comparable] struct {
|
|
keyLock *lock.KeyLock[K]
|
|
workerPool *conc.Pool[struct{}]
|
|
}
|
|
|
|
func newKeyLockDispatcher[K comparable](maxParallel int) *keyLockDispatcher[K] {
|
|
dispatcher := &keyLockDispatcher[K]{
|
|
workerPool: conc.NewPool[struct{}](maxParallel, conc.WithPreAlloc(false)),
|
|
keyLock: lock.NewKeyLock[K](),
|
|
}
|
|
return dispatcher
|
|
}
|
|
|
|
func (d *keyLockDispatcher[K]) Submit(key K, t Task, callbacks ...func(error) error) *conc.Future[struct{}] {
|
|
d.keyLock.Lock(key)
|
|
|
|
return d.workerPool.Submit(func() (struct{}, error) {
|
|
defer d.keyLock.Unlock(key)
|
|
err := t.Run()
|
|
|
|
for _, callback := range callbacks {
|
|
err = callback(err)
|
|
}
|
|
|
|
return struct{}{}, err
|
|
})
|
|
}
|