From 2cba5053a8b4b7911094324a9823d32f2f0ff25f Mon Sep 17 00:00:00 2001 From: groot Date: Mon, 11 Oct 2021 19:00:46 +0800 Subject: [PATCH] Add comment for QueryCoordComponent (#9648) Signed-off-by: yhmo --- .../distributed/querycoord/service_test.go | 6 +++-- internal/querycoord/query_coord.go | 15 +++++++++++-- internal/types/types.go | 22 ++++++++++++++----- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/internal/distributed/querycoord/service_test.go b/internal/distributed/querycoord/service_test.go index 57b0614e63..b56d862a39 100644 --- a/internal/distributed/querycoord/service_test.go +++ b/internal/distributed/querycoord/service_test.go @@ -66,10 +66,12 @@ func (m *MockQueryCoord) Register() error { func (m *MockQueryCoord) UpdateStateCode(code internalpb.StateCode) { } -func (m *MockQueryCoord) SetRootCoord(types.RootCoord) { +func (m *MockQueryCoord) SetRootCoord(types.RootCoord) error { + return nil } -func (m *MockQueryCoord) SetDataCoord(types.DataCoord) { +func (m *MockQueryCoord) SetDataCoord(types.DataCoord) error { + return nil } func (m *MockQueryCoord) GetComponentStates(ctx context.Context) (*internalpb.ComponentStates, error) { diff --git a/internal/querycoord/query_coord.go b/internal/querycoord/query_coord.go index e4c1f093b4..9a0d65bd4e 100644 --- a/internal/querycoord/query_coord.go +++ b/internal/querycoord/query_coord.go @@ -13,6 +13,7 @@ package querycoord import ( "context" + "errors" "math/rand" "path/filepath" "strconv" @@ -194,13 +195,23 @@ func NewQueryCoord(ctx context.Context, factory msgstream.Factory) (*QueryCoord, } // SetRootCoord sets root coordinator's client -func (qc *QueryCoord) SetRootCoord(rootCoord types.RootCoord) { +func (qc *QueryCoord) SetRootCoord(rootCoord types.RootCoord) error { + if rootCoord == nil { + return errors.New("null root coordinator interface") + } + qc.rootCoordClient = rootCoord + return nil } // SetDataCoord sets data coordinator's client -func (qc *QueryCoord) SetDataCoord(dataCoord types.DataCoord) { +func (qc *QueryCoord) SetDataCoord(dataCoord types.DataCoord) error { + if dataCoord == nil { + return errors.New("null data coordinator interface") + } + qc.dataCoordClient = dataCoord + return nil } func (qc *QueryCoord) watchNodeLoop() { diff --git a/internal/types/types.go b/internal/types/types.go index c503dfbf58..0a9bf94c29 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -539,7 +539,7 @@ type QueryNodeComponent interface { // UpdateStateCode updates state code for QueryNode // `stateCode` is current statement of this query node, indicating whether it's healthy. - UpdateStateCode(code internalpb.StateCode) + UpdateStateCode(stateCode internalpb.StateCode) // SetRootCoord set RootCoord for QueryNode // `rootCoord` is a client of root coordinator. Pass to segmentLoader. @@ -583,12 +583,24 @@ type QueryCoordComponent interface { QueryCoord // UpdateStateCode updates state code for QueryCoord - // State includes: Initializing, Healthy and Abnormal - UpdateStateCode(internalpb.StateCode) + // `stateCode` is current statement of this query coord, indicating whether it's healthy. + UpdateStateCode(stateCode internalpb.StateCode) // SetDataCoord set DataCoord for QueryCoord - SetDataCoord(DataCoord) + // `dataCoord` is a client of data coordinator. + // + // Return a generic error in status: + // If the dataCoord is nil. + // Return nil in status: + // The dataCoord is not nil. + SetDataCoord(dataCoord DataCoord) error // SetRootCoord set RootCoord for QueryCoord - SetRootCoord(RootCoord) + // `rootCoord` is a client of root coordinator. + // + // Return a generic error in status: + // If the rootCoord is nil. + // Return nil in status: + // The rootCoord is not nil. + SetRootCoord(rootCoord RootCoord) error }