fix(dbrp): Wait until we know this bucket is default before writing value.

pull/18618/head
Brett Buddin 2020-06-18 17:08:33 -04:00
parent a834d18cf2
commit e95839db60
No known key found for this signature in database
GPG Key ID: C51265E441C4C5AC
2 changed files with 12 additions and 7 deletions

View File

@ -148,6 +148,9 @@ func Test_handlePostDBRP(t *testing.T) {
t.Fatalf("expected orgid %s got %s", tt.ExpectedDBRP.OrganizationID, dbrp.OrganizationID)
}
if !dbrp.Default {
t.Fatalf("expected dbrp to be marked as default")
}
})
}
}

View File

@ -370,19 +370,12 @@ func (s *Service) Create(ctx context.Context, dbrp *influxdb.DBRPMappingV2) erro
if err != nil {
return ErrInvalidDBRPID
}
b, err := json.Marshal(dbrp)
if err != nil {
return ErrInternalService(err)
}
return s.store.Update(ctx, func(tx kv.Tx) error {
bucket, err := tx.Bucket(bucket)
if err != nil {
return ErrInternalService(err)
}
if err := bucket.Put(encodedID, b); err != nil {
return ErrInternalService(err)
}
compKey := indexForeignKey(*dbrp)
if err := s.byOrgAndDatabase.Insert(tx, compKey, encodedID); err != nil {
return err
@ -394,6 +387,15 @@ func (s *Service) Create(ctx context.Context, dbrp *influxdb.DBRPMappingV2) erro
if !defSet {
dbrp.Default = true
}
b, err := json.Marshal(dbrp)
if err != nil {
return ErrInternalService(err)
}
if err := bucket.Put(encodedID, b); err != nil {
return ErrInternalService(err)
}
if dbrp.Default {
if err := s.setAsDefault(tx, compKey, encodedID); err != nil {
return err