mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 00:55:55 +00:00
Merge pull request #1429 from travisturner/disco-field-createdat
ensure field.CreatedAt is set on loadField
This commit is contained in:
commit
42b8522e80
3 changed files with 12 additions and 13 deletions
2
api.go
2
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()
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
20
index.go
20
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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue