mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-04 04:49:08 +08:00
78155d3959
Signed-off-by: xige-16 <xi.ge@zilliz.com>
97 lines
2.3 KiB
Go
97 lines
2.3 KiB
Go
package queryservice
|
|
|
|
import (
|
|
"context"
|
|
"math/rand"
|
|
"sync"
|
|
"sync/atomic"
|
|
"time"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/log"
|
|
"github.com/zilliztech/milvus-distributed/internal/msgstream"
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb"
|
|
"github.com/zilliztech/milvus-distributed/internal/types"
|
|
"github.com/zilliztech/milvus-distributed/internal/util/typeutil"
|
|
)
|
|
|
|
type Timestamp = typeutil.Timestamp
|
|
|
|
type queryChannelInfo struct {
|
|
requestChannel string
|
|
responseChannel string
|
|
}
|
|
|
|
type QueryService struct {
|
|
loopCtx context.Context
|
|
loopCancel context.CancelFunc
|
|
|
|
queryServiceID uint64
|
|
replica Replica
|
|
sched *TaskScheduler
|
|
|
|
dataServiceClient types.DataService
|
|
masterServiceClient types.MasterService
|
|
queryNodes map[int64]*queryNodeInfo
|
|
queryChannels []*queryChannelInfo
|
|
qcMutex *sync.Mutex
|
|
|
|
stateCode atomic.Value
|
|
isInit atomic.Value
|
|
enableGrpc bool
|
|
|
|
msFactory msgstream.Factory
|
|
}
|
|
|
|
func (qs *QueryService) Init() error {
|
|
return nil
|
|
}
|
|
|
|
func (qs *QueryService) Start() error {
|
|
qs.sched.Start()
|
|
log.Debug("start scheduler ...")
|
|
qs.UpdateStateCode(internalpb.StateCode_Healthy)
|
|
return nil
|
|
}
|
|
|
|
func (qs *QueryService) Stop() error {
|
|
qs.sched.Close()
|
|
log.Debug("close scheduler ...")
|
|
qs.loopCancel()
|
|
qs.UpdateStateCode(internalpb.StateCode_Abnormal)
|
|
return nil
|
|
}
|
|
|
|
func (qs *QueryService) UpdateStateCode(code internalpb.StateCode) {
|
|
qs.stateCode.Store(code)
|
|
}
|
|
|
|
func NewQueryService(ctx context.Context, factory msgstream.Factory) (*QueryService, error) {
|
|
rand.Seed(time.Now().UnixNano())
|
|
nodes := make(map[int64]*queryNodeInfo)
|
|
queryChannels := make([]*queryChannelInfo, 0)
|
|
ctx1, cancel := context.WithCancel(ctx)
|
|
replica := newMetaReplica()
|
|
scheduler := NewTaskScheduler(ctx1)
|
|
service := &QueryService{
|
|
loopCtx: ctx1,
|
|
loopCancel: cancel,
|
|
replica: replica,
|
|
sched: scheduler,
|
|
queryNodes: nodes,
|
|
queryChannels: queryChannels,
|
|
qcMutex: &sync.Mutex{},
|
|
msFactory: factory,
|
|
}
|
|
|
|
service.UpdateStateCode(internalpb.StateCode_Abnormal)
|
|
return service, nil
|
|
}
|
|
|
|
func (qs *QueryService) SetMasterService(masterService types.MasterService) {
|
|
qs.masterServiceClient = masterService
|
|
}
|
|
|
|
func (qs *QueryService) SetDataService(dataService types.DataService) {
|
|
qs.dataServiceClient = dataService
|
|
}
|