def _perform_vlob_update(self, intent):
async with self.connection.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT version, read_trust_seed, write_trust_seed FROM "
"vlobs WHERE id=%s ORDER BY version DESC;", (intent.id, ))
ret = await cur.fetchone()
if ret is None:
raise VlobNotFound('Vlob not found.')
last_version, rts, wts = ret
if wts != intent.trust_seed:
raise TrustSeedError('Invalid write trust seed.')
if intent.version != last_version + 1:
raise VlobNotFound('Wrong blob version.')
# TODO: insertion doesn't do atomic check of version
await cur.execute("INSERT INTO vlobs VALUES (%s, %s, %s, %s, %s);",
(intent.id, intent.version, rts, wts, intent.blob))
await cur.execute("NOTIFY vlob_updated, %s", (intent.id, ))
评论列表
文章目录