2021-04-19 13:47:10 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
package querycoord
|
2021-04-15 15:15:46 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2021-04-15 15:15:46 +08:00
|
|
|
)
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
func (qc *QueryCoord) GetComponentStates(ctx context.Context) (*internalpb.ComponentStates, error) {
|
2021-04-15 15:15:46 +08:00
|
|
|
serviceComponentInfo := &internalpb.ComponentInfo{
|
2021-06-22 16:44:09 +08:00
|
|
|
NodeID: Params.QueryCoordID,
|
|
|
|
StateCode: qc.stateCode.Load().(internalpb.StateCode),
|
2021-04-15 15:15:46 +08:00
|
|
|
}
|
2021-06-19 11:45:09 +08:00
|
|
|
|
|
|
|
//subComponentInfos, err := qs.cluster.GetComponentInfos(ctx)
|
|
|
|
//if err != nil {
|
|
|
|
// return &internalpb.ComponentStates{
|
|
|
|
// Status: &commonpb.Status{
|
|
|
|
// ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
// Reason: err.Error(),
|
|
|
|
// },
|
|
|
|
// }, err
|
|
|
|
//}
|
2021-04-15 15:15:46 +08:00
|
|
|
return &internalpb.ComponentStates{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
},
|
2021-06-19 11:45:09 +08:00
|
|
|
State: serviceComponentInfo,
|
|
|
|
//SubcomponentStates: subComponentInfos,
|
2021-04-15 15:15:46 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
func (qc *QueryCoord) GetTimeTickChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
|
2021-04-15 15:15:46 +08:00
|
|
|
return &milvuspb.StringResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
},
|
|
|
|
Value: Params.TimeTickChannelName,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
func (qc *QueryCoord) GetStatisticsChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
|
2021-04-15 15:15:46 +08:00
|
|
|
return &milvuspb.StringResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
},
|
|
|
|
Value: Params.StatsChannelName,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
func (qc *QueryCoord) ShowCollections(ctx context.Context, req *querypb.ShowCollectionsRequest) (*querypb.ShowCollectionsResponse, error) {
|
2021-04-15 15:15:46 +08:00
|
|
|
dbID := req.DbID
|
2021-06-19 11:45:09 +08:00
|
|
|
log.Debug("show collection start", zap.Int64("dbID", dbID))
|
2021-06-24 16:00:15 +08:00
|
|
|
status := &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
}
|
|
|
|
if qc.stateCode.Load() != internalpb.StateCode_Healthy {
|
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
err := errors.New("query coordinator is not healthy")
|
|
|
|
status.Reason = err.Error()
|
|
|
|
log.Debug("show collection end with query coordinator not healthy")
|
|
|
|
return &querypb.ShowCollectionsResponse{
|
|
|
|
Status: status,
|
|
|
|
}, err
|
|
|
|
}
|
2021-06-22 16:44:09 +08:00
|
|
|
collectionIDs := qc.meta.showCollections()
|
2021-06-19 11:45:09 +08:00
|
|
|
log.Debug("show collection end", zap.Int64s("collections", collectionIDs))
|
2021-04-15 15:15:46 +08:00
|
|
|
return &querypb.ShowCollectionsResponse{
|
2021-06-24 16:00:15 +08:00
|
|
|
Status: status,
|
2021-04-15 15:15:46 +08:00
|
|
|
CollectionIDs: collectionIDs,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
func (qc *QueryCoord) LoadCollection(ctx context.Context, req *querypb.LoadCollectionRequest) (*commonpb.Status, error) {
|
2021-04-15 15:15:46 +08:00
|
|
|
collectionID := req.CollectionID
|
2021-06-19 11:45:09 +08:00
|
|
|
//schema := req.Schema
|
2021-04-15 15:15:46 +08:00
|
|
|
log.Debug("LoadCollectionRequest received", zap.String("role", Params.RoleName), zap.Int64("msgID", req.Base.MsgID), zap.Int64("collectionID", collectionID),
|
|
|
|
zap.Stringer("schema", req.Schema))
|
|
|
|
status := &commonpb.Status{
|
2021-06-23 17:44:12 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-04-15 15:15:46 +08:00
|
|
|
}
|
2021-06-24 16:00:15 +08:00
|
|
|
if qc.stateCode.Load() != internalpb.StateCode_Healthy {
|
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
err := errors.New("query coordinator is not healthy")
|
|
|
|
status.Reason = err.Error()
|
|
|
|
log.Debug("load collection end with query coordinator not healthy")
|
|
|
|
return status, err
|
|
|
|
}
|
2021-04-15 15:15:46 +08:00
|
|
|
|
|
|
|
loadCollectionTask := &LoadCollectionTask{
|
|
|
|
BaseTask: BaseTask{
|
2021-06-22 16:44:09 +08:00
|
|
|
ctx: qc.loopCtx,
|
|
|
|
Condition: NewTaskCondition(qc.loopCtx),
|
2021-06-15 12:41:40 +08:00
|
|
|
triggerCondition: querypb.TriggerCondition_grpcRequest,
|
2021-04-15 15:15:46 +08:00
|
|
|
},
|
|
|
|
LoadCollectionRequest: req,
|
2021-06-22 16:44:09 +08:00
|
|
|
rootCoord: qc.rootCoordClient,
|
|
|
|
dataCoord: qc.dataCoordClient,
|
|
|
|
cluster: qc.cluster,
|
|
|
|
meta: qc.meta,
|
2021-04-15 15:15:46 +08:00
|
|
|
}
|
2021-06-22 16:44:09 +08:00
|
|
|
qc.scheduler.Enqueue([]task{loadCollectionTask})
|
2021-04-15 15:15:46 +08:00
|
|
|
|
2021-06-21 19:20:31 +08:00
|
|
|
err := loadCollectionTask.WaitToFinish()
|
|
|
|
if err != nil {
|
2021-06-23 17:44:12 +08:00
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
2021-06-21 19:20:31 +08:00
|
|
|
status.Reason = err.Error()
|
|
|
|
return status, err
|
|
|
|
}
|
2021-04-15 15:15:46 +08:00
|
|
|
|
|
|
|
log.Debug("LoadCollectionRequest completed", zap.String("role", Params.RoleName), zap.Int64("msgID", req.Base.MsgID), zap.Int64("collectionID", collectionID))
|
|
|
|
return status, nil
|
|
|
|
}
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
func (qc *QueryCoord) ReleaseCollection(ctx context.Context, req *querypb.ReleaseCollectionRequest) (*commonpb.Status, error) {
|
2021-06-15 12:41:40 +08:00
|
|
|
//dbID := req.DbID
|
2021-04-15 15:15:46 +08:00
|
|
|
collectionID := req.CollectionID
|
|
|
|
log.Debug("ReleaseCollectionRequest received", zap.String("role", Params.RoleName), zap.Int64("msgID", req.Base.MsgID), zap.Int64("collectionID", collectionID))
|
|
|
|
status := &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
}
|
2021-06-24 16:00:15 +08:00
|
|
|
if qc.stateCode.Load() != internalpb.StateCode_Healthy {
|
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
err := errors.New("query coordinator is not healthy")
|
|
|
|
status.Reason = err.Error()
|
|
|
|
log.Debug("release collection end with query coordinator not healthy")
|
|
|
|
return status, err
|
|
|
|
}
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
hasCollection := qc.meta.hasCollection(collectionID)
|
2021-06-15 12:41:40 +08:00
|
|
|
if !hasCollection {
|
2021-06-23 17:44:12 +08:00
|
|
|
log.Warn("release collection end, query coordinator don't have the log of", zap.String("collectionID", fmt.Sprintln(collectionID)))
|
2021-04-15 15:15:46 +08:00
|
|
|
return status, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
releaseCollectionTask := &ReleaseCollectionTask{
|
|
|
|
BaseTask: BaseTask{
|
2021-06-22 16:44:09 +08:00
|
|
|
ctx: qc.loopCtx,
|
|
|
|
Condition: NewTaskCondition(qc.loopCtx),
|
2021-06-15 12:41:40 +08:00
|
|
|
triggerCondition: querypb.TriggerCondition_grpcRequest,
|
2021-04-15 15:15:46 +08:00
|
|
|
},
|
|
|
|
ReleaseCollectionRequest: req,
|
2021-06-22 16:44:09 +08:00
|
|
|
cluster: qc.cluster,
|
2021-04-15 15:15:46 +08:00
|
|
|
}
|
2021-06-22 16:44:09 +08:00
|
|
|
qc.scheduler.Enqueue([]task{releaseCollectionTask})
|
2021-06-15 12:41:40 +08:00
|
|
|
|
|
|
|
err := releaseCollectionTask.WaitToFinish()
|
2021-04-15 15:15:46 +08:00
|
|
|
if err != nil {
|
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
status.Reason = err.Error()
|
|
|
|
return status, err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("ReleaseCollectionRequest completed", zap.String("role", Params.RoleName), zap.Int64("msgID", req.Base.MsgID), zap.Int64("collectionID", collectionID))
|
2021-06-22 16:44:09 +08:00
|
|
|
qc.meta.printMeta()
|
|
|
|
qc.cluster.printMeta()
|
2021-04-15 15:15:46 +08:00
|
|
|
return status, nil
|
|
|
|
}
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
func (qc *QueryCoord) ShowPartitions(ctx context.Context, req *querypb.ShowPartitionsRequest) (*querypb.ShowPartitionsResponse, error) {
|
2021-04-15 15:15:46 +08:00
|
|
|
collectionID := req.CollectionID
|
2021-06-19 11:45:09 +08:00
|
|
|
log.Debug("show partitions start, ", zap.Int64("collectionID", collectionID))
|
2021-06-24 16:00:15 +08:00
|
|
|
status := &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
}
|
|
|
|
if qc.stateCode.Load() != internalpb.StateCode_Healthy {
|
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
err := errors.New("query coordinator is not healthy")
|
|
|
|
status.Reason = err.Error()
|
|
|
|
log.Debug("show partition end with query coordinator not healthy")
|
|
|
|
return &querypb.ShowPartitionsResponse{
|
|
|
|
Status: status,
|
|
|
|
}, err
|
|
|
|
}
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
partitionIDs, err := qc.meta.showPartitions(collectionID)
|
2021-04-15 15:15:46 +08:00
|
|
|
if err != nil {
|
2021-06-24 16:00:15 +08:00
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
status.Reason = err.Error()
|
2021-04-15 15:15:46 +08:00
|
|
|
return &querypb.ShowPartitionsResponse{
|
2021-06-24 16:00:15 +08:00
|
|
|
Status: status,
|
2021-04-15 15:15:46 +08:00
|
|
|
}, err
|
|
|
|
}
|
2021-06-15 12:41:40 +08:00
|
|
|
|
2021-06-19 11:45:09 +08:00
|
|
|
log.Debug("show partitions end", zap.Int64("collectionID", collectionID), zap.Int64s("partitionIDs", partitionIDs))
|
|
|
|
|
2021-04-15 15:15:46 +08:00
|
|
|
return &querypb.ShowPartitionsResponse{
|
2021-06-24 16:00:15 +08:00
|
|
|
Status: status,
|
2021-04-15 15:15:46 +08:00
|
|
|
PartitionIDs: partitionIDs,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
func (qc *QueryCoord) LoadPartitions(ctx context.Context, req *querypb.LoadPartitionsRequest) (*commonpb.Status, error) {
|
2021-04-15 15:15:46 +08:00
|
|
|
collectionID := req.CollectionID
|
|
|
|
partitionIDs := req.PartitionIDs
|
|
|
|
log.Debug("LoadPartitionRequest received", zap.String("role", Params.RoleName), zap.Int64("msgID", req.Base.MsgID), zap.Int64("collectionID", collectionID), zap.Int64s("partitionIDs", partitionIDs))
|
|
|
|
status := &commonpb.Status{
|
2021-06-23 17:44:12 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
2021-06-24 16:00:15 +08:00
|
|
|
if qc.stateCode.Load() != internalpb.StateCode_Healthy {
|
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
err := errors.New("query coordinator is not healthy")
|
|
|
|
status.Reason = err.Error()
|
|
|
|
log.Debug("load partition end with query coordinator not healthy")
|
|
|
|
return status, err
|
|
|
|
}
|
2021-04-15 15:15:46 +08:00
|
|
|
|
|
|
|
if len(partitionIDs) == 0 {
|
2021-06-23 17:44:12 +08:00
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
2021-04-15 15:15:46 +08:00
|
|
|
err := errors.New("partitionIDs are empty")
|
|
|
|
status.Reason = err.Error()
|
2021-06-23 17:44:12 +08:00
|
|
|
log.Debug("LoadPartitionRequest completed", zap.String("role", Params.RoleName), zap.Int64("msgID", req.Base.MsgID), zap.Int64("collectionID", req.CollectionID))
|
2021-06-15 12:41:40 +08:00
|
|
|
return status, err
|
2021-04-15 15:15:46 +08:00
|
|
|
}
|
|
|
|
|
2021-06-23 17:44:12 +08:00
|
|
|
hasCollection := qc.meta.hasCollection(collectionID)
|
|
|
|
if hasCollection {
|
|
|
|
partitionIDsToLoad := make([]UniqueID, 0)
|
|
|
|
loadCollection, _ := qc.meta.getLoadCollection(collectionID)
|
|
|
|
if loadCollection {
|
|
|
|
for _, partitionID := range partitionIDs {
|
|
|
|
hasReleasePartition := qc.meta.hasReleasePartition(collectionID, partitionID)
|
|
|
|
if hasReleasePartition {
|
|
|
|
partitionIDsToLoad = append(partitionIDsToLoad, partitionID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for _, partitionID := range partitionIDs {
|
|
|
|
hasPartition := qc.meta.hasPartition(collectionID, partitionID)
|
|
|
|
if !hasPartition {
|
|
|
|
partitionIDsToLoad = append(partitionIDsToLoad, partitionID)
|
|
|
|
}
|
|
|
|
}
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
|
|
|
|
2021-06-23 17:44:12 +08:00
|
|
|
if len(partitionIDsToLoad) == 0 {
|
|
|
|
log.Debug("LoadPartitionRequest completed", zap.String("role", Params.RoleName), zap.Int64("msgID", req.Base.MsgID), zap.Int64("collectionID", req.CollectionID))
|
|
|
|
return status, nil
|
2021-06-21 19:20:31 +08:00
|
|
|
}
|
2021-06-23 17:44:12 +08:00
|
|
|
req.PartitionIDs = partitionIDsToLoad
|
|
|
|
}
|
|
|
|
|
|
|
|
loadPartitionTask := &LoadPartitionTask{
|
|
|
|
BaseTask: BaseTask{
|
|
|
|
ctx: qc.loopCtx,
|
|
|
|
Condition: NewTaskCondition(qc.loopCtx),
|
|
|
|
triggerCondition: querypb.TriggerCondition_grpcRequest,
|
|
|
|
},
|
|
|
|
LoadPartitionsRequest: req,
|
|
|
|
dataCoord: qc.dataCoordClient,
|
|
|
|
cluster: qc.cluster,
|
|
|
|
meta: qc.meta,
|
|
|
|
}
|
|
|
|
qc.scheduler.Enqueue([]task{loadPartitionTask})
|
|
|
|
|
|
|
|
err := loadPartitionTask.WaitToFinish()
|
|
|
|
if err != nil {
|
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
status.Reason = err.Error()
|
|
|
|
log.Debug("LoadPartitionRequest completed", zap.String("role", Params.RoleName), zap.Int64("msgID", req.Base.MsgID), zap.Int64("collectionID", req.CollectionID))
|
|
|
|
return status, err
|
2021-06-19 11:45:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("LoadPartitionRequest completed", zap.String("role", Params.RoleName), zap.Int64("msgID", req.Base.MsgID), zap.Int64("collectionID", req.CollectionID))
|
2021-06-15 12:41:40 +08:00
|
|
|
return status, nil
|
2021-04-15 15:15:46 +08:00
|
|
|
}
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
func (qc *QueryCoord) ReleasePartitions(ctx context.Context, req *querypb.ReleasePartitionsRequest) (*commonpb.Status, error) {
|
2021-06-15 12:41:40 +08:00
|
|
|
//dbID := req.DbID
|
2021-04-15 15:15:46 +08:00
|
|
|
collectionID := req.CollectionID
|
|
|
|
partitionIDs := req.PartitionIDs
|
|
|
|
log.Debug("ReleasePartitionRequest received", zap.String("role", Params.RoleName), zap.Int64("msgID", req.Base.MsgID), zap.Int64("collectionID", req.CollectionID), zap.Int64s("partitionIDs", partitionIDs))
|
|
|
|
status := &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
}
|
2021-06-24 16:00:15 +08:00
|
|
|
if qc.stateCode.Load() != internalpb.StateCode_Healthy {
|
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
err := errors.New("query coordinator is not healthy")
|
|
|
|
status.Reason = err.Error()
|
|
|
|
log.Debug("release partition end with query coordinator not healthy")
|
|
|
|
return status, err
|
|
|
|
}
|
|
|
|
|
2021-06-23 17:44:12 +08:00
|
|
|
hasCollection := qc.meta.hasCollection(collectionID)
|
|
|
|
if !hasCollection {
|
|
|
|
log.Warn("release partitions end, query coordinator don't have the log of", zap.String("collectionID", fmt.Sprintln(collectionID)))
|
|
|
|
return status, nil
|
2021-04-15 15:15:46 +08:00
|
|
|
}
|
|
|
|
|
2021-06-23 17:44:12 +08:00
|
|
|
if len(partitionIDs) == 0 {
|
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
err := errors.New("partitionIDs are empty")
|
|
|
|
status.Reason = err.Error()
|
|
|
|
log.Debug("releasePartitionsRequest completed", zap.String("role", Params.RoleName), zap.Int64("msgID", req.Base.MsgID), zap.Int64("collectionID", req.CollectionID))
|
|
|
|
return status, err
|
|
|
|
}
|
2021-04-15 15:15:46 +08:00
|
|
|
|
2021-06-23 17:44:12 +08:00
|
|
|
releasePartitionTask := &ReleasePartitionTask{
|
|
|
|
BaseTask: BaseTask{
|
|
|
|
ctx: qc.loopCtx,
|
|
|
|
Condition: NewTaskCondition(qc.loopCtx),
|
|
|
|
triggerCondition: querypb.TriggerCondition_grpcRequest,
|
|
|
|
},
|
|
|
|
ReleasePartitionsRequest: req,
|
|
|
|
cluster: qc.cluster,
|
|
|
|
}
|
|
|
|
qc.scheduler.Enqueue([]task{releasePartitionTask})
|
|
|
|
|
|
|
|
err := releasePartitionTask.WaitToFinish()
|
|
|
|
if err != nil {
|
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
status.Reason = err.Error()
|
|
|
|
return status, err
|
2021-04-15 15:15:46 +08:00
|
|
|
}
|
|
|
|
log.Debug("ReleasePartitionRequest completed", zap.String("role", Params.RoleName), zap.Int64("msgID", req.Base.MsgID), zap.Int64("collectionID", collectionID), zap.Int64s("partitionIDs", partitionIDs))
|
2021-06-22 16:44:09 +08:00
|
|
|
qc.meta.printMeta()
|
|
|
|
qc.cluster.printMeta()
|
2021-04-15 15:15:46 +08:00
|
|
|
return status, nil
|
|
|
|
}
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
func (qc *QueryCoord) CreateQueryChannel(ctx context.Context, req *querypb.CreateQueryChannelRequest) (*querypb.CreateQueryChannelResponse, error) {
|
2021-06-24 16:00:15 +08:00
|
|
|
status := &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
}
|
|
|
|
if qc.stateCode.Load() != internalpb.StateCode_Healthy {
|
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
err := errors.New("query coordinator is not healthy")
|
|
|
|
status.Reason = err.Error()
|
|
|
|
log.Debug("createQueryChannel end with query coordinator not healthy")
|
|
|
|
return &querypb.CreateQueryChannelResponse{
|
|
|
|
Status: status,
|
|
|
|
}, err
|
|
|
|
}
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
collectionID := req.CollectionID
|
2021-06-22 16:44:09 +08:00
|
|
|
queryChannel, queryResultChannel := qc.meta.GetQueryChannel(collectionID)
|
2021-06-15 12:41:40 +08:00
|
|
|
|
|
|
|
return &querypb.CreateQueryChannelResponse{
|
2021-06-24 16:00:15 +08:00
|
|
|
Status: status,
|
2021-06-15 12:41:40 +08:00
|
|
|
RequestChannel: queryChannel,
|
|
|
|
ResultChannel: queryResultChannel,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
func (qc *QueryCoord) GetPartitionStates(ctx context.Context, req *querypb.GetPartitionStatesRequest) (*querypb.GetPartitionStatesResponse, error) {
|
2021-06-24 16:00:15 +08:00
|
|
|
status := &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
}
|
|
|
|
if qc.stateCode.Load() != internalpb.StateCode_Healthy {
|
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
err := errors.New("query coordinator is not healthy")
|
|
|
|
status.Reason = err.Error()
|
|
|
|
log.Debug("getPartitionStates end with query coordinator not healthy")
|
|
|
|
return &querypb.GetPartitionStatesResponse{
|
|
|
|
Status: status,
|
|
|
|
}, err
|
|
|
|
}
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
partitionIDs := req.PartitionIDs
|
|
|
|
partitionStates := make([]*querypb.PartitionStates, 0)
|
|
|
|
for _, partitionID := range partitionIDs {
|
2021-06-22 16:44:09 +08:00
|
|
|
state, err := qc.meta.getPartitionStateByID(partitionID)
|
2021-04-15 15:15:46 +08:00
|
|
|
if err != nil {
|
2021-06-24 16:00:15 +08:00
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
status.Reason = err.Error()
|
2021-06-15 12:41:40 +08:00
|
|
|
return &querypb.GetPartitionStatesResponse{
|
2021-06-24 16:00:15 +08:00
|
|
|
Status: status,
|
2021-04-15 15:15:46 +08:00
|
|
|
}, err
|
|
|
|
}
|
2021-06-15 12:41:40 +08:00
|
|
|
partitionState := &querypb.PartitionStates{
|
|
|
|
PartitionID: partitionID,
|
|
|
|
State: state,
|
|
|
|
}
|
|
|
|
partitionStates = append(partitionStates, partitionState)
|
2021-04-15 15:15:46 +08:00
|
|
|
}
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
return &querypb.GetPartitionStatesResponse{
|
2021-06-24 16:00:15 +08:00
|
|
|
Status: status,
|
2021-06-15 12:41:40 +08:00
|
|
|
PartitionDescriptions: partitionStates,
|
2021-04-15 15:15:46 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
func (qc *QueryCoord) GetSegmentInfo(ctx context.Context, req *querypb.GetSegmentInfoRequest) (*querypb.GetSegmentInfoResponse, error) {
|
2021-06-24 16:00:15 +08:00
|
|
|
status := &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
}
|
|
|
|
if qc.stateCode.Load() != internalpb.StateCode_Healthy {
|
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
err := errors.New("query coordinator is not healthy")
|
|
|
|
status.Reason = err.Error()
|
|
|
|
log.Debug("getSegmentInfo end with query coordinator not healthy")
|
|
|
|
return &querypb.GetSegmentInfoResponse{
|
|
|
|
Status: status,
|
|
|
|
}, err
|
|
|
|
}
|
|
|
|
|
2021-06-15 12:41:40 +08:00
|
|
|
totalMemSize := int64(0)
|
|
|
|
totalNumRows := int64(0)
|
|
|
|
//TODO::get segment infos from meta
|
|
|
|
//segmentIDs := req.SegmentIDs
|
|
|
|
//segmentInfos, err := qs.meta.getSegmentInfos(segmentIDs)
|
2021-06-22 16:44:09 +08:00
|
|
|
segmentInfos, err := qc.cluster.getSegmentInfo(ctx, req)
|
2021-04-15 15:15:46 +08:00
|
|
|
if err != nil {
|
2021-06-24 16:00:15 +08:00
|
|
|
status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
status.Reason = err.Error()
|
2021-06-15 12:41:40 +08:00
|
|
|
return &querypb.GetSegmentInfoResponse{
|
2021-06-24 16:00:15 +08:00
|
|
|
Status: status,
|
2021-04-15 15:15:46 +08:00
|
|
|
}, err
|
|
|
|
}
|
2021-06-15 12:41:40 +08:00
|
|
|
for _, info := range segmentInfos {
|
|
|
|
totalNumRows += info.NumRows
|
|
|
|
totalMemSize += info.MemSize
|
2021-04-15 15:15:46 +08:00
|
|
|
}
|
2021-06-15 12:41:40 +08:00
|
|
|
log.Debug("getSegmentInfo", zap.Int64("num rows", totalNumRows), zap.Int64("memory size", totalMemSize))
|
2021-04-15 15:15:46 +08:00
|
|
|
return &querypb.GetSegmentInfoResponse{
|
2021-06-24 16:00:15 +08:00
|
|
|
Status: status,
|
|
|
|
Infos: segmentInfos,
|
2021-04-15 15:15:46 +08:00
|
|
|
}, nil
|
|
|
|
}
|