Compare commits

..

2 Commits

Author SHA1 Message Date
cgonzalez
5da3490aa3 Remove sleep 2021-09-27 16:53:18 +01:00
cgonzalez
592ef90abc Update CDB_TableMetadata_Trigger to handle race conditions 2021-09-27 14:21:35 +01:00
3 changed files with 25 additions and 11 deletions

View File

@ -1,7 +1,7 @@
# cartodb/Makefile
EXTENSION = cartodb
EXTVERSION = 0.37.1
EXTVERSION = 0.37.2
SED = sed
AWK = awk
@ -110,6 +110,7 @@ UPGRADABLE = \
0.35.0 \
0.36.0 \
0.37.0 \
0.37.1 \
$(EXTVERSION)dev \
$(EXTVERSION)next \
$(END)

View File

@ -1,3 +1,6 @@
0.37.2 (2021-09-27)
* Change `CDB_TableMetadata_Trigger` to handle a race condition due to concurrent inserts.
0.37.1 (2020-12-02)
* Change `__CDB_RegenerateTable_Get_Commands` to use the caller timeout or '1min' if not set.

View File

@ -42,16 +42,26 @@ BEGIN
SELECT oid FROM pg_class WHERE oid = tabname
);
WITH nv as (
SELECT TG_RELID as tabname, now() as t
), updated as (
UPDATE @extschema@.CDB_TableMetadata x SET updated_at = nv.t
FROM nv WHERE x.tabname = nv.tabname
RETURNING x.tabname
)
INSERT INTO @extschema@.CDB_TableMetadata SELECT nv.*
FROM nv LEFT JOIN updated USING(tabname)
WHERE updated.tabname IS NULL;
BEGIN
WITH nv as (
SELECT TG_RELID as tabname, now() as t
), updated as (
UPDATE @extschema@.CDB_TableMetadata x SET updated_at = nv.t
FROM nv WHERE x.tabname = nv.tabname
RETURNING x.tabname
)
INSERT INTO @extschema@.CDB_TableMetadata SELECT nv.*
FROM nv LEFT JOIN updated USING(tabname)
WHERE updated.tabname IS NULL;
EXCEPTION
-- Managing race condition due to concurrent inserts
WHEN UNIQUE_VIOLATION THEN
WITH nv as (
SELECT TG_RELID as tabname, now() as t
)
UPDATE @extschema@.CDB_TableMetadata x SET updated_at = nv.t
FROM nv WHERE x.tabname = nv.tabname;
END;
RETURN NULL;
END;