mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-17 19:13:16 +08:00
Add LWLock for OSM usage in loader
Modify the loader to add a LWLock for OSM code. Update the loader API version to 4.
This commit is contained in:
parent
101e4c57ef
commit
8c34a207d9
.unreleased
src
test
1
.unreleased/pr_6608
Normal file
1
.unreleased/pr_6608
Normal file
@ -0,0 +1 @@
|
||||
Implements: #6608 Add LWLock for OSM usage in loader
|
@ -11,7 +11,7 @@
|
||||
#include "launcher_interface.h"
|
||||
#include "compat/compat.h"
|
||||
|
||||
#define MIN_LOADER_API_VERSION 3
|
||||
#define MIN_LOADER_API_VERSION 4
|
||||
|
||||
extern bool
|
||||
ts_bgw_worker_reserve(void)
|
||||
|
@ -16,7 +16,14 @@
|
||||
|
||||
/* This is where versioned-extension facing functions live. They shouldn't live anywhere else. */
|
||||
|
||||
const int32 ts_bgw_loader_api_version = 3;
|
||||
/* All loader changes should always be backward compatible.
|
||||
* Update ts_bgw_loader_api_version if the loader changes are needed for newer extension updates.
|
||||
* e.g. adding a LWLock to loader is required for some future change coming to OSM extension version
|
||||
* xxxx. RENDEZVOUS_BGW_LOADER_API_VERSION is used to verify if the loader in use is compatible with
|
||||
* the current TimescaleDB version. This check happens in bgw/bgw_launcher.c When
|
||||
* ts_bgw_loader_api_version is updated, check the compatibility in bgw/bgw_launcher.c as well
|
||||
*/
|
||||
const int32 ts_bgw_loader_api_version = 4;
|
||||
|
||||
TS_FUNCTION_INFO_V1(ts_bgw_worker_reserve);
|
||||
TS_FUNCTION_INFO_V1(ts_bgw_worker_release);
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#define TS_LWLOCKS_SHMEM_NAME "ts_lwlocks_shmem"
|
||||
#define CHUNK_APPEND_LWLOCK_TRANCHE_NAME "ts_chunk_append_lwlock_tranche"
|
||||
#define OSM_PARALLEL_LWLOCK_TRANCHE_NAME "ts_osm_parallel_lwlock_tranche"
|
||||
|
||||
/*
|
||||
* since shared memory can only be setup in a library loaded as
|
||||
@ -22,6 +23,7 @@
|
||||
typedef struct TSLWLocks
|
||||
{
|
||||
LWLock *chunk_append;
|
||||
LWLock *osm_parallel_lwlock;
|
||||
} TSLWLocks;
|
||||
|
||||
static TSLWLocks *ts_lwlocks = NULL;
|
||||
@ -30,7 +32,7 @@ void
|
||||
ts_lwlocks_shmem_startup()
|
||||
{
|
||||
bool found;
|
||||
LWLock **lock_pointer;
|
||||
LWLock **lock_pointer, **osm_lock_pointer;
|
||||
|
||||
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
|
||||
ts_lwlocks = ShmemInitStruct(TS_LWLOCKS_SHMEM_NAME, sizeof(TSLWLocks), &found);
|
||||
@ -38,6 +40,8 @@ ts_lwlocks_shmem_startup()
|
||||
{
|
||||
memset(ts_lwlocks, 0, sizeof(TSLWLocks));
|
||||
ts_lwlocks->chunk_append = &(GetNamedLWLockTranche(CHUNK_APPEND_LWLOCK_TRANCHE_NAME))->lock;
|
||||
ts_lwlocks->osm_parallel_lwlock =
|
||||
&(GetNamedLWLockTranche(OSM_PARALLEL_LWLOCK_TRANCHE_NAME))->lock;
|
||||
}
|
||||
LWLockRelease(AddinShmemInitLock);
|
||||
|
||||
@ -48,11 +52,21 @@ ts_lwlocks_shmem_startup()
|
||||
*/
|
||||
lock_pointer = (LWLock **) find_rendezvous_variable(RENDEZVOUS_CHUNK_APPEND_LWLOCK);
|
||||
*lock_pointer = ts_lwlocks->chunk_append;
|
||||
osm_lock_pointer = (LWLock **) find_rendezvous_variable(RENDEZVOUS_OSM_PARALLEL_LWLOCK);
|
||||
*osm_lock_pointer = ts_lwlocks->osm_parallel_lwlock;
|
||||
}
|
||||
|
||||
/*
|
||||
* from postgres code comments:
|
||||
* Extensions (or core code) can obtain an LWLocks by calling
|
||||
* RequestNamedLWLockTranche() during postmaster startup. Subsequently,
|
||||
* call GetNamedLWLockTranche() to obtain a pointer to an array containing
|
||||
* the number of LWLocks requested.
|
||||
*/
|
||||
void
|
||||
ts_lwlocks_shmem_alloc()
|
||||
{
|
||||
RequestNamedLWLockTranche(CHUNK_APPEND_LWLOCK_TRANCHE_NAME, 1);
|
||||
RequestNamedLWLockTranche(OSM_PARALLEL_LWLOCK_TRANCHE_NAME, 1);
|
||||
RequestAddinShmemSpace(sizeof(TSLWLocks));
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#define RENDEZVOUS_CHUNK_APPEND_LWLOCK "ts_chunk_append_lwlock"
|
||||
#define RENDEZVOUS_OSM_PARALLEL_LWLOCK "ts_osm_parallel_lwlock"
|
||||
|
||||
void ts_lwlocks_shmem_startup(void);
|
||||
void ts_lwlocks_shmem_alloc(void);
|
||||
|
@ -557,6 +557,7 @@ CREATE EXTENSION timescaledb_osm VERSION 'mock-1';
|
||||
WARNING: mock post_analyze_hook "mock-2"
|
||||
WARNING: mock post_analyze_hook "mock-2"
|
||||
WARNING: OSM-mock-1 _PG_init
|
||||
WARNING: got lwlock osm lock
|
||||
WARNING: mock post_analyze_hook "mock-2"
|
||||
WARNING: mock post_analyze_hook "mock-2"
|
||||
-- Test that OSM process utility hook works: it should see this DROP TABLE.
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "compat/compat.h"
|
||||
#include "export.h"
|
||||
#include "loader/lwlocks.h"
|
||||
|
||||
#ifdef PG_MODULE_MAGIC
|
||||
PG_MODULE_MAGIC;
|
||||
@ -33,6 +34,16 @@ void
|
||||
_PG_init(void)
|
||||
{
|
||||
elog(WARNING, "OSM-%s _PG_init", OSM_VERSION_MOD);
|
||||
void *osm_lock_pointer = (LWLock **) find_rendezvous_variable(RENDEZVOUS_OSM_PARALLEL_LWLOCK);
|
||||
if (osm_lock_pointer != NULL)
|
||||
{
|
||||
elog(WARNING, "got lwlock osm lock");
|
||||
}
|
||||
else
|
||||
{
|
||||
elog(WARNING, "NO lwlock osm lock");
|
||||
}
|
||||
|
||||
prev_ProcessUtility_hook = ProcessUtility_hook;
|
||||
ProcessUtility_hook = osm_process_utility_hook;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user