Edit: This was originally about updates being non-atomic but I was wrong.
There does still seem to be a significant opportunity to optimize.
I am not a pgsql expert, so please correct me if I am wrong.
Jet Chiang (@supreme-gg-gg)
Roughly, it looks like:
Query:
SELECT proto FROM actors
WHERE atespace = $1 AND name = $2
FOR UPDATE`, atespace, name
Unmarshal
call mutate(oldVal)
validate
Marshal
Query:
UPDATE actors
SET version = $1, proto = $2
WHERE atespace = $3 AND name = $4`,
dbActor.GetMetadata().GetVersion(), protoBytes, atespace, name
I am not a PGSQL expert but I thought "FOR UPDATE" requires a txn. Also gemini says not to use "FOR UPDATE" but "FOR NO KEY UPDATE". IIUC, also: row-locks are not auto-released, so we need to handle a crash mid-txn.
I assumed I would find something more like:
UPDATE actors
SET version = $5, proto = $6
WHERE atespace = $1 AND name = $2 AND uid = $3 AND version = $4,
atespace, name, expectUid, expectVersion, newVersion, protoBytes
...and then check that it affected exactly 1 row.
Edit: This was originally about updates being non-atomic but I was wrong.
There does still seem to be a significant opportunity to optimize.
I am not a pgsql expert, so please correct me if I am wrong.
Jet Chiang (@supreme-gg-gg)
Roughly, it looks like:
I am not a PGSQL expert but I thought "FOR UPDATE" requires a txn. Also gemini says not to use "FOR UPDATE" but "FOR NO KEY UPDATE". IIUC, also: row-locks are not auto-released, so we need to handle a crash mid-txn.
I assumed I would find something more like:
...and then check that it affected exactly 1 row.