Skip to content

Commit

Permalink
lock cache row to prevent concurrent updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Omarabdul3ziz committed Aug 31, 2024
1 parent d8b6bca commit a2a8080
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion grid-proxy/internal/explorer/db/setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,12 @@ $$
BEGIN
IF (TG_OP = 'UPDATE' AND NEW.state = 'Deleted') THEN
BEGIN
-- lock cache row to prevent concurrent updates
PERFORM 1
FROM resources_cache
WHERE node_id = NEW.node_id
FOR UPDATE;

UPDATE resources_cache
SET
used_cru = resources_cache.used_cru - contract_resources.cru,
Expand Down Expand Up @@ -621,7 +627,7 @@ BEGIN

total_ips = total_ips + (
CASE
WHEN TG_OP = 'INSERT'
WHEN TG_OP = 'INSERT'
THEN 1
WHEn TG_OP = 'DELETE'
THEN -1
Expand Down

0 comments on commit a2a8080

Please sign in to comment.