diff --git a/api.go b/api.go index cf5431198..f03c3f4d3 100644 --- a/api.go +++ b/api.go @@ -1479,7 +1479,7 @@ func (api *API) ImportValue(ctx context.Context, qcx *Qcx, req *ImportValueReque return api.ImportValueWithTx(ctx, qcx, req, opts...) } -// ImportValue bulk imports values into a particular field. +// ImportValueWithTx bulk imports values into a particular field. func (api *API) ImportValueWithTx(ctx context.Context, qcx *Qcx, req *ImportValueRequest, opts ...ImportOption) (err0 error) { span, _ := tracing.StartSpanFromContext(ctx, "API.ImportValue") defer span.Finish() diff --git a/holder.go b/holder.go index 0fdc64b49..24c6e939f 100644 --- a/holder.go +++ b/holder.go @@ -1256,8 +1256,7 @@ func (h *Holder) loadField(indexName, fieldName string) (*Field, error) { return nil, errors.Wrap(err, "decoding CreateFieldMessage") } - // TODO: can this take cfm? - return idx.createFieldIfNotExists(fieldName, cfm.Meta) + return idx.createFieldIfNotExists(cfm) } func (h *Holder) loadView(indexName, fieldName, viewName string) (*view, error) { diff --git a/index.go b/index.go index ea04dcf45..bd6d81c60 100644 --- a/index.go +++ b/index.go @@ -399,7 +399,14 @@ func (i *Index) openExistenceField() error { // If we have gotten here, it means that we couldn't successfully open the // existence field from disk, so we need to create it. - f, err := i.createFieldIfNotExists(existenceFieldName, &FieldOptions{CacheType: CacheTypeNone, CacheSize: 0}) + cfm := &CreateFieldMessage{ + Index: i.name, + Field: existenceFieldName, + CreatedAt: 0, + Meta: &FieldOptions{CacheType: CacheTypeNone, CacheSize: 0}, + } + + f, err := i.createFieldIfNotExists(cfm) if err != nil { return errors.Wrap(err, "creating existence field") } @@ -723,22 +730,15 @@ func (i *Index) persistField(ctx context.Context, cfm *CreateFieldMessage) error // createFieldIfNotExists creates the field if it does not already exist in the // in-memory index structure. This is not related to whether or not the field // exists in etcd. -func (i *Index) createFieldIfNotExists(name string, opt *FieldOptions) (*Field, error) { +func (i *Index) createFieldIfNotExists(cfm *CreateFieldMessage) (*Field, error) { i.mu.Lock() defer i.mu.Unlock() // Find field in cache first. - if f := i.fields[name]; f != nil { + if f := i.fields[cfm.Field]; f != nil { return f, nil } - cfm := &CreateFieldMessage{ - Index: i.name, - Field: name, - CreatedAt: 0, - Meta: opt, - } - return i.createField(cfm, false) }