Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sesposito committed Feb 14, 2024
1 parent f1e9203 commit aeb7627
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions server/core_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ func storageWriteObjects(ctx context.Context, logger *zap.Logger, metrics Metric
// - permission: non-authoritative write & original row write != 1
metrics.StorageWriteRejectCount(map[string]string{"collection": object.Collection, "reason": "permission"}, 1)
return nil, runtime.ErrStorageRejectedPermission
} else if object.Version != "" && versionRejected {
} else if versionRejected {
// - version mismatch
metrics.StorageWriteRejectCount(map[string]string{"collection": object.Collection, "reason": "version"}, 1)
return nil, runtime.ErrStorageRejectedVersion
Expand Down Expand Up @@ -686,11 +686,9 @@ func storagePrepBatch(batch *pgx.Batch, authoritativeWrite bool, op *StorageOpWr
)
(SELECT read, write, version, create_time, update_time, true AS upsert, false AS rejected FROM upd)
UNION ALL
(SELECT read, write, version, create_time, update_time, false AS upsert, $8 != version AS rejected FROM storage WHERE collection = $1 and key = $2 and user_id = $3 AND NOT EXISTS (SELECT 1 FROM upd))
(SELECT read, write, version, create_time, update_time, false AS upsert, false AS rejected FROM storage WHERE collection = $1 and key = $2 and user_id = $3 AND NOT EXISTS (SELECT 1 FROM upd))
LIMIT 1`

params = append(params, object.Version)

// Outcomes:
// - Row is always returned, need to know if update happened, that WHERE matches
// - write != 1 means no permission to write
Expand Down

0 comments on commit aeb7627

Please sign in to comment.