From 81edbf670ebc571fdd3c31f531457686794e4521 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Wed, 30 Apr 2014 17:11:00 +0200 Subject: [PATCH] bdr: WIP: add more info to ddl queues --- contrib/bdr/bdr--0.5.sql | 43 ++++++++++++++++++++++++++++------------ contrib/bdr/bdr_apply.c | 8 ++++---- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/contrib/bdr/bdr--0.5.sql b/contrib/bdr/bdr--0.5.sql index f6554b614e..e69fd401ce 100644 --- a/contrib/bdr/bdr--0.5.sql +++ b/contrib/bdr/bdr--0.5.sql @@ -151,6 +151,8 @@ VALUES ( ); CREATE TABLE bdr_queued_commands ( + lsn pg_lsn NOT NULL, + queued_at timestamptz NOT NULL, obj_type text, obj_identity text, command text, @@ -167,14 +169,17 @@ BEGIN ident := quote_ident(TG_TABLE_SCHEMA)||'.'||quote_ident(TG_TABLE_NAME); - INSERT INTO bdr.bdr_queued_commands - (obj_type, obj_identity, command, executed) - VALUES - ('table', + INSERT INTO bdr.bdr_queued_commands ( + lsn, queued_at, + obj_type, obj_identity, command, executed + ) + VALUES ( + pg_current_xlog_location(), + NOW(), + 'table', ident, 'TRUNCATE TABLE ONLY ' || ident, 'false'); - RETURN NULL; END; $function$; @@ -203,10 +208,14 @@ BEGIN CONTINUE; END IF; - INSERT INTO bdr.bdr_queued_commands - (obj_type, obj_identity, command, executed) - VALUES - (r.object_type, + INSERT INTO bdr.bdr_queued_commands( + lsn, queued_at, + obj_type, obj_identity, command, executed + ) + VALUES ( + pg_current_xlog_location(), + NOW(), + r.object_type, r.identity, pg_catalog.pg_event_trigger_expand_command(r.command), 'false'); @@ -252,8 +261,11 @@ SELECT pg_catalog.pg_extension_config_dump('bdr_nodes', ''); CREATE TYPE bdr.dropped_object AS (objtype text, objnames text[], objargs text[]); -CREATE TABLE bdr.bdr_queued_drops - (dropped_objects bdr.dropped_object[] NOT NULL); +CREATE TABLE bdr.bdr_queued_drops( + lsn pg_lsn NOT NULL, + queued_at timestamptz NOT NULL, + dropped_objects bdr.dropped_object[] NOT NULL +); CREATE OR REPLACE FUNCTION bdr.queue_dropped_objects() RETURNS event_trigger @@ -276,8 +288,13 @@ BEGIN END LOOP; IF otherobjs <> '{}' THEN - INSERT INTO bdr.bdr_queued_drops - (dropped_objects) VALUES (otherobjs); + INSERT INTO bdr.bdr_queued_drops ( + lsn, queued_at, dropped_objects + ) + VALUES (pg_current_xlog_location(), + NOW(), + otherobjs + ); END IF; END; $function$; diff --git a/contrib/bdr/bdr_apply.c b/contrib/bdr/bdr_apply.c index 9980074a9d..759d1f904b 100644 --- a/contrib/bdr/bdr_apply.c +++ b/contrib/bdr/bdr_apply.c @@ -910,7 +910,7 @@ process_queued_ddl_command(HeapTuple cmdtup, bool tx_just_started) cmdsrel = heap_open(QueuedDDLCommandsRelid, NoLock); /* fetch the object type */ - datum = heap_getattr(cmdtup, 1, + datum = heap_getattr(cmdtup, 3, RelationGetDescr(cmdsrel), &isnull); if (isnull) @@ -919,7 +919,7 @@ process_queued_ddl_command(HeapTuple cmdtup, bool tx_just_started) type = TextDatumGetCString(datum); /* fetch the object identity */ - datum = heap_getattr(cmdtup, 2, + datum = heap_getattr(cmdtup, 4, RelationGetDescr(cmdsrel), &isnull); if (isnull) @@ -929,7 +929,7 @@ process_queued_ddl_command(HeapTuple cmdtup, bool tx_just_started) identstr = TextDatumGetCString(datum); /* finally fetch and execute the command */ - datum = heap_getattr(cmdtup, 3, + datum = heap_getattr(cmdtup, 5, RelationGetDescr(cmdsrel), &isnull); if (isnull) @@ -1024,7 +1024,7 @@ process_queued_drop(HeapTuple cmdtup) ObjectAddresses *addresses; cmdsrel = heap_open(QueuedDropsRelid, AccessShareLock); - arrayDatum = heap_getattr(cmdtup, 1, + arrayDatum = heap_getattr(cmdtup, 3, RelationGetDescr(cmdsrel), &null); if (null) -- 2.39.5