Skip to content

Commit cc320fc

Browse files
committed
Merge branch 'master_lock_group' into rel_1_2_beta
2 parents d8be066 + 41ae65a commit cc320fc

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/pathman_workers.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "storage/dsm.h"
3030
#include "storage/ipc.h"
3131
#include "storage/latch.h"
32+
#include "storage/proc.h"
3233
#include "utils/builtins.h"
3334
#include "utils/datum.h"
3435
#include "utils/memutils.h"
@@ -256,6 +257,12 @@ create_partitions_bg_worker_segment(Oid relid, Datum value, Oid value_type)
256257
args->dbid = MyDatabaseId;
257258
args->partitioned_table = relid;
258259

260+
#if PG_VERSION_NUM >= 90600
261+
/* Initialize args for BecomeLockGroupMember() */
262+
args->parallel_master_pgproc = MyProc;
263+
args->parallel_master_pid = MyProcPid;
264+
#endif
265+
259266
/* Write value-related stuff */
260267
args->value_type = value_type;
261268
args->value_size = datum_size;
@@ -286,6 +293,11 @@ create_partitions_bg_worker(Oid relid, Datum value, Oid value_type)
286293
segment_handle = dsm_segment_handle(segment);
287294
bgw_args = (SpawnPartitionArgs *) dsm_segment_address(segment);
288295

296+
#if PG_VERSION_NUM >= 90600
297+
/* Become locking group leader */
298+
BecomeLockGroupLeader();
299+
#endif
300+
289301
/* Start worker and wait for it to finish */
290302
start_bg_worker(spawn_partitions_bgw,
291303
bgw_main_spawn_partitions,
@@ -337,6 +349,13 @@ bgw_main_spawn_partitions(Datum main_arg)
337349
spawn_partitions_bgw, MyProcPid);
338350
args = dsm_segment_address(segment);
339351

352+
#if PG_VERSION_NUM >= 90600
353+
/* Join locking group. If we can't join the group, quit */
354+
if (!BecomeLockGroupMember(args->parallel_master_pgproc,
355+
args->parallel_master_pid))
356+
return;
357+
#endif
358+
340359
/* Establish connection and start transaction */
341360
BackgroundWorkerInitializeConnectionByOid(args->dbid, args->userid);
342361

src/pathman_workers.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#include "postgres.h"
2121
#include "storage/spin.h"
2222

23+
#if PG_VERSION_NUM >= 90600
24+
#include "storage/lock.h"
25+
#endif
26+
2327

2428
/*
2529
* Store args, result and execution status of CreatePartitionsWorker.
@@ -32,6 +36,12 @@ typedef struct
3236
Oid dbid; /* database which stores 'partitioned_table' */
3337
Oid partitioned_table;
3438

39+
#if PG_VERSION_NUM >= 90600
40+
/* Args for BecomeLockGroupMember() function */
41+
PGPROC *parallel_master_pgproc;
42+
pid_t parallel_master_pid;
43+
#endif
44+
3545
/* Needed to decode Datum from 'values' */
3646
Oid value_type;
3747
Size value_size;

src/xact_handling.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ xact_unlock_rel_exclusive(Oid relid)
8282
bool
8383
xact_bgw_conflicting_lock_exists(Oid relid)
8484
{
85+
#if PG_VERSION_NUM >= 90600
86+
/* We use locking groups for 9.6+ */
87+
return false;
88+
#else
8589
LOCKMODE lockmode;
8690

8791
/* Try each lock >= ShareUpdateExclusiveLock */
@@ -94,6 +98,7 @@ xact_bgw_conflicting_lock_exists(Oid relid)
9498
}
9599

96100
return false;
101+
#endif
97102
}
98103

99104

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy