From 750a776f1d2af0b692c5cfb1a148e2bde4e31605 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Mon, 18 Sep 2017 11:00:39 +0900 Subject: [PATCH] Fixes for PostgreSQL 9.3 support --- compat-lsn.h | 27 --------------------------- repmgr.c | 34 +++++++++++++++++++++------------- 2 files changed, 21 insertions(+), 40 deletions(-) delete mode 100644 compat-lsn.h diff --git a/compat-lsn.h b/compat-lsn.h deleted file mode 100644 index cc51b2a0..00000000 --- a/compat-lsn.h +++ /dev/null @@ -1,27 +0,0 @@ -/*------------------------------------------------------------------------- - * - * pg_lsn.h - * Declarations for operations on log sequence numbers (LSNs) of - * PostgreSQL. - * - * - * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group - * Portions Copyright (c) 1994, Regents of the University of California - * - * src/include/utils/pg_lsn.h - * - *------------------------------------------------------------------------- - */ -#ifndef PG_LSN_H -#define PG_LSN_H - -#include "fmgr.h" -#include "access/xlogdefs.h" - -#define DatumGetLSN(X) ((XLogRecPtr) DatumGetInt64(X)) -#define LSNGetDatum(X) (Int64GetDatum((int64) (X))) - -#define PG_GETARG_LSN(n) DatumGetLSN(PG_GETARG_DATUM(n)) -#define PG_RETURN_LSN(x) return LSNGetDatum(x) - -#endif /* PG_LSN_H */ diff --git a/repmgr.c b/repmgr.c index 22f62a4c..eabfcc81 100644 --- a/repmgr.c +++ b/repmgr.c @@ -35,8 +35,6 @@ #if (PG_VERSION_NUM >= 90400) #include "utils/pg_lsn.h" -#else -#include "compat-lsn.h" #endif #include "utils/timestamp.h" @@ -287,14 +285,24 @@ request_vote(PG_FUNCTION_ARGS) { #ifndef BDR_ONLY StringInfoData query; + +#if (PG_VERSION_NUM >= 90400) XLogRecPtr our_lsn = InvalidXLogRecPtr; + bool isnull; +#else + char *value = NULL; + char lsn_text[64] = ""; +#endif /* node_id used for logging purposes */ int requesting_node_id = PG_GETARG_INT32(0); int current_electoral_term = PG_GETARG_INT32(1); int ret; - bool isnull; + + + + if (!shared_state) PG_RETURN_NULL(); @@ -341,14 +349,22 @@ request_vote(PG_FUNCTION_ARGS) #endif } +#if (PG_VERSION_NUM >= 90400) our_lsn = DatumGetLSN(SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull)); - elog(DEBUG1, "our LSN is %X/%X", (uint32) (our_lsn >> 32), (uint32) our_lsn); +#else + value = SPI_getvalue(SPI_tuptable->vals[0], + SPI_tuptable->tupdesc, + 1); + strncpy(lsn_text, value, 64); + pfree(value); + elog(DEBUG1, "our LSN is %s", lsn_text); +#endif /* indicate this node has responded to a vote request */ shared_state->voting_status = VS_VOTE_REQUEST_RECEIVED; @@ -362,15 +378,7 @@ request_vote(PG_FUNCTION_ARGS) #if (PG_VERSION_NUM >= 90400) PG_RETURN_LSN(our_lsn); #else - { - char lsn_text[64] = ""; - snprintf(lsn_text, 64, - "%X/%X", - (uint32) (our_lsn >> 32), - (uint32) our_lsn); - - PG_RETURN_TEXT_P(cstring_to_text(lsn_text)); - } + PG_RETURN_TEXT_P(cstring_to_text(lsn_text)); #endif #else PG_RETURN(InvalidOid);