Compare commits

...

12 Commits

Author SHA1 Message Date
Gonzalo Riestra
74210c5b5c release 0.26.1 2019-03-19 17:43:36 +01:00
Gonzalo Riestra
d14d1d9994 Merge pull request #351 from CartoDB/remove_default_tis_config
Remove default TIS config in Ghost Table function
2019-03-14 12:23:06 +01:00
Gonzalo Riestra
5b19d0fc5e fix test correctly 2019-03-14 12:08:33 +01:00
Gonzalo Riestra
2baee24f30 fix test 2019-03-14 11:47:41 +01:00
Gonzalo Riestra
85d6164956 add log when there is no tig config 2019-03-14 11:39:10 +01:00
Gonzalo Riestra
a5b2b66bb6 fix test comment 2019-03-14 10:06:04 +01:00
Gonzalo Riestra
3faa389860 improve logs 2019-03-13 18:16:08 +01:00
Gonzalo Riestra
bc5d532735 remove default TIS config 2019-03-13 18:12:48 +01:00
Gonzalo Riestra
4f3d19ce7a Merge pull request #350 from CartoDB/explicit-schema-for-ghost-tables
Add explicit schema for Ghost Tables functions
2019-03-13 10:42:13 +01:00
Gonzalo Riestra
45fed9cf1b more explicit schemas 2019-03-13 10:29:50 +01:00
Gonzalo Riestra
e19489144c simplify queries 2019-03-13 09:08:13 +01:00
Gonzalo Riestra
83707297de add explicit schema for all functions 2019-03-12 18:39:48 +01:00
6 changed files with 46 additions and 25 deletions

View File

@@ -1,7 +1,7 @@
# cartodb/Makefile
EXTENSION = cartodb
EXTVERSION = 0.26.0
EXTVERSION = 0.26.1
SED = sed
AWK = awk
@@ -95,6 +95,7 @@ UPGRADABLE = \
0.24.1 \
0.25.0 \
0.26.0 \
0.26.1 \
$(EXTVERSION)dev \
$(EXTVERSION)next \
$(END)

View File

@@ -1,3 +1,6 @@
0.26.1 (2019-03-19)
* Remove default TIS values from Ghost tables functions
0.26.0 (2019-03-11)
* Use `ST_ShiftLongitude` instead of `ST_Shift_Longitude`.
* Add Ghost tables functions to install triggers and enqueue the linking process

View File

@@ -1,5 +1,5 @@
-- Enqueues a job to run Ghost tables linking process for the provided username
CREATE OR REPLACE FUNCTION _CDB_LinkGhostTables(username text, db_name text, event_name text)
CREATE OR REPLACE FUNCTION cartodb._CDB_LinkGhostTables(username text, db_name text, event_name text)
RETURNS void
AS $$
if not username:
@@ -12,9 +12,13 @@ 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:
plpy.warning('Invalidation service configuration not found. Skipping Ghost Tables linking.')
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)
@@ -30,7 +34,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:
@@ -40,43 +44,42 @@ 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;
-- Enqueues a job to run Ghost tables linking process for the current user
CREATE OR REPLACE FUNCTION CDB_LinkGhostTables(event_name text DEFAULT 'USER')
CREATE OR REPLACE FUNCTION cartodb.CDB_LinkGhostTables(event_name text DEFAULT 'USER')
RETURNS void
AS $$
DECLARE
username TEXT;
db_name TEXT;
BEGIN
EXECUTE 'SELECT CDB_Username();' INTO username;
EXECUTE 'SELECT cartodb.CDB_Username();' INTO username;
EXECUTE 'SELECT current_database();' INTO db_name;
PERFORM _CDB_LinkGhostTables(username, db_name, event_name);
PERFORM cartodb._CDB_LinkGhostTables(username, db_name, event_name);
RAISE NOTICE '_CDB_LinkGhostTables() called with username=%, event_name=%', username, event_name;
END;
$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE SECURITY DEFINER;
-- Trigger function to call CDB_LinkGhostTables()
CREATE OR REPLACE FUNCTION _CDB_LinkGhostTablesTrigger()
CREATE OR REPLACE FUNCTION cartodb._CDB_LinkGhostTablesTrigger()
RETURNS trigger
AS $$
DECLARE
ddl_tag TEXT;
BEGIN
EXECUTE 'SELECT tag FROM cartodb.cdb_ddl_execution WHERE txid = txid_current();' INTO ddl_tag;
DELETE FROM cartodb.cdb_ddl_execution WHERE txid = txid_current();
PERFORM CDB_LinkGhostTables(ddl_tag);
EXECUTE 'DELETE FROM cartodb.cdb_ddl_execution WHERE txid = txid_current() RETURNING tag;' INTO ddl_tag;
PERFORM cartodb.CDB_LinkGhostTables(ddl_tag);
RETURN NULL;
END;
$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE SECURITY DEFINER;
-- Event trigger to save the current transaction in cartodb.cdb_ddl_execution
CREATE OR REPLACE FUNCTION CDB_SaveDDLTransaction()
CREATE OR REPLACE FUNCTION cartodb.CDB_SaveDDLTransaction()
RETURNS event_trigger
AS $$
BEGIN
@@ -85,7 +88,7 @@ AS $$
$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE SECURITY DEFINER;
-- Creates the trigger on DDL events to link ghost tables
CREATE OR REPLACE FUNCTION CDB_EnableGhostTablesTrigger()
CREATE OR REPLACE FUNCTION cartodb.CDB_EnableGhostTablesTrigger()
RETURNS void
AS $$
BEGIN
@@ -99,17 +102,17 @@ AS $$
AFTER INSERT ON cartodb.cdb_ddl_execution
INITIALLY DEFERRED
FOR EACH ROW
EXECUTE PROCEDURE _CDB_LinkGhostTablesTrigger();
EXECUTE PROCEDURE cartodb._CDB_LinkGhostTablesTrigger();
CREATE EVENT TRIGGER link_ghost_tables
ON ddl_command_end
WHEN TAG IN ('CREATE TABLE', 'SELECT INTO', 'DROP TABLE', 'ALTER TABLE', 'CREATE TRIGGER', 'DROP TRIGGER', 'CREATE VIEW', 'DROP VIEW', 'ALTER VIEW')
EXECUTE PROCEDURE CDB_SaveDDLTransaction();
EXECUTE PROCEDURE cartodb.CDB_SaveDDLTransaction();
END;
$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE;
-- Drops the trigger on DDL events to link ghost tables
CREATE OR REPLACE FUNCTION CDB_DisableGhostTablesTrigger()
CREATE OR REPLACE FUNCTION cartodb.CDB_DisableGhostTablesTrigger()
RETURNS void
AS $$
BEGIN

View File

@@ -1,6 +1,6 @@
-- Returns the cartodb username of the current PostgreSQL session
CREATE OR REPLACE FUNCTION CDB_Username()
CREATE OR REPLACE FUNCTION cartodb.CDB_Username()
RETURNS text
AS $$
SELECT CDB_Conf_GetConf(CONCAT('api_keys_', session_user))->>'username';
SELECT cartodb.CDB_Conf_GetConf(CONCAT('api_keys_', session_user))->>'username';
$$ LANGUAGE SQL STABLE PARALLEL SAFE SECURITY DEFINER;

View File

@@ -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 (configuration not found)
-- Add TIS configuration
\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;

View File

@@ -1,5 +1,10 @@
WARNING: Invalidation Service error: Error -2 connecting fake-tis-host:3142. Name or service not known.
WARNING: Invalidation service configuration not found. Skipping Ghost Tables linking.
NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER
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
@@ -7,7 +12,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