mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
fix: Alter allow_insert_autoid via AlterCollection (#44530)
issue: #44425 --------- Signed-off-by: sunby <sunbingyi1992@gmail.com>
This commit is contained in:
parent
f61952adfc
commit
4f61f4ee22
@ -1159,6 +1159,10 @@ func (t *alterCollectionTask) PreExecute(ctx context.Context) error {
|
||||
return merr.WrapErrParameterInvalidMsg("cannot provide both DeleteKeys and ExtraParams")
|
||||
}
|
||||
|
||||
collSchema, err := globalMetaCache.GetCollectionSchema(ctx, t.GetDbName(), t.CollectionName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
collectionID, err := globalMetaCache.GetCollectionID(ctx, t.GetDbName(), t.CollectionName)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -1176,6 +1180,17 @@ func (t *alterCollectionTask) PreExecute(ctx context.Context) error {
|
||||
return merr.WrapErrCollectionLoaded(t.CollectionName, "can not alter mmap properties if collection loaded")
|
||||
}
|
||||
}
|
||||
|
||||
enabled, _ := common.IsAllowInsertAutoID(t.Properties...)
|
||||
if enabled {
|
||||
primaryFieldSchema, err := typeutil.GetPrimaryFieldSchema(collSchema.CollectionSchema)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !primaryFieldSchema.AutoID {
|
||||
return merr.WrapErrParameterInvalidMsg("the value for %s must be false when autoID is false", common.AllowInsertAutoIDKey)
|
||||
}
|
||||
}
|
||||
// Check the validation of timezone
|
||||
err := checkTimezone(t.Properties...)
|
||||
if err != nil {
|
||||
@ -1343,7 +1358,6 @@ var allowedAlterProps = []string{
|
||||
common.MaxLengthKey,
|
||||
common.MmapEnabledKey,
|
||||
common.MaxCapacityKey,
|
||||
common.AllowInsertAutoIDKey,
|
||||
}
|
||||
|
||||
var allowedDropProps = []string{
|
||||
@ -1473,18 +1487,6 @@ func (t *alterCollectionFieldTask) PreExecute(ctx context.Context) error {
|
||||
if maxCapacityPerRow > defaultMaxArrayCapacity || maxCapacityPerRow <= 0 {
|
||||
return merr.WrapErrParameterInvalidMsg("the maximum capacity specified for a Array should be in (0, %d]", defaultMaxArrayCapacity)
|
||||
}
|
||||
case common.AllowInsertAutoIDKey:
|
||||
allowInsertAutoID, err := strconv.ParseBool(prop.Value)
|
||||
if err != nil {
|
||||
return merr.WrapErrParameterInvalidMsg("the value for %s must be a boolean", common.AllowInsertAutoIDKey)
|
||||
}
|
||||
primaryFieldSchema, err := typeutil.GetPrimaryFieldSchema(collSchema.CollectionSchema)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if allowInsertAutoID && !primaryFieldSchema.AutoID {
|
||||
return merr.WrapErrParameterInvalidMsg("the value for %s must be false when autoID is false", common.AllowInsertAutoIDKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -462,8 +462,8 @@ func TestAlterCollection_AllowInsertAutoID_Validation(t *testing.T) {
|
||||
err := InitMetaCache(ctx, root, mgr)
|
||||
assert.NoError(t, err)
|
||||
|
||||
task := &alterCollectionFieldTask{
|
||||
AlterCollectionFieldRequest: &milvuspb.AlterCollectionFieldRequest{
|
||||
task := &alterCollectionTask{
|
||||
AlterCollectionRequest: &milvuspb.AlterCollectionRequest{
|
||||
Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_AlterCollectionField},
|
||||
DbName: dbName,
|
||||
CollectionName: "allow_autoid_test",
|
||||
@ -484,8 +484,8 @@ func TestAlterCollection_AllowInsertAutoID_Validation(t *testing.T) {
|
||||
err := InitMetaCache(ctx, root, mgr)
|
||||
assert.NoError(t, err)
|
||||
|
||||
task := &alterCollectionFieldTask{
|
||||
AlterCollectionFieldRequest: &milvuspb.AlterCollectionFieldRequest{
|
||||
task := &alterCollectionTask{
|
||||
AlterCollectionRequest: &milvuspb.AlterCollectionRequest{
|
||||
Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_AlterCollectionField},
|
||||
DbName: dbName,
|
||||
CollectionName: "allow_autoid_test",
|
||||
@ -5341,7 +5341,7 @@ func TestDescribeCollectionTaskWithStructArrayField(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestAlterCollectionField_AllowInsertAutoID_AutoIDFalse(t *testing.T) {
|
||||
func TestAlterCollection_AllowInsertAutoID_AutoIDFalse(t *testing.T) {
|
||||
qc := NewMixCoordMock()
|
||||
InitMetaCache(context.Background(), qc, nil)
|
||||
ctx := context.Background()
|
||||
@ -5364,11 +5364,10 @@ func TestAlterCollectionField_AllowInsertAutoID_AutoIDFalse(t *testing.T) {
|
||||
}
|
||||
qc.CreateCollection(ctx, createColReq)
|
||||
|
||||
task := &alterCollectionFieldTask{
|
||||
AlterCollectionFieldRequest: &milvuspb.AlterCollectionFieldRequest{
|
||||
task := &alterCollectionTask{
|
||||
AlterCollectionRequest: &milvuspb.AlterCollectionRequest{
|
||||
Base: &commonpb.MsgBase{},
|
||||
CollectionName: collectionName,
|
||||
FieldName: "",
|
||||
Properties: []*commonpb.KeyValuePair{
|
||||
{Key: common.AllowInsertAutoIDKey, Value: "true"},
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user