From 90ad3acc3065de4abb6c5b2e511acddec772f6fd Mon Sep 17 00:00:00 2001 From: Craig Ringer Date: Thu, 20 Nov 2014 14:21:28 +0800 Subject: [PATCH] bdr: Introduce bdr_get_local_nodeid() --- Makefile.in | 12 ++++++++++-- bdr--0.8.0.5--0.8.0.6.sql | 12 ++++++++++++ bdr.c | 23 +++++++++++++++++++++++ bdr.control | 2 +- expected/identifier.out | 8 ++++++++ expected/upgrade.out | 5 ++++- sql/identifier.sql | 3 +++ sql/upgrade.sql | 4 ++++ 8 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 bdr--0.8.0.5--0.8.0.6.sql create mode 100644 expected/identifier.out create mode 100644 sql/identifier.sql diff --git a/Makefile.in b/Makefile.in index cf5b351e64..eb41c8b2ee 100644 --- a/Makefile.in +++ b/Makefile.in @@ -11,10 +11,11 @@ DATA = bdr--0.8.0.sql \ bdr--0.8.0.1--0.8.0.2.sql \ bdr--0.8.0.2--0.8.0.3.sql \ bdr--0.8.0.3--0.8.0.4.sql \ - bdr--0.8.0.4--0.8.0.5.sql + bdr--0.8.0.4--0.8.0.5.sql \ + bdr--0.8.0.5--0.8.0.6.sql DATA_built = bdr--0.8.0.1.sql bdr--0.8.0.2.sql bdr--0.8.0.3.sql \ - bdr--0.8.0.4.sql bdr--0.8.0.5.sql + bdr--0.8.0.4.sql bdr--0.8.0.5.sql bdr--0.8.0.6.sql DOCS = bdr.conf.sample README.bdr SCRIPTS = scripts/bdr_initial_load bdr_init_copy bdr_resetxlog bdr_dump @@ -113,6 +114,12 @@ bdr--0.8.0.5.sql: bdr--0.8.0.sql bdr--0.8.0--0.8.0.1.sql \ bdr--0.8.0.3--0.8.0.4.sql bdr--0.8.0.4--0.8.0.5.sql cat $^ > $@ +bdr--0.8.0.6.sql: bdr--0.8.0.sql bdr--0.8.0--0.8.0.1.sql \ + bdr--0.8.0.1--0.8.0.2.sql bdr--0.8.0.2--0.8.0.3.sql \ + bdr--0.8.0.3--0.8.0.4.sql bdr--0.8.0.4--0.8.0.5.sql \ + bdr--0.8.0.5--0.8.0.6.sql + cat $^ > $@ + bdr_resetxlog: pg_resetxlog.o $(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(libpq_pgport) $(LIBS) -o $@$(X) @@ -162,6 +169,7 @@ endif REGRESSCHECKS= \ init \ upgrade \ + identifier \ $(DDLREGRESSCHECKS) \ dml/basic dml/contrib dml/delete_pk dml/extended dml/missing_pk dml/toasted diff --git a/bdr--0.8.0.5--0.8.0.6.sql b/bdr--0.8.0.5--0.8.0.6.sql new file mode 100644 index 0000000000..53b4f7c4dc --- /dev/null +++ b/bdr--0.8.0.5--0.8.0.6.sql @@ -0,0 +1,12 @@ +SET LOCAL search_path = bdr; +SET bdr.permit_unsafe_ddl_commands = true; +SET bdr.skip_ddl_replication = true; + +CREATE FUNCTION bdr_get_local_nodeid( sysid OUT oid, timeline OUT oid, dboid OUT oid) +RETURNS record LANGUAGE c AS 'MODULE_PATHNAME'; + +-- bdr_get_local_nodeid is intentionally not revoked from all, it's read-only + +RESET bdr.permit_unsafe_ddl_commands; +RESET bdr.skip_ddl_replication; +RESET search_path; diff --git a/bdr.c b/bdr.c index 1e62196700..913f6d0034 100644 --- a/bdr.c +++ b/bdr.c @@ -110,11 +110,13 @@ Datum bdr_apply_pause(PG_FUNCTION_ARGS); Datum bdr_apply_resume(PG_FUNCTION_ARGS); Datum bdr_version(PG_FUNCTION_ARGS); Datum bdr_variant(PG_FUNCTION_ARGS); +Datum bdr_get_local_nodeid(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(bdr_apply_pause); PG_FUNCTION_INFO_V1(bdr_apply_resume); PG_FUNCTION_INFO_V1(bdr_version); PG_FUNCTION_INFO_V1(bdr_variant); +PG_FUNCTION_INFO_V1(bdr_get_local_nodeid); static void bdr_sigterm(SIGNAL_ARGS) @@ -1591,3 +1593,24 @@ bdr_variant(PG_FUNCTION_ARGS) { PG_RETURN_TEXT_P(cstring_to_text(BDR_VARIANT)); } + +/* Return a tuple of (sysid oid, tlid oid, dboid oid) */ +Datum +bdr_get_local_nodeid(PG_FUNCTION_ARGS) +{ + Datum values[3]; + bool isnull[3] = {false, false, false}; + TupleDesc tupleDesc; + HeapTuple returnTuple; + + if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE) + elog(ERROR, "return type must be a row type"); + + values[0] = ObjectIdGetDatum(GetSystemIdentifier()); + values[1] = ObjectIdGetDatum(ThisTimeLineID); + values[2] = ObjectIdGetDatum(MyDatabaseId); + + returnTuple = heap_form_tuple(tupleDesc, values, isnull); + + PG_RETURN_DATUM(HeapTupleGetDatum(returnTuple)); +} diff --git a/bdr.control b/bdr.control index 659f65ebe9..c4758fe4b1 100644 --- a/bdr.control +++ b/bdr.control @@ -1,6 +1,6 @@ # bdr extension comment = 'bdr support functions' -default_version = '0.8.0.5' +default_version = '0.8.0.6' module_pathname = '$libdir/bdr' relocatable = false requires = btree_gist diff --git a/expected/identifier.out b/expected/identifier.out new file mode 100644 index 0000000000..2d2e38b131 --- /dev/null +++ b/expected/identifier.out @@ -0,0 +1,8 @@ +-- No real way to test the sysid, so ignore it +SELECT timeline= 1, dboid = (SELECT oid FROM pg_database WHERE datname = current_database()) +FROM bdr.bdr_get_local_nodeid(); + ?column? | ?column? +----------+---------- + t | t +(1 row) + diff --git a/expected/upgrade.out b/expected/upgrade.out index 2491449c37..55fc27972c 100644 --- a/expected/upgrade.out +++ b/expected/upgrade.out @@ -19,6 +19,8 @@ CREATE EXTENSION bdr VERSION '0.8.0.4'; DROP EXTENSION bdr; CREATE EXTENSION bdr VERSION '0.8.0.5'; DROP EXTENSION bdr; +CREATE EXTENSION bdr VERSION '0.8.0.6'; +DROP EXTENSION bdr; -- evolve version one by one from the oldest to the newest one CREATE EXTENSION bdr VERSION '0.8.0'; ALTER EXTENSION bdr UPDATE TO '0.8.0.1'; @@ -26,8 +28,9 @@ ALTER EXTENSION bdr UPDATE TO '0.8.0.2'; ALTER EXTENSION bdr UPDATE TO '0.8.0.3'; ALTER EXTENSION bdr UPDATE TO '0.8.0.4'; ALTER EXTENSION bdr UPDATE TO '0.8.0.5'; +ALTER EXTENSION bdr UPDATE TO '0.8.0.6'; -- Should never have to do anything: You missed adding the new version above. ALTER EXTENSION bdr UPDATE; -NOTICE: version "0.8.0.5" of extension "bdr" is already installed +NOTICE: version "0.8.0.6" of extension "bdr" is already installed \c postgres DROP DATABASE extension_upgrade; diff --git a/sql/identifier.sql b/sql/identifier.sql new file mode 100644 index 0000000000..4d73aecf02 --- /dev/null +++ b/sql/identifier.sql @@ -0,0 +1,3 @@ +-- No real way to test the sysid, so ignore it +SELECT timeline= 1, dboid = (SELECT oid FROM pg_database WHERE datname = current_database()) +FROM bdr.bdr_get_local_nodeid(); diff --git a/sql/upgrade.sql b/sql/upgrade.sql index 2599d0f28f..4275ffa25a 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -27,6 +27,9 @@ DROP EXTENSION bdr; CREATE EXTENSION bdr VERSION '0.8.0.5'; DROP EXTENSION bdr; +CREATE EXTENSION bdr VERSION '0.8.0.6'; +DROP EXTENSION bdr; + -- evolve version one by one from the oldest to the newest one CREATE EXTENSION bdr VERSION '0.8.0'; ALTER EXTENSION bdr UPDATE TO '0.8.0.1'; @@ -34,6 +37,7 @@ ALTER EXTENSION bdr UPDATE TO '0.8.0.2'; ALTER EXTENSION bdr UPDATE TO '0.8.0.3'; ALTER EXTENSION bdr UPDATE TO '0.8.0.4'; ALTER EXTENSION bdr UPDATE TO '0.8.0.5'; +ALTER EXTENSION bdr UPDATE TO '0.8.0.6'; -- Should never have to do anything: You missed adding the new version above. -- 2.39.5