fix collection not exist cause query coord panic (#20553)

Signed-off-by: Wei Liu <wei.liu@zilliz.com>

Signed-off-by: Wei Liu <wei.liu@zilliz.com>
pull/20566/head
wei liu 2022-11-14 14:51:06 +08:00 committed by GitHub
parent 44aed995ae
commit 6a2e458f90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 4 deletions

View File

@ -46,7 +46,6 @@ import (
"github.com/milvus-io/milvus/internal/querycoordv2/params"
"github.com/milvus-io/milvus/internal/querycoordv2/session"
"github.com/milvus-io/milvus/internal/querycoordv2/task"
"github.com/milvus-io/milvus/internal/querycoordv2/utils"
"github.com/milvus-io/milvus/internal/types"
"github.com/milvus-io/milvus/internal/util/dependency"
"github.com/milvus-io/milvus/internal/util/metricsinfo"
@ -515,9 +514,12 @@ func (s *Server) recover() error {
func (s *Server) recoverCollectionTargets(ctx context.Context, collection int64) error {
err := s.targetMgr.UpdateCollectionNextTarget(collection)
if err != nil {
msg := "failed to update next target for collection"
log.Error(msg, zap.Error(err))
return utils.WrapError(msg, err)
s.meta.CollectionManager.RemoveCollection(collection)
s.meta.ReplicaManager.RemoveCollection(collection)
log.Error("failed to recover collection due to update next target failed",
zap.Int64("collectionID", collection),
zap.Error(err),
)
}
return nil
}

View File

@ -18,6 +18,7 @@ package querycoordv2
import (
"context"
"errors"
"sync"
"testing"
"time"
@ -141,6 +142,26 @@ func (suite *ServerSuite) TestRecover() {
}
}
func (suite *ServerSuite) TestRecoverFailed() {
err := suite.server.Stop()
suite.NoError(err)
suite.server, err = newQueryCoord()
suite.NoError(err)
broker := meta.NewMockBroker(suite.T())
broker.EXPECT().GetPartitions(context.TODO(), int64(1000)).Return(nil, errors.New("CollectionNotExist"))
broker.EXPECT().GetRecoveryInfo(context.TODO(), int64(1001), mock.Anything).Return(nil, nil, errors.New("CollectionNotExist"))
suite.server.targetMgr = meta.NewTargetManager(broker, suite.server.meta)
err = suite.server.Start()
suite.NoError(err)
for _, collection := range suite.collections {
suite.False(suite.server.meta.Exist(collection))
suite.Nil(suite.server.targetMgr.GetDmChannelsByCollection(collection, meta.NextTarget))
}
}
func (suite *ServerSuite) TestNodeUp() {
newNode := mocks.NewMockQueryNode(suite.T(), suite.server.etcdCli, 100)
newNode.EXPECT().GetDataDistribution(mock.Anything, mock.Anything).Return(&querypb.GetDataDistributionResponse{}, nil)