fix(dbrp): Wait until we know this bucket is default before writing value.
parent
a834d18cf2
commit
e95839db60
|
@ -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")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue