From 29b3690c83cd65e50ca2fb127d676f0677093b46 Mon Sep 17 00:00:00 2001 From: smellthemoon <64083300+smellthemoon@users.noreply.github.com> Date: Mon, 6 Mar 2023 14:29:51 +0800 Subject: [PATCH] Upsert raise error (#22533) Signed-off-by: lixinguo Co-authored-by: lixinguo --- internal/proxy/impl.go | 5 +++++ internal/proxy/proxy_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/internal/proxy/impl.go b/internal/proxy/impl.go index 3ef72e8640..64849d4a8c 100644 --- a/internal/proxy/impl.go +++ b/internal/proxy/impl.go @@ -2341,6 +2341,11 @@ func (node *Proxy) Upsert(ctx context.Context, request *milvuspb.UpsertRequest) zap.Error(err)) metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc() + // Not every error case changes the status internally + // change status there to handle it + if it.result.Status.ErrorCode == commonpb.ErrorCode_Success { + it.result.Status.ErrorCode = commonpb.ErrorCode_UnexpectedError + } return constructFailedResponse(err, it.result.Status.ErrorCode), nil } diff --git a/internal/proxy/proxy_test.go b/internal/proxy/proxy_test.go index 505adb801a..6381309676 100644 --- a/internal/proxy/proxy_test.go +++ b/internal/proxy/proxy_test.go @@ -3333,6 +3333,21 @@ func TestProxy(t *testing.T) { } } + constructPartitionReqUpsertRequestInvalid := func() *milvuspb.UpsertRequest { + pkFieldData := newScalarFieldData(schema.Fields[0], int64Field, rowNum) + fVecColumn := newFloatVectorFieldData(floatVecField, rowNum, dim) + hashKeys := generateHashKeys(rowNum) + return &milvuspb.UpsertRequest{ + Base: nil, + DbName: dbName, + CollectionName: collectionName, + PartitionName: "%$@", + FieldsData: []*schemapb.FieldData{pkFieldData, fVecColumn}, + HashKeys: hashKeys, + NumRows: uint32(rowNum), + } + } + constructCollectionUpsertRequestValid := func() *milvuspb.UpsertRequest { pkFieldData := newScalarFieldData(schema.Fields[0], int64Field, rowNum) fVecColumn := newFloatVectorFieldData(floatVecField, rowNum, dim) @@ -3409,6 +3424,19 @@ func TestProxy(t *testing.T) { assert.Equal(t, int64(rowNum), resp.UpsertCnt) }) + wg.Add(1) + t.Run("upsert when occurs unexpected error like illegal partition name", func(t *testing.T) { + defer wg.Done() + req := constructPartitionReqUpsertRequestInvalid() + + resp, err := proxy.Upsert(ctx, req) + assert.NoError(t, err) + assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.Status.ErrorCode) + assert.Equal(t, 0, len(resp.SuccIndex)) + assert.Equal(t, rowNum, len(resp.ErrIndex)) + assert.Equal(t, int64(0), resp.UpsertCnt) + }) + wg.Add(1) t.Run("upsert when autoID == false", func(t *testing.T) { defer wg.Done()