From bc5d5327350f4cd515b1efc398f0454f62c01924 Mon Sep 17 00:00:00 2001 From: Gonzalo Riestra Date: Wed, 13 Mar 2019 16:34:12 +0100 Subject: [PATCH 1/6] remove default TIS config --- scripts-available/CDB_GhostTables.sql | 9 ++++++--- test/CDB_GhostTables.sql | 13 +++++++++++-- test/CDB_GhostTables_expect | 4 ++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/scripts-available/CDB_GhostTables.sql b/scripts-available/CDB_GhostTables.sql index cb48e88..6fed1e8 100644 --- a/scripts-available/CDB_GhostTables.sql +++ b/scripts-available/CDB_GhostTables.sql @@ -12,9 +12,12 @@ AS $$ json = GD['json'] tis_config = plpy.execute("select cartodb.CDB_Conf_GetConf('invalidation_service');")[0]['cdb_conf_getconf'] - tis_config_dict = json.loads(tis_config) if tis_config else {} - tis_host = tis_config_dict.get('host', '127.0.0.1') - tis_port = tis_config_dict.get('port', 3142) + if not tis_config: + return + + tis_config_dict = json.loads(tis_config) + tis_host = tis_config_dict.get('host') + tis_port = tis_config_dict.get('port') tis_timeout = tis_config_dict.get('timeout', 5) tis_retry = tis_config_dict.get('retry', 5) diff --git a/test/CDB_GhostTables.sql b/test/CDB_GhostTables.sql index 33fae5b..1c1e244 100644 --- a/test/CDB_GhostTables.sql +++ b/test/CDB_GhostTables.sql @@ -7,12 +7,21 @@ GRANT ALL ON SCHEMA cartodb TO "fulano"; GRANT SELECT ON cartodb.cdb_ddl_execution TO "fulano"; GRANT EXECUTE ON FUNCTION CDB_Username() TO "fulano"; GRANT EXECUTE ON FUNCTION CDB_LinkGhostTables(text) TO "fulano"; -INSERT INTO cdb_conf (key, value) VALUES ('api_keys_fulano', '{"username": "fulanito", "permissions":[]}'); -INSERT INTO cdb_conf (key, value) VALUES ('invalidation_service', '{"host": "fake-tis-host"}'); +SELECT cartodb.CDB_Conf_SetConf('api_keys_fulano', '{"username": "fulanito", "permissions":[]}'); +DELETE FROM cdb_conf WHERE key = 'invalidation_service'; SET SESSION AUTHORIZATION "fulano"; SET client_min_messages TO notice; \set QUIET off +SELECT CDB_LinkGhostTables(); -- _CDB_LinkGhostTables called, TIS connection not tried + +-- Disable Ghost tables trigger +\set QUIET on +SET SESSION AUTHORIZATION postgres; +SELECT cartodb.CDB_Conf_SetConf('invalidation_service', '{"host": "fake-tis-host", "port": 3142}'); +SET SESSION AUTHORIZATION "fulano"; +\set QUIET off + SELECT CDB_LinkGhostTables(); -- _CDB_LinkGhostTables called BEGIN; diff --git a/test/CDB_GhostTables_expect b/test/CDB_GhostTables_expect index 3e46518..4300a01 100644 --- a/test/CDB_GhostTables_expect +++ b/test/CDB_GhostTables_expect @@ -1,4 +1,8 @@ + +NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER + + WARNING: Invalidation Service error: Error -2 connecting fake-tis-host:3142. Name or service not known. NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER From 3faa38986082fd0b6a849f107aa20fd4f32882a6 Mon Sep 17 00:00:00 2001 From: Gonzalo Riestra Date: Wed, 13 Mar 2019 18:16:08 +0100 Subject: [PATCH 2/6] improve logs --- scripts-available/CDB_GhostTables.sql | 4 ++-- test/CDB_GhostTables_expect | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts-available/CDB_GhostTables.sql b/scripts-available/CDB_GhostTables.sql index 6fed1e8..59dab7f 100644 --- a/scripts-available/CDB_GhostTables.sql +++ b/scripts-available/CDB_GhostTables.sql @@ -33,7 +33,7 @@ AS $$ except Exception as err: error = "client_error - %s" % str(err) # NOTE: no retries on connection error - plpy.warning('Invalidation Service connection error: ' + str(err)) + plpy.warning('Error trying to connect to Invalidation Service to link Ghost Tables: ' + str(err)) break try: @@ -43,7 +43,7 @@ AS $$ error = "request_error - %s" % str(err) client = GD['invalidation'] = None # force reconnect if not tis_retry: - plpy.warning('Invalidation Service error: ' + str(err)) + plpy.warning('Error calling Invalidation Service to link Ghost Tables: ' + str(err)) break tis_retry -= 1 # try reconnecting $$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE; diff --git a/test/CDB_GhostTables_expect b/test/CDB_GhostTables_expect index 4300a01..0a42733 100644 --- a/test/CDB_GhostTables_expect +++ b/test/CDB_GhostTables_expect @@ -3,7 +3,7 @@ NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER -WARNING: Invalidation Service error: Error -2 connecting fake-tis-host:3142. Name or service not known. +WARNING: Error calling Invalidation Service to link Ghost Tables: Error -2 connecting fake-tis-host:3142. Name or service not known. NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER BEGIN @@ -11,7 +11,7 @@ cdb_ddl_execution 0 CREATE TABLE 1 -WARNING: Invalidation Service error: Error -2 connecting fake-tis-host:3142. Name or service not known. +WARNING: Error calling Invalidation Service to link Ghost Tables: Error -2 connecting fake-tis-host:3142. Name or service not known. NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=CREATE TABLE COMMIT From a5b2b66bb6e12af3d23a003298c61c0cf79cb53a Mon Sep 17 00:00:00 2001 From: Gonzalo Riestra Date: Thu, 14 Mar 2019 10:06:04 +0100 Subject: [PATCH 3/6] fix test comment --- test/CDB_GhostTables.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CDB_GhostTables.sql b/test/CDB_GhostTables.sql index 1c1e244..dd30ac8 100644 --- a/test/CDB_GhostTables.sql +++ b/test/CDB_GhostTables.sql @@ -15,7 +15,7 @@ SET client_min_messages TO notice; SELECT CDB_LinkGhostTables(); -- _CDB_LinkGhostTables called, TIS connection not tried --- Disable Ghost tables trigger +-- Add TIS configuration \set QUIET on SET SESSION AUTHORIZATION postgres; SELECT cartodb.CDB_Conf_SetConf('invalidation_service', '{"host": "fake-tis-host", "port": 3142}'); From 85d61649562f6c7b9942efa931456e335bba6ac4 Mon Sep 17 00:00:00 2001 From: Gonzalo Riestra Date: Thu, 14 Mar 2019 11:39:10 +0100 Subject: [PATCH 4/6] add log when there is no tig config --- scripts-available/CDB_GhostTables.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts-available/CDB_GhostTables.sql b/scripts-available/CDB_GhostTables.sql index 59dab7f..a96b275 100644 --- a/scripts-available/CDB_GhostTables.sql +++ b/scripts-available/CDB_GhostTables.sql @@ -13,6 +13,7 @@ AS $$ tis_config = plpy.execute("select cartodb.CDB_Conf_GetConf('invalidation_service');")[0]['cdb_conf_getconf'] if not tis_config: + plpy.warning('Invalidation service configuration not found. Skipping Ghost Tables linking.') return tis_config_dict = json.loads(tis_config) From 2baee24f30e0c643c99fb9ac3ccc78099a43b057 Mon Sep 17 00:00:00 2001 From: Gonzalo Riestra Date: Thu, 14 Mar 2019 11:47:41 +0100 Subject: [PATCH 5/6] fix test --- test/CDB_GhostTables.sql | 2 +- test/CDB_GhostTables_expect | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/CDB_GhostTables.sql b/test/CDB_GhostTables.sql index dd30ac8..1741f01 100644 --- a/test/CDB_GhostTables.sql +++ b/test/CDB_GhostTables.sql @@ -13,7 +13,7 @@ SET SESSION AUTHORIZATION "fulano"; SET client_min_messages TO notice; \set QUIET off -SELECT CDB_LinkGhostTables(); -- _CDB_LinkGhostTables called, TIS connection not tried +SELECT CDB_LinkGhostTables(); -- _CDB_LinkGhostTables called (configuration not found) -- Add TIS configuration \set QUIET on diff --git a/test/CDB_GhostTables_expect b/test/CDB_GhostTables_expect index 0a42733..a037395 100644 --- a/test/CDB_GhostTables_expect +++ b/test/CDB_GhostTables_expect @@ -1,5 +1,5 @@ - +WARNING: Invalidation service configuration not found. Skipping Ghost Tables linking. NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER From 5b19d0fc5e72c83366e54c0cbf22ce817d02b523 Mon Sep 17 00:00:00 2001 From: Gonzalo Riestra Date: Thu, 14 Mar 2019 12:08:33 +0100 Subject: [PATCH 6/6] fix test correctly --- test/CDB_GhostTables_expect | 1 + 1 file changed, 1 insertion(+) diff --git a/test/CDB_GhostTables_expect b/test/CDB_GhostTables_expect index a037395..01156f7 100644 --- a/test/CDB_GhostTables_expect +++ b/test/CDB_GhostTables_expect @@ -1,4 +1,5 @@ + WARNING: Invalidation service configuration not found. Skipping Ghost Tables linking. NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER