Unified Storage: Don't read before create (#102906)
* Unified Storage: Don't read before create * test: use the existing test infra * fix: support pq We use pgx, but it seems to be wrapped in a pq driver shim, causing the errors to be remapped to pq's type. Weird situation. * feat: support CDK backend * revert: there is a postgres_tests block * fix(CDK): only check existence on ADDED updates * fix(CDK): use ReadResource to deal with deleted files
This commit is contained in:
@@ -476,22 +476,14 @@ func (s *server) Create(ctx context.Context, req *CreateRequest) (*CreateRespons
|
||||
return rsp, nil
|
||||
}
|
||||
|
||||
found := s.backend.ReadResource(ctx, &ReadRequest{Key: req.Key})
|
||||
if found != nil && len(found.Value) > 0 {
|
||||
rsp.Error = &ErrorResult{
|
||||
Code: http.StatusConflict,
|
||||
Reason: string(metav1.StatusReasonAlreadyExists),
|
||||
Message: "key already exists", // TODO?? soft delete replace?
|
||||
}
|
||||
return rsp, nil
|
||||
}
|
||||
|
||||
event, e := s.newEvent(ctx, user, req.Key, req.Value, nil)
|
||||
if e != nil {
|
||||
rsp.Error = e
|
||||
return rsp, nil
|
||||
}
|
||||
|
||||
// If the resource already exists, the create will return an already exists error that is remapped appropriately by AsErrorResult.
|
||||
// This also benefits from ACID behaviours on our databases, so we avoid race conditions.
|
||||
var err error
|
||||
rsp.ResourceVersion, err = s.backend.WriteEvent(ctx, *event)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user