summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Kreen2007-10-12 09:39:07 +0000
committerMarko Kreen2007-10-12 09:39:07 +0000
commitf697dbe89b47e3c6b07a03243a5e119c757569f5 (patch)
tree9231548457394aa972dc103af9f7a202f17c2d80
parent04a765ce990a9c8b382ec001e4adc50354663023 (diff)
convert to new txid interface apperaing in 8.3
-rw-r--r--python/londiste/installer.py2
-rw-r--r--python/londiste/table_copy.py2
-rw-r--r--python/pgq/ticker.py2
-rwxr-xr-xpython/pgqadm.py2
-rw-r--r--sql/pgq/functions/pgq.batch_event_sql.sql16
-rw-r--r--sql/pgq/functions/pgq.batch_event_tables.sql4
-rw-r--r--sql/pgq/functions/pgq.maint_rotate_tables.sql8
-rw-r--r--sql/pgq/structure/tables.sql8
-rw-r--r--sql/txid/Makefile44
-rw-r--r--sql/txid/README.txid16
-rw-r--r--sql/txid/expected/txid.out69
-rw-r--r--sql/txid/sql/txid.sql17
-rw-r--r--sql/txid/txid.c120
-rw-r--r--sql/txid/txid.h10
-rw-r--r--sql/txid/txid.std.sql38
-rw-r--r--sql/txid/uninstall_txid.sql5
16 files changed, 252 insertions, 111 deletions
diff --git a/python/londiste/installer.py b/python/londiste/installer.py
index c4e51b9d..e76cdb20 100644
--- a/python/londiste/installer.py
+++ b/python/londiste/installer.py
@@ -7,7 +7,7 @@ __all__ = ['install_provider', 'install_subscriber']
provider_object_list = [
skytools.DBLanguage("plpgsql"),
- skytools.DBFunction('get_current_snapshot', 0, sql_file = "txid.sql"),
+ skytools.DBFunction('txid_current_snapshot', 0, sql_file = "txid.sql"),
skytools.DBSchema('pgq', sql_file = "pgq.sql"),
skytools.DBSchema('londiste', sql_file = "londiste.sql")
]
diff --git a/python/londiste/table_copy.py b/python/londiste/table_copy.py
index aa99e376..5e21483a 100644
--- a/python/londiste/table_copy.py
+++ b/python/londiste/table_copy.py
@@ -59,7 +59,7 @@ class CopyTable(Replicator):
self.real_copy(src_curs, dst_curs, tbl_stat)
# get snapshot
- src_curs.execute("select get_current_snapshot()")
+ src_curs.execute("select txid_current_snapshot()")
snapshot = src_curs.fetchone()[0]
src_db.commit()
diff --git a/python/pgq/ticker.py b/python/pgq/ticker.py
index a9d6190c..bff59214 100644
--- a/python/pgq/ticker.py
+++ b/python/pgq/ticker.py
@@ -11,7 +11,7 @@ from maint import MaintenanceJob
__all__ = ['SmartTicker']
def is_txid_sane(curs):
- curs.execute("select get_current_txid()")
+ curs.execute("select txid_current()")
txid = curs.fetchone()[0]
# on 8.2 theres no such table
diff --git a/python/pgqadm.py b/python/pgqadm.py
index e732bea0..07c7aa01 100755
--- a/python/pgqadm.py
+++ b/python/pgqadm.py
@@ -85,7 +85,7 @@ class PGQAdmin(skytools.DBScript):
def installer(self):
objs = [
skytools.DBLanguage("plpgsql"),
- skytools.DBFunction("get_current_txid", 0, sql_file="txid.sql"),
+ skytools.DBFunction("txid_current_snapshot", 0, sql_file="txid.sql"),
skytools.DBSchema("pgq", sql_file="pgq.sql"),
]
diff --git a/sql/pgq/functions/pgq.batch_event_sql.sql b/sql/pgq/functions/pgq.batch_event_sql.sql
index 2c0588fe..043a3caa 100644
--- a/sql/pgq/functions/pgq.batch_event_sql.sql
+++ b/sql/pgq/functions/pgq.batch_event_sql.sql
@@ -19,8 +19,8 @@ returns text as $$
--
-- Simplest solution would be
-- > WHERE ev_txid >= xmin1 AND ev_txid <= xmax2
--- > AND NOT txid_in_snapshot(ev_txid, sn1)
--- > AND txid_in_snapshot(ev_txid, sn2)
+-- > AND NOT txid_visible_in_snapshot(ev_txid, sn1)
+-- > AND txid_visible_in_snapshot(ev_txid, sn2)
--
-- The simple solution has a problem with long transactions (xmin1 very low).
-- All the batches that happen when the long tx is active will need
@@ -48,8 +48,8 @@ declare
batch record;
begin
select s.sub_last_tick, s.sub_next_tick, s.sub_id, s.sub_queue,
- get_snapshot_xmax(last.tick_snapshot) as tx_start,
- get_snapshot_xmax(cur.tick_snapshot) as tx_end,
+ txid_snapshot_xmax(last.tick_snapshot) as tx_start,
+ txid_snapshot_xmax(cur.tick_snapshot) as tx_end,
last.tick_snapshot as last_snapshot,
cur.tick_snapshot as cur_snapshot
into batch
@@ -68,8 +68,8 @@ begin
for rec in
-- active tx-es in prev_snapshot that were committed in cur_snapshot
select id1 from
- get_snapshot_active(batch.last_snapshot) id1 left join
- get_snapshot_active(batch.cur_snapshot) id2 on (id1 = id2)
+ txid_snapshot_xip(batch.last_snapshot) id1 left join
+ txid_snapshot_xip(batch.cur_snapshot) id2 on (id1 = id2)
where id2 is null
order by 1 desc
loop
@@ -107,8 +107,8 @@ begin
|| ' and last.tick_queue = ' || batch.sub_queue
|| ' and ev.ev_txid >= ' || batch.tx_start
|| ' and ev.ev_txid <= ' || batch.tx_end
- || ' and txid_in_snapshot(ev.ev_txid, cur.tick_snapshot)'
- || ' and not txid_in_snapshot(ev.ev_txid, last.tick_snapshot)'
+ || ' and txid_visible_in_snapshot(ev.ev_txid, cur.tick_snapshot)'
+ || ' and not txid_visible_in_snapshot(ev.ev_txid, last.tick_snapshot)'
|| retry_expr;
-- now include older tx-es, that were ongoing
-- at the time of prev_snapshot
diff --git a/sql/pgq/functions/pgq.batch_event_tables.sql b/sql/pgq/functions/pgq.batch_event_tables.sql
index f6bdc309..fd8cbd65 100644
--- a/sql/pgq/functions/pgq.batch_event_tables.sql
+++ b/sql/pgq/functions/pgq.batch_event_tables.sql
@@ -16,8 +16,8 @@ declare
batch record;
begin
select
- get_snapshot_xmin(last.tick_snapshot) as tx_min, -- absolute minimum
- get_snapshot_xmax(cur.tick_snapshot) as tx_max, -- absolute maximum
+ txid_snapshot_xmin(last.tick_snapshot) as tx_min, -- absolute minimum
+ txid_snapshot_xmax(cur.tick_snapshot) as tx_max, -- absolute maximum
q.queue_data_pfx, q.queue_ntables,
q.queue_cur_table, q.queue_switch_step1, q.queue_switch_step2
into batch
diff --git a/sql/pgq/functions/pgq.maint_rotate_tables.sql b/sql/pgq/functions/pgq.maint_rotate_tables.sql
index f9d12367..b52a5025 100644
--- a/sql/pgq/functions/pgq.maint_rotate_tables.sql
+++ b/sql/pgq/functions/pgq.maint_rotate_tables.sql
@@ -31,7 +31,7 @@ begin
-- check if any consumer is on previous table
select coalesce(count(*), 0) into badcnt
from pgq.subscription, pgq.tick
- where get_snapshot_xmin(tick_snapshot) < cf.queue_switch_step2
+ where txid_snapshot_xmin(tick_snapshot) < cf.queue_switch_step2
and sub_queue = cf.queue_id
and tick_queue = cf.queue_id
and tick_id = (select tick_id from pgq.tick
@@ -65,14 +65,14 @@ begin
update pgq.queue
set queue_cur_table = nr,
queue_switch_time = current_timestamp,
- queue_switch_step1 = get_current_txid(),
+ queue_switch_step1 = txid_current(),
queue_switch_step2 = NULL
where queue_id = cf.queue_id;
-- clean ticks - avoid partial batches
delete from pgq.tick
where tick_queue = cf.queue_id
- and get_snapshot_xmin(tick_snapshot) < cf.queue_switch_step2;
+ and txid_snapshot_xmin(tick_snapshot) < cf.queue_switch_step2;
return 1;
end;
@@ -90,7 +90,7 @@ returns integer as $$
-- tranaction than step1
begin
update pgq.queue
- set queue_switch_step2 = get_current_txid()
+ set queue_switch_step2 = txid_current()
where queue_switch_step2 is null;
return 1;
end;
diff --git a/sql/pgq/structure/tables.sql b/sql/pgq/structure/tables.sql
index 83e23d3b..57e749c1 100644
--- a/sql/pgq/structure/tables.sql
+++ b/sql/pgq/structure/tables.sql
@@ -73,8 +73,8 @@ create table pgq.queue (
queue_ntables integer not null default 3,
queue_cur_table integer not null default 0,
queue_rotation_period interval not null default '2 hours',
- queue_switch_step1 bigint not null default get_current_txid(),
- queue_switch_step2 bigint default get_current_txid(),
+ queue_switch_step1 bigint not null default txid_current(),
+ queue_switch_step2 bigint default txid_current(),
queue_switch_time timestamptz not null default now(),
queue_external_ticker boolean not null default false,
@@ -105,7 +105,7 @@ create table pgq.tick (
tick_queue int4 not null,
tick_id bigint not null,
tick_time timestamptz not null default now(),
- tick_snapshot txid_snapshot not null default get_current_snapshot(),
+ tick_snapshot txid_snapshot not null default txid_current_snapshot(),
constraint tick_pkey primary key (tick_queue, tick_id),
constraint tick_queue_fkey foreign key (tick_queue)
@@ -173,7 +173,7 @@ create table pgq.event_template (
ev_id bigint not null,
ev_time timestamptz not null,
- ev_txid bigint not null default get_current_txid(),
+ ev_txid bigint not null default txid_current(),
ev_owner int4,
ev_retry int4,
diff --git a/sql/txid/Makefile b/sql/txid/Makefile
index 64b2c106..d3e25b8f 100644
--- a/sql/txid/Makefile
+++ b/sql/txid/Makefile
@@ -1,30 +1,50 @@
+include ../../config.mak
+
+PGVER := $(shell $(PG_CONFIG) --version | sed 's/PostgreSQL //')
+
+ifeq ($(PGVER),)
+$(error skytools not configured, cannot continue)
+else
+# postgres >= manages epoch itself, so skip epoch tables
+pg83 = $(shell test $(PGVER) "<" "8.3" && echo "false" || echo "true")
+pg82 = $(shell test $(PGVER) "<" "8.2" && echo "false" || echo "true")
+endif
+
+ifeq ($(pg83),true) # we have 8.3 with internal txid
+
+# nothing to do
+
+else # 8.2 or 8.1
+#
+# pg < 8.3 needs this module
+#
MODULE_big = txid
SRCS = txid.c epoch.c
OBJS = $(SRCS:.c=.o)
-
-DATA_built = txid.sql
+REGRESS = txid
+REGRESS_OPTS = --load-language=plpgsql
DATA = uninstall_txid.sql
DOCS = README.txid
+DATA_built = txid.sql
EXTRA_CLEAN = txid.sql.in
-REGRESS = txid
-REGRESS_OPTS = --load-language=plpgsql
+ifeq ($(pg82),true)
+# 8.2 tracks epoch internally
+TXID_SQL = txid.std.sql
+else
+# 8.1 needs epoch-tracking code
+TXID_SQL = txid.std.sql txid.schema.sql
+endif # ! 8.2
+endif # ! 8.3
-include ../../config.mak
+# PGXS build procedure
include $(PGXS)
# additional deps
txid.o: txid.h
epoch.o: txid.h
-# postgres >= manages epoch itself, so skip epoch tables
-pgnew = $(shell test $(VERSION) "<" "8.2" && echo "false" || echo "true")
-ifeq ($(pgnew),true)
-TXID_SQL = txid.std.sql
-else
-TXID_SQL = txid.std.sql txid.schema.sql
-endif
txid.sql.in: $(TXID_SQL)
cat $(TXID_SQL) > $@
diff --git a/sql/txid/README.txid b/sql/txid/README.txid
index 6cdac28a..1a46a748 100644
--- a/sql/txid/README.txid
+++ b/sql/txid/README.txid
@@ -17,37 +17,33 @@ read-write access - ca. after 100k - 500k transactions.
Also it contains type 'txid_snapshot' and following functions:
-get_current_txid() returns int8
+txid_current() returns int8
Current transaction ID
-get_current_snapshot() returns txid_snapshot
+txid_current_snapshot() returns txid_snapshot
Current snapshot
-get_snapshot_xmin( snap ) returns int8 --
+txid_snapshot_xmin( snap ) returns int8
Smallest TXID in snapshot. TXID's smaller than this
are all visible in snapshot.
-get_snapshot_xmax( snap ) returns int8
+txid_snapshot_xmax( snap ) returns int8
Largest TXID in snapshot. TXID's starting from this one are
all invisible in snapshot.
-get_snapshot_values( snap ) setof int8
+txid_snapshot_xip( snap ) setof int8
List of uncommitted TXID's in snapshot, that are invisible
in snapshot. Values are between xmin and xmax.
-txid_in_snapshot(id, snap) returns bool
+txid_visible_in_snapshot(id, snap) returns bool
Is TXID visible in snapshot?
-txid_not_in_snapshot(id, snap) returns bool
-
- Is TXID invisible in snapshot?
-
Problems
--------
diff --git a/sql/txid/expected/txid.out b/sql/txid/expected/txid.out
index 400f88c2..7b394449 100644
--- a/sql/txid/expected/txid.out
+++ b/sql/txid/expected/txid.out
@@ -33,56 +33,45 @@ select snap from snapshot_test order by nr;
100001:100009:100005,100007,100008
(3 rows)
-select get_snapshot_xmin(snap),
- get_snapshot_xmax(snap),
- get_snapshot_active(snap)
+select txid_snapshot_xmin(snap),
+ txid_snapshot_xmax(snap),
+ txid_snapshot_xip(snap)
from snapshot_test order by nr;
- get_snapshot_xmin | get_snapshot_xmax | get_snapshot_active
--------------------+-------------------+---------------------
- 12 | 20 | 13
- 12 | 20 | 15
- 12 | 20 | 18
- 100001 | 100009 | 100005
- 100001 | 100009 | 100007
- 100001 | 100009 | 100008
+ txid_snapshot_xmin | txid_snapshot_xmax | txid_snapshot_xip
+--------------------+--------------------+-------------------
+ 12 | 20 | 13
+ 12 | 20 | 15
+ 12 | 20 | 18
+ 100001 | 100009 | 100005
+ 100001 | 100009 | 100007
+ 100001 | 100009 | 100008
(6 rows)
-select id, txid_in_snapshot(id, snap),
- txid_not_in_snapshot(id, snap)
+select id, txid_visible_in_snapshot(id, snap)
from snapshot_test, generate_series(11, 21) id
where nr = 2;
- id | txid_in_snapshot | txid_not_in_snapshot
-----+------------------+----------------------
- 11 | t | f
- 12 | t | f
- 13 | f | t
- 14 | t | f
- 15 | f | t
- 16 | t | f
- 17 | t | f
- 18 | f | t
- 19 | t | f
- 20 | f | t
- 21 | f | t
+ id | txid_visible_in_snapshot
+----+--------------------------
+ 11 | t
+ 12 | t
+ 13 | f
+ 14 | t
+ 15 | f
+ 16 | t
+ 17 | t
+ 18 | f
+ 19 | t
+ 20 | f
+ 21 | f
(11 rows)
-- test current values also
-select get_current_txid() >= get_snapshot_xmin(get_current_snapshot());
+select txid_current() >= txid_snapshot_xmin(txid_current_snapshot());
?column?
----------
t
(1 row)
-select get_current_txid() < get_snapshot_xmax(get_current_snapshot());
- ?column?
-----------
- t
-(1 row)
-
-select txid_in_snapshot(get_current_txid(), get_current_snapshot()),
- txid_not_in_snapshot(get_current_txid(), get_current_snapshot());
- txid_in_snapshot | txid_not_in_snapshot
-------------------+----------------------
- t | f
-(1 row)
-
+-- select txid_current_txid() < txid_snapshot_xmax(txid_current_snapshot());
+-- select txid_in_snapshot(txid_current_txid(), txid_current_snapshot()),
+-- txid_not_in_snapshot(txid_current_txid(), txid_current_snapshot());
diff --git a/sql/txid/sql/txid.sql b/sql/txid/sql/txid.sql
index 6009944b..72b52d44 100644
--- a/sql/txid/sql/txid.sql
+++ b/sql/txid/sql/txid.sql
@@ -24,20 +24,19 @@ insert into snapshot_test values (3, '100001:100009:100005,100007,100008');
select snap from snapshot_test order by nr;
-select get_snapshot_xmin(snap),
- get_snapshot_xmax(snap),
- get_snapshot_active(snap)
+select txid_snapshot_xmin(snap),
+ txid_snapshot_xmax(snap),
+ txid_snapshot_xip(snap)
from snapshot_test order by nr;
-select id, txid_in_snapshot(id, snap),
- txid_not_in_snapshot(id, snap)
+select id, txid_visible_in_snapshot(id, snap)
from snapshot_test, generate_series(11, 21) id
where nr = 2;
-- test current values also
-select get_current_txid() >= get_snapshot_xmin(get_current_snapshot());
-select get_current_txid() < get_snapshot_xmax(get_current_snapshot());
+select txid_current() >= txid_snapshot_xmin(txid_current_snapshot());
+-- select txid_current_txid() < txid_snapshot_xmax(txid_current_snapshot());
-select txid_in_snapshot(get_current_txid(), get_current_snapshot()),
- txid_not_in_snapshot(get_current_txid(), get_current_snapshot());
+-- select txid_in_snapshot(txid_current_txid(), txid_current_snapshot()),
+-- txid_not_in_snapshot(txid_current_txid(), txid_current_snapshot());
diff --git a/sql/txid/txid.c b/sql/txid/txid.c
index 13dabfd9..75232142 100644
--- a/sql/txid/txid.c
+++ b/sql/txid/txid.c
@@ -17,6 +17,7 @@
#include "access/xact.h"
#include "funcapi.h"
#include "lib/stringinfo.h"
+#include "libpq/pqformat.h"
#include "txid.h"
@@ -32,6 +33,9 @@ PG_MODULE_MAGIC;
#define SET_VARSIZE(x, len) VARATT_SIZEP(x) = len
#endif
+/* txid will be signed int8 in database, so must limit to 63 bits */
+#define MAX_TXID UINT64CONST(0x7FFFFFFFFFFFFFFF)
+
/*
* If defined, use bsearch() function for searching
* txid's inside snapshots that have more than given values.
@@ -46,11 +50,19 @@ PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(txid_current);
PG_FUNCTION_INFO_V1(txid_snapshot_in);
PG_FUNCTION_INFO_V1(txid_snapshot_out);
-PG_FUNCTION_INFO_V1(txid_in_snapshot);
-PG_FUNCTION_INFO_V1(txid_not_in_snapshot);
+PG_FUNCTION_INFO_V1(txid_snapshot_recv);
+PG_FUNCTION_INFO_V1(txid_snapshot_send);
PG_FUNCTION_INFO_V1(txid_current_snapshot);
PG_FUNCTION_INFO_V1(txid_snapshot_xmin);
PG_FUNCTION_INFO_V1(txid_snapshot_xmax);
+
+/* new API in 8.3 */
+PG_FUNCTION_INFO_V1(txid_visible_in_snapshot);
+PG_FUNCTION_INFO_V1(txid_snapshot_xip);
+
+/* old API */
+PG_FUNCTION_INFO_V1(txid_in_snapshot);
+PG_FUNCTION_INFO_V1(txid_not_in_snapshot);
PG_FUNCTION_INFO_V1(txid_snapshot_active);
/*
@@ -254,6 +266,85 @@ txid_snapshot_out(PG_FUNCTION_ARGS)
PG_RETURN_CSTRING(str.data);
}
+/*
+ * txid_snapshot_recv(internal) returns txid_snapshot
+ *
+ * binary input function for type txid_snapshot
+ *
+ * format: int4 nxip, int8 xmin, int8 xmax, int8 xip
+ */
+Datum
+txid_snapshot_recv(PG_FUNCTION_ARGS)
+{
+ StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
+ TxidSnapshot *snap;
+ txid last = 0;
+ int nxip;
+ int i;
+ int avail;
+ int expect;
+ txid xmin, xmax;
+
+ /*
+ * load nxip and check for nonsense.
+ *
+ * (nxip > avail) check is against int overflows in 'expect'.
+ */
+ nxip = pq_getmsgint(buf, 4);
+ avail = buf->len - buf->cursor;
+ expect = 8 + 8 + nxip * 8;
+ if (nxip < 0 || nxip > avail || expect > avail)
+ goto bad_format;
+
+ xmin = pq_getmsgint64(buf);
+ xmax = pq_getmsgint64(buf);
+ if (xmin == 0 || xmax == 0 || xmin > xmax || xmax > MAX_TXID)
+ goto bad_format;
+
+ snap = palloc(TXID_SNAPSHOT_SIZE(nxip));
+ snap->xmin = xmin;
+ snap->xmax = xmax;
+ snap->nxip = nxip;
+ SET_VARSIZE(snap, TXID_SNAPSHOT_SIZE(nxip));
+
+ for (i = 0; i < nxip; i++)
+ {
+ txid cur = pq_getmsgint64(buf);
+ if (cur <= last || cur < xmin || cur >= xmax)
+ goto bad_format;
+ snap->xip[i] = cur;
+ last = cur;
+ }
+ PG_RETURN_POINTER(snap);
+
+bad_format:
+ elog(ERROR, "invalid snapshot data");
+ return (Datum)NULL;
+}
+
+/*
+ * txid_snapshot_send(txid_snapshot) returns bytea
+ *
+ * binary output function for type txid_snapshot
+ *
+ * format: int4 nxip, int8 xmin, int8 xmax, int8 xip
+ */
+Datum
+txid_snapshot_send(PG_FUNCTION_ARGS)
+{
+ TxidSnapshot *snap = (TxidSnapshot *)PG_GETARG_VARLENA_P(0);
+ StringInfoData buf;
+ uint32 i;
+
+ pq_begintypsend(&buf);
+ pq_sendint(&buf, snap->nxip, 4);
+ pq_sendint64(&buf, snap->xmin);
+ pq_sendint64(&buf, snap->xmax);
+ for (i = 0; i < snap->nxip; i++)
+ pq_sendint64(&buf, snap->xip[i]);
+ PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
+}
+
static int
_txid_in_snapshot(txid value, const TxidSnapshot *snap)
@@ -298,6 +389,22 @@ txid_in_snapshot(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(res);
}
+/*
+ * changed api
+ */
+Datum
+txid_visible_in_snapshot(PG_FUNCTION_ARGS)
+{
+ txid value = PG_GETARG_INT64(0);
+ TxidSnapshot *snap = (TxidSnapshot *) PG_GETARG_VARLENA_P(1);
+ int res;
+
+ res = _txid_in_snapshot(value, snap) ? true : false;
+
+ PG_FREE_IF_COPY(snap, 1);
+ PG_RETURN_BOOL(res);
+}
+
/*
* txid_not_in_snapshot - is txid invisible in snapshot ?
@@ -349,7 +456,7 @@ struct snap_state {
* txid_snapshot_active - returns uncommitted TXID's in snapshot.
*/
Datum
-txid_snapshot_active(PG_FUNCTION_ARGS)
+txid_snapshot_xip(PG_FUNCTION_ARGS)
{
FuncCallContext *fctx;
struct snap_state *state;
@@ -381,3 +488,10 @@ txid_snapshot_active(PG_FUNCTION_ARGS)
}
}
+/* old api */
+Datum
+txid_snapshot_active(PG_FUNCTION_ARGS)
+{
+ return txid_snapshot_xip(fcinfo);
+}
+
diff --git a/sql/txid/txid.h b/sql/txid/txid.h
index b2536a77..5cd481d7 100644
--- a/sql/txid/txid.h
+++ b/sql/txid/txid.h
@@ -15,6 +15,7 @@ typedef struct
txid xip[1];
} TxidSnapshot;
+#define TXID_SNAPSHOT_SIZE(nxip) (offsetof(TxidSnapshot, xip) + sizeof(txid) * nxip)
typedef struct {
uint64 last_value;
@@ -31,12 +32,17 @@ Datum txid_current_snapshot(PG_FUNCTION_ARGS);
Datum txid_snapshot_in(PG_FUNCTION_ARGS);
Datum txid_snapshot_out(PG_FUNCTION_ARGS);
+Datum txid_snapshot_recv(PG_FUNCTION_ARGS);
+Datum txid_snapshot_send(PG_FUNCTION_ARGS);
-Datum txid_in_snapshot(PG_FUNCTION_ARGS);
-Datum txid_not_in_snapshot(PG_FUNCTION_ARGS);
Datum txid_snapshot_xmin(PG_FUNCTION_ARGS);
Datum txid_snapshot_xmax(PG_FUNCTION_ARGS);
+Datum txid_snapshot_xip(PG_FUNCTION_ARGS);
+Datum txid_visible_in_snapshot(PG_FUNCTION_ARGS);
+
Datum txid_snapshot_active(PG_FUNCTION_ARGS);
+Datum txid_in_snapshot(PG_FUNCTION_ARGS);
+Datum txid_not_in_snapshot(PG_FUNCTION_ARGS);
#endif /* _TXID_H_ */
diff --git a/sql/txid/txid.std.sql b/sql/txid/txid.std.sql
index 8ba34cbc..574e2e5c 100644
--- a/sql/txid/txid.std.sql
+++ b/sql/txid/txid.std.sql
@@ -23,6 +23,14 @@ CREATE OR REPLACE FUNCTION txid_snapshot_out(txid_snapshot)
RETURNS cstring
AS 'MODULE_PATHNAME' LANGUAGE C
IMMUTABLE STRICT;
+CREATE OR REPLACE FUNCTION txid_snapshot_recv(internal)
+ RETURNS txid_snapshot
+ AS 'MODULE_PATHNAME' LANGUAGE C
+ IMMUTABLE STRICT;
+CREATE OR REPLACE FUNCTION txid_snapshot_send(txid_snapshot)
+ RETURNS bytea
+ AS 'MODULE_PATHNAME' LANGUAGE C
+ IMMUTABLE STRICT;
--
-- The data type itself
@@ -30,34 +38,41 @@ CREATE OR REPLACE FUNCTION txid_snapshot_out(txid_snapshot)
CREATE TYPE txid_snapshot (
INPUT = txid_snapshot_in,
OUTPUT = txid_snapshot_out,
+ RECEIVE = txid_snapshot_recv,
+ SEND = txid_snapshot_send,
INTERNALLENGTH = variable,
STORAGE = extended,
ALIGNMENT = double
);
-CREATE OR REPLACE FUNCTION get_current_txid()
+--CREATE OR REPLACE FUNCTION get_current_txid()
+CREATE OR REPLACE FUNCTION txid_current()
RETURNS bigint
AS 'MODULE_PATHNAME', 'txid_current' LANGUAGE C
- SECURITY DEFINER;
+ STABLE SECURITY DEFINER;
-CREATE OR REPLACE FUNCTION get_current_snapshot()
+-- CREATE OR REPLACE FUNCTION get_current_snapshot()
+CREATE OR REPLACE FUNCTION txid_current_snapshot()
RETURNS txid_snapshot
AS 'MODULE_PATHNAME', 'txid_current_snapshot' LANGUAGE C
- SECURITY DEFINER;
+ STABLE SECURITY DEFINER;
-CREATE OR REPLACE FUNCTION get_snapshot_xmin(txid_snapshot)
+--CREATE OR REPLACE FUNCTION get_snapshot_xmin(txid_snapshot)
+CREATE OR REPLACE FUNCTION txid_snapshot_xmin(txid_snapshot)
RETURNS bigint
AS 'MODULE_PATHNAME', 'txid_snapshot_xmin' LANGUAGE C
IMMUTABLE STRICT;
-CREATE OR REPLACE FUNCTION get_snapshot_xmax(txid_snapshot)
+-- CREATE OR REPLACE FUNCTION get_snapshot_xmax(txid_snapshot)
+CREATE OR REPLACE FUNCTION txid_snapshot_xmax(txid_snapshot)
RETURNS bigint
AS 'MODULE_PATHNAME', 'txid_snapshot_xmax' LANGUAGE C
IMMUTABLE STRICT;
-CREATE OR REPLACE FUNCTION get_snapshot_active(txid_snapshot)
+-- CREATE OR REPLACE FUNCTION get_snapshot_active(txid_snapshot)
+CREATE OR REPLACE FUNCTION txid_snapshot_xip(txid_snapshot)
RETURNS setof bigint
- AS 'MODULE_PATHNAME', 'txid_snapshot_active' LANGUAGE C
+ AS 'MODULE_PATHNAME', 'txid_snapshot_xip' LANGUAGE C
IMMUTABLE STRICT;
@@ -65,6 +80,11 @@ CREATE OR REPLACE FUNCTION get_snapshot_active(txid_snapshot)
-- Special comparision functions used by the remote worker
-- for sync chunk selection
--
+CREATE OR REPLACE FUNCTION txid_visible_in_snapshot(bigint, txid_snapshot)
+ RETURNS boolean
+ AS 'MODULE_PATHNAME', 'txid_visible_in_snapshot' LANGUAGE C
+ IMMUTABLE STRICT;
+/*
CREATE OR REPLACE FUNCTION txid_in_snapshot(bigint, txid_snapshot)
RETURNS boolean
AS 'MODULE_PATHNAME', 'txid_in_snapshot' LANGUAGE C
@@ -74,4 +94,4 @@ CREATE OR REPLACE FUNCTION txid_not_in_snapshot(bigint, txid_snapshot)
RETURNS boolean
AS 'MODULE_PATHNAME', 'txid_not_in_snapshot' LANGUAGE C
IMMUTABLE STRICT;
-
+*/
diff --git a/sql/txid/uninstall_txid.sql b/sql/txid/uninstall_txid.sql
index 17a88045..9141c660 100644
--- a/sql/txid/uninstall_txid.sql
+++ b/sql/txid/uninstall_txid.sql
@@ -2,9 +2,6 @@
DROP DOMAIN txid;
DROP TYPE txid_snapshot cascade;
DROP SCHEMA txid CASCADE;
-DROP FUNCTION get_current_txid();
-DROP FUNCTION get_snapshot_xmin();
-DROP FUNCTION get_snapshot_xmax();
-DROP FUNCTION get_snapshot_active();
+DROP FUNCTION txid_current();