From 0243aa5a8ebf56e2a92b99b1fb208ebc5084c87e Mon Sep 17 00:00:00 2001 From: Marc Munro Date: Fri, 4 May 2018 17:25:34 -0700 Subject: [PATCH] Update to work with postgresql 10.3 --- src/veil_mainpage.c | 35 ++++++++++++++++++++++++++++-- src/veil_shmem.c | 52 ++++++++++++++++++++++++++++++++++++++++----- src/veil_shmem.h | 8 ++++--- veil.control | 4 ++-- veil_demo.control | 4 ++-- 5 files changed, 89 insertions(+), 14 deletions(-) diff --git a/src/veil_mainpage.c b/src/veil_mainpage.c index e480eda..d195a55 100644 --- a/src/veil_mainpage.c +++ b/src/veil_mainpage.c @@ -3,7 +3,7 @@ * * Doxygen documentation root for Veil * - * Copyright (c) 2005 - 2016 Marc Munro + * Copyright (c) 2005 - 2018 Marc Munro * Author: Marc Munro * License: BSD * @@ -2031,6 +2031,15 @@ Next: \ref History */ /*! \page History History and Compatibility \section past Changes History +\subsection v10_3 Version 10.3.0 (Stable) (2018-05-04) +This version supports PostgreSQL V10.3. + +This was updated following a report of being unable to build veil for +Postgres 10.3. This was the result of changes made in postgres after +version 9.5, to change the way that LWlocks are handled. This version +of veil may work for earlier versions of Postgres 10.x but has not been +tested. + \subsection v9_5 Version 9.5.0 (Stable) (2016-03-14) This version supports PostgreSQL V9.5. @@ -2095,7 +2104,7 @@ version, please ask. - + @@ -2103,6 +2112,8 @@ version, please ask. + + @@ -2111,6 +2122,8 @@ version, please ask. + + @@ -2119,6 +2132,8 @@ version, please ask. + + @@ -2127,6 +2142,8 @@ version, please ask. + + @@ -2135,6 +2152,8 @@ version, please ask. + + @@ -2143,6 +2162,18 @@ version, please ask. + + + + + + + + + + + +
Veil versionPostgres VersionPostgres Version
9.19.3 9.4 9.510.x (x < 3)10.3
9.1.0 (Stable)- - - - -
9.2.0 (Stable)- - - - -
9.3.0 (Stable)Yes - - - -
9.4.1 (Stable)- Yes - - -
9.5.0 (Stable)- - Yes- -
10.3 (Stable)- - - - - ? Yes
diff --git a/src/veil_shmem.c b/src/veil_shmem.c index ff33c91..14b2bcc 100644 --- a/src/veil_shmem.c +++ b/src/veil_shmem.c @@ -2,7 +2,7 @@ * @file veil_shmem.c * \code * Author: Marc Munro - * Copyright (c) 2005 - 2015 Marc Munro + * Copyright (c) 2005 - 2018 Marc Munro * License: BSD * * \endcode @@ -46,7 +46,7 @@ * - We look up variable "x" in the current hash, and if we have to * allocate space for it, allocate it from the current context. * - * Note that We use a dynamicall allocated LWLock, VeilLWLock to protect + * Note that We use a dynamically allocated LWLock, VeilLWLock to protect * our shared control structures. * */ @@ -100,6 +100,38 @@ static LWLockId InitialLWLock = 0; */ #define OTHER_CONTEXT(x) (x ? 0: 1) +/** + * The MemContext that we use to manage our tranche of LWLocks + */ +static MemContext *lwlock_context; + +/** + * Name of tranche of LWLocks used by veil. + */ +static char *TRANCHE_NAME = "veil"; + +/** + * Return the next LWLock from our tranche. + * Note that locking is the responsibility of the caller. + */ +static LWLock * +NextLWLock() +{ + // TODO: Ensure we don't exceed the number of locks in our tranche + if (lwlock_context->lwlock_idx > 0) { + lwlock_context->lwlock_idx--; + } + else { + // Error + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("veil: out of LWLocks"))); + } + return + &(lwlock_context->lwlock_tranche[lwlock_context->lwlock_idx].lock); +} + + /** * Veil's startup function. This should be run when the Veil shared * library is loaded by postgres. @@ -121,8 +153,8 @@ _PG_init() /* Request a Veil-specific shared memory context */ RequestAddinShmemSpace(2 * veil_shmem_context_size() * veil_dbs); - /* Request a LWLock for later use by all backends */ - RequestAddinLWLocks(veil_dbs); + /* Request LWLocks for later use by all backends */ + RequestNamedLWLockTranche(TRANCHE_NAME, veil_dbs); } /** @@ -237,6 +269,15 @@ get_shmem_context(char *name, context->next = sizeof(MemContext); context->limit = size; context->lwlock = VeilLWLock; + + if (i == 0) { + /* This context is the very first MemContext for the + * cluster: this is the one used to manage our LWLocks + * tranche. */ + context->lwlock_tranche = GetNamedLWLockTranche(TRANCHE_NAME); + context->lwlock_idx = max_dbs; + lwlock_context = context; + } return context; } } @@ -399,6 +440,7 @@ vl_free(void *mem) } + /** * Attach to, creating and initialising as necessary, the shared memory * control structure. Record this for the session in shared_meminfo. @@ -449,7 +491,7 @@ shmalloc_init(void) else { /* Allocate new LWLock for this new shared memory * context */ - VeilLWLock = LWLockAssign(); + VeilLWLock = NextLWLock(); } /* Record the lock id in context0 (for possible re-use if * the current database is dropped and a new veil-using diff --git a/src/veil_shmem.h b/src/veil_shmem.h index 5ccd2df..45c5e59 100644 --- a/src/veil_shmem.h +++ b/src/veil_shmem.h @@ -2,7 +2,7 @@ * @file veil_shmem.h * \code * Author: Marc Munro - * Copyright (c) 2005 - 2011 Marc Munro + * Copyright (c) 2005 - 2018 Marc Munro * License: BSD * * \endcode @@ -56,12 +56,14 @@ typedef struct MemContext { * which this context was created, * or by which it has been taken * over. */ - LWLockId lwlock; /**< The LWLock associated with this + LWLock *lwlock; /**< The LWLock associated with this * memory context */ size_t next; /**< Offset of 1st free byte */ size_t limit; /**< Offset, of 1st byte beyond this * struct */ - + LWLockPadded *lwlock_tranche; /**< A tranche of lwlocks (only used in + * the zeroth MemContext. */ + int lwlock_idx; /**< Index into the above. */ struct ShmemCtl *memctl; /**< Pointer to shared memory control * structure. */ void *memory[0]; /**< The rest of the chunk, from which diff --git a/veil.control b/veil.control index 0e0f16c..97f6b38 100644 --- a/veil.control +++ b/veil.control @@ -2,13 +2,13 @@ # # Postgres extension control file for Veil # -# Copyright (c) 2011 - 2016 Marc Munro +# Copyright (c) 2011 - 2018 Marc Munro # Author: Marc Munro # License: BSD # directory = 'extension' -default_version = '9.5.0' +default_version = '10.3.0' module_pathname = '$libdir/veil' superuser = true relocatable = false diff --git a/veil_demo.control b/veil_demo.control index c779991..bd67a8d 100644 --- a/veil_demo.control +++ b/veil_demo.control @@ -2,13 +2,13 @@ # # Postgres extension control file for veil_demo # -# Copyright (c) 2011 - 2016 Marc Munro +# Copyright (c) 2011 - 2018 Marc Munro # Author: Marc Munro # License: BSD # directory = 'extension' -default_version = '9.5.0' +default_version = '10.3.0' superuser = true relocatable = false requires = veil -- 2.39.5