From e09f4318912e5798adaceaff3504001f21ba5c68 Mon Sep 17 00:00:00 2001 From: wei liu Date: Tue, 3 Dec 2024 10:36:38 +0800 Subject: [PATCH] fix: grant ManualCompact api doesn't work (#38096) issue: #38086 cause ManualCompact api pass collection id in request, but RBAC requires to check collection name, so grant ManualCompact api doesn't work. This PR refine the ManualCompact api to accpet collection name in request. Signed-off-by: Wei Liu --- go.mod | 2 +- go.sum | 4 ++++ internal/proxy/database_interceptor.go | 5 +++++ internal/proxy/database_interceptor_test.go | 2 +- internal/proxy/impl.go | 11 +++++++++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index dfd33944502ac..2d269939bcb5d 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 github.com/klauspost/compress v1.17.9 github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d - github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20241120015424-93892e628c69 + github.com/milvus-io/milvus-proto/go-api/v2 v2.5.0-beta.0.20241129033252-5d0b09587056 github.com/minio/minio-go/v7 v7.0.73 github.com/pingcap/log v1.1.1-0.20221015072633-39906604fb81 github.com/prometheus/client_golang v1.14.0 diff --git a/go.sum b/go.sum index 5ce59aedb4722..afc6f6f6fbcc0 100644 --- a/go.sum +++ b/go.sum @@ -632,6 +632,10 @@ github.com/milvus-io/gorocksdb v0.0.0-20220624081344-8c5f4212846b h1:TfeY0NxYxZz github.com/milvus-io/gorocksdb v0.0.0-20220624081344-8c5f4212846b/go.mod h1:iwW+9cWfIzzDseEBCCeDSN5SD16Tidvy8cwQ7ZY8Qj4= github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20241120015424-93892e628c69 h1:Qt0Bv2Fum3EX3OlkuQYHJINBzeU4oEuHy2lXSfB/gZw= github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20241120015424-93892e628c69/go.mod h1:/6UT4zZl6awVeXLeE7UGDWZvXj3IWkRsh3mqsn0DiAs= +github.com/milvus-io/milvus-proto/go-api/v2 v2.5.0-beta.0.20241129024423-3911e6ebd8a6 h1:TrGZtojfj84Rdd1XAaGULCWZqO3rJMiGS8vxFXHT7G4= +github.com/milvus-io/milvus-proto/go-api/v2 v2.5.0-beta.0.20241129024423-3911e6ebd8a6/go.mod h1:/6UT4zZl6awVeXLeE7UGDWZvXj3IWkRsh3mqsn0DiAs= +github.com/milvus-io/milvus-proto/go-api/v2 v2.5.0-beta.0.20241129033252-5d0b09587056 h1:o2uJgfwTOg8bu/E9n6TvmFT2XPrPm1v0XFhc6XXcFoE= +github.com/milvus-io/milvus-proto/go-api/v2 v2.5.0-beta.0.20241129033252-5d0b09587056/go.mod h1:/6UT4zZl6awVeXLeE7UGDWZvXj3IWkRsh3mqsn0DiAs= github.com/milvus-io/pulsar-client-go v0.12.1 h1:O2JZp1tsYiO7C0MQ4hrUY/aJXnn2Gry6hpm7UodghmE= github.com/milvus-io/pulsar-client-go v0.12.1/go.mod h1:dkutuH4oS2pXiGm+Ti7fQZ4MRjrMPZ8IJeEGAWMeckk= github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 h1:AMFGa4R4MiIpspGNG7Z948v4n35fFGB3RR3G/ry4FWs= diff --git a/internal/proxy/database_interceptor.go b/internal/proxy/database_interceptor.go index ba4c13d06f5fa..85578d5029df5 100644 --- a/internal/proxy/database_interceptor.go +++ b/internal/proxy/database_interceptor.go @@ -265,6 +265,11 @@ func fillDatabase(ctx context.Context, req interface{}) (context.Context, interf r.DbName = GetCurDBNameFromContextOrDefault(ctx) } return ctx, r + case *milvuspb.ManualCompactionRequest: + if r.DbName == "" { + r.DbName = GetCurDBNameFromContextOrDefault(ctx) + } + return ctx, r default: } return ctx, req diff --git a/internal/proxy/database_interceptor_test.go b/internal/proxy/database_interceptor_test.go index 92aad0ad74ef2..bf989c76e632c 100644 --- a/internal/proxy/database_interceptor_test.go +++ b/internal/proxy/database_interceptor_test.go @@ -94,6 +94,7 @@ func TestDatabaseInterceptor(t *testing.T) { &milvuspb.ListImportTasksRequest{}, &milvuspb.OperatePrivilegeRequest{Entity: &milvuspb.GrantEntity{}}, &milvuspb.SelectGrantRequest{Entity: &milvuspb.GrantEntity{}}, + &milvuspb.ManualCompactionRequest{}, } md := metadata.Pairs(util.HeaderDBName, "db") @@ -117,7 +118,6 @@ func TestDatabaseInterceptor(t *testing.T) { &milvuspb.CalcDistanceRequest{}, &milvuspb.FlushAllRequest{}, &milvuspb.GetCompactionStateRequest{}, - &milvuspb.ManualCompactionRequest{}, &milvuspb.GetCompactionPlansRequest{}, &milvuspb.GetFlushAllStateRequest{}, &milvuspb.GetImportStateRequest{}, diff --git a/internal/proxy/impl.go b/internal/proxy/impl.go index f0c4a73f9f0ac..da06cf4d4abdc 100644 --- a/internal/proxy/impl.go +++ b/internal/proxy/impl.go @@ -4620,6 +4620,7 @@ func (node *Proxy) ManualCompaction(ctx context.Context, req *milvuspb.ManualCom defer sp.End() log := log.Ctx(ctx).With( + zap.String("collectionName", req.GetCollectionName()), zap.Int64("collectionID", req.GetCollectionID())) log.Info("received ManualCompaction request") @@ -4629,6 +4630,16 @@ func (node *Proxy) ManualCompaction(ctx context.Context, req *milvuspb.ManualCom return resp, nil } + // before v2.4.18, manual compact request only pass collectionID, should correct sdk's behavior to pass collectionName + if req.GetCollectionName() != "" { + var err error + req.CollectionID, err = globalMetaCache.GetCollectionID(ctx, req.GetDbName(), req.GetCollectionName()) + if err != nil { + resp.Status = merr.Status(err) + return resp, nil + } + } + resp, err := node.dataCoord.ManualCompaction(ctx, req) log.Info("received ManualCompaction response", zap.Any("resp", resp),