Skip to content

Commit

Permalink
Lock per-entity
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhuaaa committed Aug 29, 2024
1 parent 174cb80 commit e05d645
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/migrations/mls/20240829001344_serial-ids.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ BEGIN
-- Ensures that the generated sequence ID matches the insertion order
-- Only released at the end of the enclosing transaction - beware if called within a long transaction
PERFORM
pg_advisory_xact_lock(hashtext('group_messages_sequence'));
pg_advisory_xact_lock(hashtext('group_messages_sequence'), hashtext(encode(group_id, 'hex')));
RETURN QUERY INSERT INTO group_messages(group_id, data, group_id_data_hash)
VALUES(group_id, data, group_id_data_hash)
RETURNING
Expand All @@ -19,7 +19,7 @@ CREATE FUNCTION insert_welcome_message(installation_key BYTEA, data BYTEA, insta
AS $$
BEGIN
PERFORM
pg_advisory_xact_lock(hashtext('welcome_messages_sequence'));
pg_advisory_xact_lock(hashtext('welcome_messages_sequence'), hashtext(encode(installation_key, 'hex')));
RETURN QUERY INSERT INTO welcome_messages(installation_key, data, installation_key_data_hash, hpke_public_key)
VALUES(installation_key, data, installation_key_data_hash, hpke_public_key)
RETURNING
Expand All @@ -33,7 +33,7 @@ CREATE FUNCTION insert_inbox_log(inbox_id BYTEA, server_timestamp_ns BIGINT, ide
AS $$
BEGIN
PERFORM
pg_advisory_xact_lock(hashtext('inbox_log_sequence'));
pg_advisory_xact_lock(hashtext('inbox_log_sequence'), hashtext(encode(inbox_id, 'hex')));
RETURN QUERY INSERT INTO inbox_log(inbox_id, server_timestamp_ns, identity_update_proto)
VALUES(inbox_id, server_timestamp_ns, identity_update_proto)
RETURNING
Expand Down

0 comments on commit e05d645

Please sign in to comment.