Skip to content

Commit

Permalink
enhance: alterdatabase support delete property (#38380)
Browse files Browse the repository at this point in the history
alterdatabase support delete property
issue: #38379

---------

Signed-off-by: Xianhui.Lin <[email protected]>
  • Loading branch information
JsDove authored Dec 12, 2024
1 parent 59234a3 commit d0a8110
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 22 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ require (
github.com/gin-gonic/gin v1.9.1
github.com/go-playground/validator/v10 v10.14.0
github.com/gofrs/flock v0.8.1
github.com/golang/protobuf v1.5.4
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.1.2
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.5.0-beta.0.20241204065646-180ce3a8d277
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.0-beta.0.20241211060635-410431d7865b
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
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -630,10 +630,8 @@ github.com/milvus-io/cgosymbolizer v0.0.0-20240722103217-b7dee0e50119 h1:9VXijWu
github.com/milvus-io/cgosymbolizer v0.0.0-20240722103217-b7dee0e50119/go.mod h1:DvXTE/K/RtHehxU8/GtDs4vFtfw64jJ3PaCnFri8CRg=
github.com/milvus-io/gorocksdb v0.0.0-20220624081344-8c5f4212846b h1:TfeY0NxYxZzUfIfYe5qYDBzt4ZYRqzUjTR6CvUzjat8=
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.5.0-beta.0.20241202112430-822be0295910 h1:cFRrdFZwhFHv33pue1z8beYSvrXDYFSFsCuvXGX3DHE=
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.0-beta.0.20241202112430-822be0295910/go.mod h1:/6UT4zZl6awVeXLeE7UGDWZvXj3IWkRsh3mqsn0DiAs=
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.0-beta.0.20241204065646-180ce3a8d277 h1:5/35+F32fs6ifVzI1e+VkUNpK0gWyXQSdZVnmNUFrrg=
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.0-beta.0.20241204065646-180ce3a8d277/go.mod h1:/6UT4zZl6awVeXLeE7UGDWZvXj3IWkRsh3mqsn0DiAs=
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.0-beta.0.20241211060635-410431d7865b h1:iPPhnFx+s7FF53UeWj7A4EYhPRMFPL6mHqyQw7qRjeQ=
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.0-beta.0.20241211060635-410431d7865b/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=
Expand Down
1 change: 1 addition & 0 deletions internal/proto/root_coord.proto
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ message AlterDatabaseRequest {
string db_name = 2;
string db_id = 3;
repeated common.KeyValuePair properties = 4;
repeated string delete_keys = 5;
}

message GetPChannelInfoRequest {
Expand Down
1 change: 1 addition & 0 deletions internal/proxy/task_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ func (t *alterDatabaseTask) Execute(ctx context.Context) error {
DbName: t.AlterDatabaseRequest.GetDbName(),
DbId: t.AlterDatabaseRequest.GetDbId(),
Properties: t.AlterDatabaseRequest.GetProperties(),
DeleteKeys: t.AlterDatabaseRequest.GetDeleteKeys(),
}

ret, err := t.rootCoord.AlterDatabase(ctx, req)
Expand Down
14 changes: 14 additions & 0 deletions internal/proxy/task_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ func TestAlterDatabase(t *testing.T) {

err = task.Execute(context.Background())
assert.Nil(t, err)

task1 := &alterDatabaseTask{
AlterDatabaseRequest: &milvuspb.AlterDatabaseRequest{
Base: &commonpb.MsgBase{},
DbName: "test_alter_database",
DeleteKeys: []string{common.MmapEnabledKey},
},
rootCoord: rc,
}
err1 := task1.PreExecute(context.Background())
assert.Nil(t, err1)

err1 = task1.Execute(context.Background())
assert.Nil(t, err1)
}

func TestDescribeDatabaseTask(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion internal/rootcoord/alter_collection_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ func DeleteProperties(oldProps []*commonpb.KeyValuePair, deleteKeys []string) []
for key, value := range propsMap {
propKV = append(propKV, &commonpb.KeyValuePair{Key: key, Value: value})
}
log.Info("Alter Collection Drop Properties", zap.Any("newProperties", propKV))
return propKV
}

Expand Down
28 changes: 18 additions & 10 deletions internal/rootcoord/alter_database_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ func (a *alterDatabaseTask) Prepare(ctx context.Context) error {
}

func (a *alterDatabaseTask) Execute(ctx context.Context) error {
// Now we only support alter properties of database
if a.Req.GetProperties() == nil {
return errors.New("only support alter database properties, but database properties is empty")
// Now we support alter and delete properties of database
if a.Req.GetProperties() == nil && a.Req.GetDeleteKeys() == nil {
return errors.New("alter database requires either properties or deletekeys to modify or delete keys, both cannot be empty")
}

if len(a.Req.GetProperties()) > 0 && len(a.Req.GetDeleteKeys()) > 0 {
return errors.New("alter database operation cannot modify properties and delete keys at the same time")
}

oldDB, err := a.core.meta.GetDatabaseByName(ctx, a.Req.GetDbName(), a.ts)
Expand All @@ -59,14 +63,18 @@ func (a *alterDatabaseTask) Execute(ctx context.Context) error {
return err
}

if ContainsKeyPairArray(a.Req.GetProperties(), oldDB.Properties) {
log.Info("skip to alter database due to no changes were detected in the properties", zap.String("databaseName", a.Req.GetDbName()))
return nil
}

newDB := oldDB.Clone()
ret := MergeProperties(oldDB.Properties, a.Req.GetProperties())
newDB.Properties = ret
if (len(a.Req.GetProperties())) > 0 {
if ContainsKeyPairArray(a.Req.GetProperties(), oldDB.Properties) {
log.Info("skip to alter database due to no changes were detected in the properties", zap.String("databaseName", a.Req.GetDbName()))
return nil
}
ret := MergeProperties(oldDB.Properties, a.Req.GetProperties())
newDB.Properties = ret
} else if (len(a.Req.GetDeleteKeys())) > 0 {
ret := DeleteProperties(oldDB.Properties, a.Req.GetDeleteKeys())
newDB.Properties = ret
}

ts := a.GetTs()
redoTask := newBaseRedoTask(a.core.stepExecutor)
Expand Down
35 changes: 35 additions & 0 deletions internal/rootcoord/alter_database_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,39 @@ func Test_alterDatabaseTask_Execute(t *testing.T) {
Value: "true",
})
})

t.Run("test delete collection props", func(t *testing.T) {
oldProps := []*commonpb.KeyValuePair{
{
Key: common.CollectionTTLConfigKey,
Value: "1",
},
}

deleteKeys := []string{
common.CollectionAutoCompactionKey,
}

ret := DeleteProperties(oldProps, deleteKeys)

assert.Contains(t, ret, &commonpb.KeyValuePair{
Key: common.CollectionTTLConfigKey,
Value: "1",
})

oldProps2 := []*commonpb.KeyValuePair{
{
Key: common.CollectionTTLConfigKey,
Value: "1",
},
}

deleteKeys2 := []string{
common.CollectionTTLConfigKey,
}

ret2 := DeleteProperties(oldProps2, deleteKeys2)

assert.Empty(t, ret2)
})
}
24 changes: 20 additions & 4 deletions internal/rootcoord/quota_center.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,14 @@ func (q *QuotaCenter) getDenyReadingDBs() map[int64]struct{} {
for _, dbID := range lo.Uniq(q.collectionIDToDBID.Values()) {
if db, err := q.meta.GetDatabaseByID(q.ctx, dbID, typeutil.MaxTimestamp); err == nil {
if v := db.GetProperty(common.DatabaseForceDenyReadingKey); v != "" {
if dbForceDenyReadingEnabled, _ := strconv.ParseBool(v); dbForceDenyReadingEnabled {
dbIDs[dbID] = struct{}{}
if dbForceDenyReadingEnabled, err := strconv.ParseBool(v); err == nil {
if dbForceDenyReadingEnabled {
dbIDs[dbID] = struct{}{}
}
} else {
log.Warn("invalid configuration for database force deny reading",
zap.String("config item", common.DatabaseForceDenyReadingKey),
zap.String("config value", v))
}
}
}
Expand Down Expand Up @@ -740,8 +746,14 @@ func (q *QuotaCenter) getDenyWritingDBs() map[int64]struct{} {
for _, dbID := range lo.Uniq(q.collectionIDToDBID.Values()) {
if db, err := q.meta.GetDatabaseByID(q.ctx, dbID, typeutil.MaxTimestamp); err == nil {
if v := db.GetProperty(common.DatabaseForceDenyWritingKey); v != "" {
if dbForceDenyWritingEnabled, _ := strconv.ParseBool(v); dbForceDenyWritingEnabled {
dbIDs[dbID] = struct{}{}
if dbForceDenyWritingEnabled, err := strconv.ParseBool(v); err == nil {
if dbForceDenyWritingEnabled {
dbIDs[dbID] = struct{}{}
}
} else {
log.Warn("invalid configuration for database force deny writing",
zap.String("config item", common.DatabaseForceDenyWritingKey),
zap.String("config value", v))
}
}
}
Expand Down Expand Up @@ -1341,6 +1353,10 @@ func (q *QuotaCenter) checkDBDiskQuota(dbSizeInfo map[int64]int64) []int64 {
dbDiskQuotaMB := dbDiskQuotaBytes * 1024 * 1024
checkDiskQuota(dbID, binlogSize, dbDiskQuotaMB)
continue
} else {
log.Warn("invalid configuration for diskQuota.mb",
zap.String("config item", common.DatabaseDiskQuotaKey),
zap.String("config value", dbDiskQuotaStr))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/json-iterator/go v1.1.12
github.com/klauspost/compress v1.17.7
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.0-beta.0.20241204065646-180ce3a8d277
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.0-beta.0.20241211060635-410431d7865b
github.com/nats-io/nats-server/v2 v2.10.12
github.com/nats-io/nats.go v1.34.1
github.com/panjf2000/ants/v2 v2.7.2
Expand Down
2 changes: 2 additions & 0 deletions pkg/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ 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.5.0-beta.0.20241204065646-180ce3a8d277 h1:5/35+F32fs6ifVzI1e+VkUNpK0gWyXQSdZVnmNUFrrg=
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.0-beta.0.20241204065646-180ce3a8d277/go.mod h1:/6UT4zZl6awVeXLeE7UGDWZvXj3IWkRsh3mqsn0DiAs=
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.0-beta.0.20241211060635-410431d7865b h1:iPPhnFx+s7FF53UeWj7A4EYhPRMFPL6mHqyQw7qRjeQ=
github.com/milvus-io/milvus-proto/go-api/v2 v2.5.0-beta.0.20241211060635-410431d7865b/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/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
Expand Down

0 comments on commit d0a8110

Please sign in to comment.