pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: movead.li@highgo.ca <movead.li@highgo.ca>
To: michael <michael@paquier.xyz>
Cc: pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: A patch for get origin from commit_ts.
Date: Wed, 13 May 2020 16:29:19 +0800
Message-ID: <2020051316291300911447@highgo.ca> (raw)
References: <2020051116430836450630@highgo.ca>
	<20200512014537.GF88791@paquier.xyz>


>I have not thought about this matter, but it seems to me that you
>should add this patch to the upcoming commit fest for evaluation:
>https://commitfest.postgresql.org/28/ 
Thanks.

I think about it more detailed, and find it's better to show the 'roident'
other than 'roname'. Because an old 'roident' value will be used
immediately after dropped, and a new patch attached with test case
and documentation.

============================================
SELECT pg_xact_commit_origin('490');
 pg_xact_commit_origin 
-----------------------
                     1
(1 row)

SELECT pg_xact_commit_origin('491');
 pg_xact_commit_origin 
-----------------------
                     2
(1 row)
============================================




Regards,
Highgo Software (Canada/China/Pakistan) 
URL : www.highgo.ca 
EMAIL: mailto:movead(dot)li(at)highgo(dot)ca


Attachments:

get_origin_from_commit_ts_v2.patch (application/octet-stream, 9.4K) download diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index d9b3598977..91e61337b7 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -23368,6 +23368,19 @@ SELECT collation for ('foo' COLLATE "de_DE"); </para></entry> </row> + <row> + <entry role="func_table_entry"><para role="func_signature"> + <indexterm> + <primary>pg_xact_commit_origin</primary> + </indexterm> + <function>pg_xact_commit_origin</function> () + <returnvalue>RepOriginId</returnvalue> + </para> + <para> + Returns the commit origin of a transaction. + </para></entry> + </row> + <row> <entry role="func_table_entry"><para role="func_signature"> <indexterm> diff --git a/src/backend/access/transam/commit_ts.c b/src/backend/access/transam/commit_ts.c index 630df672cc..113a81e80a 100644 --- a/src/backend/access/transam/commit_ts.c +++ b/src/backend/access/transam/commit_ts.c @@ -416,6 +416,26 @@ pg_xact_commit_timestamp(PG_FUNCTION_ARGS) PG_RETURN_TIMESTAMPTZ(ts); } +/* + * SQL-callable wrapper to obtain commit origin of a transaction + */ +Datum +pg_xact_commit_origin(PG_FUNCTION_ARGS) +{ + TransactionId xid = PG_GETARG_UINT32(0); + RepOriginId nodeid; + TimestampTz ts; + bool found; + + found = TransactionIdGetCommitTsData(xid, &ts, &nodeid); + + if (!found || (InvalidRepOriginId == nodeid)) + PG_RETURN_NULL(); + + PG_RETURN_OID((Oid)nodeid); +} + + Datum pg_last_committed_xact(PG_FUNCTION_ARGS) diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 4bce3ad8de..95d2ad3797 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -5945,6 +5945,12 @@ prorettype => 'timestamptz', proargtypes => 'xid', prosrc => 'pg_xact_commit_timestamp' }, +{ oid => '3435', descr => 'get commit origin of a transaction', + proname => 'pg_xact_commit_origin', provolatile => 'v', + prorettype => 'oid', proargtypes => 'xid', + prosrc => 'pg_xact_commit_origin' }, + + { oid => '3583', descr => 'get transaction Id and commit timestamp of latest transaction commit', proname => 'pg_last_committed_xact', provolatile => 'v', diff --git a/src/test/modules/commit_ts/expected/commit_timestamp.out b/src/test/modules/commit_ts/expected/commit_timestamp.out index 5b7783b58f..a50e6420fb 100644 --- a/src/test/modules/commit_ts/expected/commit_timestamp.out +++ b/src/test/modules/commit_ts/expected/commit_timestamp.out @@ -45,3 +45,96 @@ SELECT x.xid::text::bigint > 0, x.timestamp > '-infinity'::timestamptz, x.timest t | t | t (1 row) +SELECT pg_replication_origin_create('test_commit_ts: get_origin_1'); + pg_replication_origin_create +------------------------------ + 1 +(1 row) + +SELECT pg_replication_origin_create('test_commit_ts: get_origin_2'); + pg_replication_origin_create +------------------------------ + 2 +(1 row) + +SELECT pg_replication_origin_create('test_commit_ts: get_origin_3'); + pg_replication_origin_create +------------------------------ + 3 +(1 row) + +SELECT pg_replication_origin_session_setup('test_commit_ts: get_origin_1'); + pg_replication_origin_session_setup +------------------------------------- + +(1 row) + +SELECT txid_current() as txid \gset +SELECT pg_xact_commit_origin(:'txid'); + pg_xact_commit_origin +----------------------- + 1 +(1 row) + +SELECT pg_replication_origin_session_reset(); + pg_replication_origin_session_reset +------------------------------------- + +(1 row) + +SELECT pg_replication_origin_session_setup('test_commit_ts: get_origin_2'); + pg_replication_origin_session_setup +------------------------------------- + +(1 row) + +SELECT txid_current() as txid \gset +SELECT pg_xact_commit_origin(:'txid'); + pg_xact_commit_origin +----------------------- + 2 +(1 row) + +SELECT pg_replication_origin_session_reset(); + pg_replication_origin_session_reset +------------------------------------- + +(1 row) + +SELECT pg_replication_origin_session_setup('test_commit_ts: get_origin_3'); + pg_replication_origin_session_setup +------------------------------------- + +(1 row) + +SELECT txid_current() as txid \gset +SELECT pg_xact_commit_origin(:'txid'); + pg_xact_commit_origin +----------------------- + 3 +(1 row) + +SELECT pg_replication_origin_session_reset(); + pg_replication_origin_session_reset +------------------------------------- + +(1 row) + +SELECT pg_replication_origin_drop('test_commit_ts: get_origin_1'); + pg_replication_origin_drop +---------------------------- + +(1 row) + +SELECT pg_replication_origin_drop('test_commit_ts: get_origin_2'); + pg_replication_origin_drop +---------------------------- + +(1 row) + +SELECT pg_replication_origin_drop('test_commit_ts: get_origin_3'); + pg_replication_origin_drop +---------------------------- + +(1 row) + diff --git a/src/test/modules/commit_ts/expected/commit_timestamp_1.out b/src/test/modules/commit_ts/expected/commit_timestamp_1.out index c10b0abc2b..db5d4ebcc0 100644 --- a/src/test/modules/commit_ts/expected/commit_timestamp_1.out +++ b/src/test/modules/commit_ts/expected/commit_timestamp_1.out @@ -37,3 +37,87 @@ SELECT pg_xact_commit_timestamp('2'::xid); SELECT x.xid::text::bigint > 0, x.timestamp > '-infinity'::timestamptz, x.timestamp <= now() FROM pg_last_committed_xact() x; ERROR: could not get commit timestamp data HINT: Make sure the configuration parameter "track_commit_timestamp" is set. +SELECT pg_replication_origin_create('test_commit_ts: get_origin_1'); + pg_replication_origin_create +------------------------------ + 1 +(1 row) + +SELECT pg_replication_origin_create('test_commit_ts: get_origin_2'); + pg_replication_origin_create +------------------------------ + 2 +(1 row) + +SELECT pg_replication_origin_create('test_commit_ts: get_origin_3'); + pg_replication_origin_create +------------------------------ + 3 +(1 row) + +SELECT pg_replication_origin_session_setup('test_commit_ts: get_origin_1'); + pg_replication_origin_session_setup +------------------------------------- + +(1 row) + +SELECT txid_current() as txid \gset +SELECT pg_xact_commit_origin(:'txid'); +ERROR: could not get commit timestamp data +HINT: Make sure the configuration parameter "track_commit_timestamp" is set. +SELECT pg_replication_origin_session_reset(); + pg_replication_origin_session_reset +------------------------------------- + +(1 row) + +SELECT pg_replication_origin_session_setup('test_commit_ts: get_origin_2'); + pg_replication_origin_session_setup +------------------------------------- + +(1 row) + +SELECT txid_current() as txid \gset +SELECT pg_xact_commit_origin(:'txid'); +ERROR: could not get commit timestamp data +HINT: Make sure the configuration parameter "track_commit_timestamp" is set. +SELECT pg_replication_origin_session_reset(); + pg_replication_origin_session_reset +------------------------------------- + +(1 row) + +SELECT pg_replication_origin_session_setup('test_commit_ts: get_origin_3'); + pg_replication_origin_session_setup +------------------------------------- + +(1 row) + +SELECT txid_current() as txid \gset +SELECT pg_xact_commit_origin(:'txid'); +ERROR: could not get commit timestamp data +HINT: Make sure the configuration parameter "track_commit_timestamp" is set. +SELECT pg_replication_origin_session_reset(); + pg_replication_origin_session_reset +------------------------------------- + +(1 row) + +SELECT pg_replication_origin_drop('test_commit_ts: get_origin_1'); + pg_replication_origin_drop +---------------------------- + +(1 row) + +SELECT pg_replication_origin_drop('test_commit_ts: get_origin_2'); + pg_replication_origin_drop +---------------------------- + +(1 row) + +SELECT pg_replication_origin_drop('test_commit_ts: get_origin_3'); + pg_replication_origin_drop +---------------------------- + +(1 row) + diff --git a/src/test/modules/commit_ts/sql/commit_timestamp.sql b/src/test/modules/commit_ts/sql/commit_timestamp.sql index 4e041a5347..ba7ccfda42 100644 --- a/src/test/modules/commit_ts/sql/commit_timestamp.sql +++ b/src/test/modules/commit_ts/sql/commit_timestamp.sql @@ -22,3 +22,27 @@ SELECT pg_xact_commit_timestamp('1'::xid); SELECT pg_xact_commit_timestamp('2'::xid); SELECT x.xid::text::bigint > 0, x.timestamp > '-infinity'::timestamptz, x.timestamp <= now() FROM pg_last_committed_xact() x; + +SELECT pg_replication_origin_create('test_commit_ts: get_origin_1'); +SELECT pg_replication_origin_create('test_commit_ts: get_origin_2'); +SELECT pg_replication_origin_create('test_commit_ts: get_origin_3'); + + +SELECT pg_replication_origin_session_setup('test_commit_ts: get_origin_1'); +SELECT txid_current() as txid \gset +SELECT pg_xact_commit_origin(:'txid'); +SELECT pg_replication_origin_session_reset(); + +SELECT pg_replication_origin_session_setup('test_commit_ts: get_origin_2'); +SELECT txid_current() as txid \gset +SELECT pg_xact_commit_origin(:'txid'); +SELECT pg_replication_origin_session_reset(); + +SELECT pg_replication_origin_session_setup('test_commit_ts: get_origin_3'); +SELECT txid_current() as txid \gset +SELECT pg_xact_commit_origin(:'txid'); +SELECT pg_replication_origin_session_reset(); + +SELECT pg_replication_origin_drop('test_commit_ts: get_origin_1'); +SELECT pg_replication_origin_drop('test_commit_ts: get_origin_2'); +SELECT pg_replication_origin_drop('test_commit_ts: get_origin_3');

view thread (31+ messages)  latest in thread

Message-ID: <2020051316291300911447@highgo.ca>
Permalink:  ../2020051316291300911447@highgo.ca/
Also on:    postgresql.org/message-id/2020051316291300911447@highgo.ca

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: movead.li@highgo.ca, michael@paquier.xyz, pgsql-hackers@lists.postgresql.org
  Subject: Re: A patch for get origin from commit_ts.
  In-Reply-To: <2020051316291300911447@highgo.ca>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox