Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [CHERRY-PICK] CollectionSchema.autoID is deprecated #30011

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions internal/distributed/proxy/httpserver/handler_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ func (h *HandlersV1) describeCollection(ctx context.Context, c *gin.Context, dbN
return nil, err
}
primaryField, ok := getPrimaryField(response.Schema)
if ok && primaryField.AutoID && !response.Schema.AutoID {
log.Warn("primary filed autoID VS schema autoID", zap.String("collectionName", collectionName), zap.Bool("primary Field", primaryField.AutoID), zap.Bool("schema", response.Schema.AutoID))
if ok && primaryField.AutoID {
response.Schema.AutoID = EnableAutoID
}
return response.Schema, nil
Expand Down Expand Up @@ -163,10 +162,11 @@ func (h *HandlersV1) listCollections(c *gin.Context) {

func (h *HandlersV1) createCollection(c *gin.Context) {
httpReq := CreateCollectionReq{
DbName: DefaultDbName,
MetricType: DefaultMetricType,
PrimaryField: DefaultPrimaryFieldName,
VectorField: DefaultVectorFieldName,
DbName: DefaultDbName,
MetricType: DefaultMetricType,
PrimaryField: DefaultPrimaryFieldName,
VectorField: DefaultVectorFieldName,
EnableDynamicField: EnableDynamic,
}
if err := c.ShouldBindWith(&httpReq, binding.JSON); err != nil {
log.Warn("high level restful api, the parameter of create collection is incorrect", zap.Any("request", httpReq), zap.Error(err))
Expand Down Expand Up @@ -209,7 +209,7 @@ func (h *HandlersV1) createCollection(c *gin.Context) {
AutoID: DisableAutoID,
},
},
EnableDynamicField: EnableDynamic,
EnableDynamicField: httpReq.EnableDynamicField,
})
if err != nil {
log.Warn("high level restful api, marshal collection schema fail", zap.Any("request", httpReq), zap.Error(err))
Expand Down Expand Up @@ -741,7 +741,8 @@ func (h *HandlersV1) upsert(c *gin.Context) {
if err != nil || coll == nil {
return
}
if coll.AutoID {
primaryField, ok := getPrimaryField(coll)
if ok && primaryField.AutoID {
err := merr.WrapErrParameterInvalid("autoID: false", "autoID: true", "cannot upsert an autoID collection")
c.AbortWithStatusJSON(http.StatusOK, gin.H{HTTPReturnCode: merr.Code(err), HTTPReturnMessage: err.Error()})
return
Expand Down
15 changes: 8 additions & 7 deletions internal/distributed/proxy/httpserver/request.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package httpserver

type CreateCollectionReq struct {
DbName string `json:"dbName"`
CollectionName string `json:"collectionName" validate:"required"`
Dimension int32 `json:"dimension" validate:"required"`
Description string `json:"description"`
MetricType string `json:"metricType"`
PrimaryField string `json:"primaryField"`
VectorField string `json:"vectorField"`
DbName string `json:"dbName"`
CollectionName string `json:"collectionName" validate:"required"`
Dimension int32 `json:"dimension" validate:"required"`
Description string `json:"description"`
MetricType string `json:"metricType"`
PrimaryField string `json:"primaryField"`
VectorField string `json:"vectorField"`
EnableDynamicField bool `json:"enableDynamicField"`
}

type DropCollectionReq struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/distributed/proxy/httpserver/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func checkAndSetData(body string, collSchema *schemapb.CollectionSchema) (error,

dataString := gjson.Get(data.Raw, fieldName).String()

if field.IsPrimaryKey && collSchema.AutoID {
if field.IsPrimaryKey && field.AutoID {
if dataString != "" {
return merr.WrapErrParameterInvalid("", "set primary key but autoID == true"), reallyDataArray
}
Expand Down
2 changes: 2 additions & 0 deletions internal/proxy/meta_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,8 @@ func (m *MetaCache) RemoveDatabase(ctx context.Context, database string) {
}

func (m *MetaCache) HasDatabase(ctx context.Context, database string) bool {
m.mu.RLock()
defer m.mu.RUnlock()
_, ok := m.collInfo[database]
return ok
}
Loading