Skip to content

Commit

Permalink
fix: drop partition can not be successful if load failed[2.4] (#38871)
Browse files Browse the repository at this point in the history
related to #38649
pr: #38793
when partition load failed, the partition drop will also fail due to the
wrong error message

Signed-off-by: xiaofanluan <[email protected]>
  • Loading branch information
xiaofan-luan authored Jan 2, 2025
1 parent ef1b722 commit a3ea66f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion internal/proxy/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ func (t *dropPartitionTask) PreExecute(ctx context.Context) error {
return err
}
if collLoaded {
loaded, err := isPartitionLoaded(ctx, t.queryCoord, collID, []int64{partID})
loaded, err := isPartitionLoaded(ctx, t.queryCoord, collID, partID)
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions internal/proxy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import (
"github.com/milvus-io/milvus/pkg/util/commonpbutil"
"github.com/milvus-io/milvus/pkg/util/contextutil"
"github.com/milvus-io/milvus/pkg/util/crypto"
"github.com/milvus-io/milvus/pkg/util/funcutil"
"github.com/milvus-io/milvus/pkg/util/indexparamcheck"
"github.com/milvus-io/milvus/pkg/util/merr"
"github.com/milvus-io/milvus/pkg/util/metric"
Expand Down Expand Up @@ -1299,11 +1298,11 @@ func isCollectionLoaded(ctx context.Context, qc types.QueryCoordClient, collID i
return false, nil
}

func isPartitionLoaded(ctx context.Context, qc types.QueryCoordClient, collID int64, partIDs []int64) (bool, error) {
func isPartitionLoaded(ctx context.Context, qc types.QueryCoordClient, collID int64, partID int64) (bool, error) {
// get all loading collections
resp, err := qc.ShowPartitions(ctx, &querypb.ShowPartitionsRequest{
CollectionID: collID,
PartitionIDs: partIDs,
PartitionIDs: []int64{partID},
})
if err := merr.CheckRPCCall(resp, err); err != nil {
// qc returns error if partition not loaded
Expand All @@ -1313,7 +1312,7 @@ func isPartitionLoaded(ctx context.Context, qc types.QueryCoordClient, collID in
return false, err
}

return funcutil.SliceSetEqual(partIDs, resp.GetPartitionIDs()), nil
return true, nil
}

func checkFieldsDataBySchema(schema *schemapb.CollectionSchema, insertMsg *msgstream.InsertMsg, inInsert bool) error {
Expand Down
6 changes: 3 additions & 3 deletions internal/proxy/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ func Test_isPartitionIsLoaded(t *testing.T) {
Status: merr.Success(),
PartitionIDs: []int64{partID},
}, nil)
loaded, err := isPartitionLoaded(ctx, qc, collID, []int64{partID})
loaded, err := isPartitionLoaded(ctx, qc, collID, partID)
assert.NoError(t, err)
assert.True(t, loaded)
})
Expand All @@ -1088,7 +1088,7 @@ func Test_isPartitionIsLoaded(t *testing.T) {
Status: merr.Success(),
PartitionIDs: []int64{partID},
}, errors.New("error"))
loaded, err := isPartitionLoaded(ctx, qc, collID, []int64{partID})
loaded, err := isPartitionLoaded(ctx, qc, collID, partID)
assert.Error(t, err)
assert.False(t, loaded)
})
Expand Down Expand Up @@ -1116,7 +1116,7 @@ func Test_isPartitionIsLoaded(t *testing.T) {
},
PartitionIDs: []int64{partID},
}, nil)
loaded, err := isPartitionLoaded(ctx, qc, collID, []int64{partID})
loaded, err := isPartitionLoaded(ctx, qc, collID, partID)
assert.Error(t, err)
assert.False(t, loaded)
})
Expand Down
7 changes: 4 additions & 3 deletions internal/querycoordv2/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,16 @@ func (s *Server) ShowPartitions(ctx context.Context, req *querypb.ShowPartitions
if percentage < 0 {
err := meta.GlobalFailedLoadCache.Get(req.GetCollectionID())
if err != nil {
status := merr.Status(err)
log.Warn("show partition failed", zap.Error(err))
partitionErr := merr.WrapErrPartitionNotLoaded(partitionID, err.Error())
status := merr.Status(partitionErr)
log.Warn("show partition failed", zap.Error(partitionErr))
return &querypb.ShowPartitionsResponse{
Status: status,
}, nil
}

err = merr.WrapErrPartitionNotLoaded(partitionID)
log.Warn("show partitions failed", zap.Error(err))
log.Warn("show partition failed", zap.Error(err))
return &querypb.ShowPartitionsResponse{
Status: merr.Status(err),
}, nil
Expand Down
7 changes: 5 additions & 2 deletions internal/querycoordv2/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/cockroachdb/errors"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"

Expand Down Expand Up @@ -315,7 +316,8 @@ func (suite *ServiceSuite) TestShowPartitions() {
meta.GlobalFailedLoadCache.Put(collection, merr.WrapErrServiceMemoryLimitExceeded(100, 10))
resp, err = server.ShowPartitions(ctx, req)
suite.NoError(err)
suite.Equal(commonpb.ErrorCode_InsufficientMemoryToLoad, resp.GetStatus().GetErrorCode())
err := merr.CheckRPCCall(resp, err)
assert.True(suite.T(), errors.Is(err, merr.ErrPartitionNotLoaded))
meta.GlobalFailedLoadCache.Remove(collection)
err = suite.meta.CollectionManager.PutCollection(colBak)
suite.NoError(err)
Expand All @@ -327,7 +329,8 @@ func (suite *ServiceSuite) TestShowPartitions() {
meta.GlobalFailedLoadCache.Put(collection, merr.WrapErrServiceMemoryLimitExceeded(100, 10))
resp, err = server.ShowPartitions(ctx, req)
suite.NoError(err)
suite.Equal(commonpb.ErrorCode_InsufficientMemoryToLoad, resp.GetStatus().GetErrorCode())
err := merr.CheckRPCCall(resp, err)
assert.True(suite.T(), errors.Is(err, merr.ErrPartitionNotLoaded))
meta.GlobalFailedLoadCache.Remove(collection)
err = suite.meta.CollectionManager.PutPartition(parBak)
suite.NoError(err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/util/merr/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ func Code(err error) int32 {
}

cause := errors.Cause(err)
switch cause := cause.(type) {
switch specificErr := cause.(type) {
case milvusError:
return cause.code()
return specificErr.code()

default:
if errors.Is(cause, context.Canceled) {
if errors.Is(specificErr, context.Canceled) {
return CanceledCode
} else if errors.Is(cause, context.DeadlineExceeded) {
} else if errors.Is(specificErr, context.DeadlineExceeded) {
return TimeoutCode
} else {
return errUnexpected.code()
Expand Down

0 comments on commit a3ea66f

Please sign in to comment.