Skip to content

Commit 69f9410

Browse files
committed
Allow definition of lock mode for custom reloptions
Relation options can define a lock mode other than AccessExclusiveMode since 47167b7, but modules defining custom relation options did not really have a way to enforce that. Correct that by extending the current API set so as modules can define a custom lock mode. Author: Michael Paquier Reviewed-by: Kuntal Ghosh Discussion: https://postgr.es/m/20190920013831.GD1844@paquier.xyz
1 parent 736b84e commit 69f9410

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

contrib/bloom/blutils.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ _PG_init(void)
6060
/* Option for length of signature */
6161
add_int_reloption(bl_relopt_kind, "length",
6262
"Length of signature in bits",
63-
DEFAULT_BLOOM_LENGTH, 1, MAX_BLOOM_LENGTH);
63+
DEFAULT_BLOOM_LENGTH, 1, MAX_BLOOM_LENGTH,
64+
AccessExclusiveLock);
6465
bl_relopt_tab[0].optname = "length";
6566
bl_relopt_tab[0].opttype = RELOPT_TYPE_INT;
6667
bl_relopt_tab[0].offset = offsetof(BloomOptions, bloomLength);
@@ -71,7 +72,8 @@ _PG_init(void)
7172
snprintf(buf, sizeof(buf), "col%d", i + 1);
7273
add_int_reloption(bl_relopt_kind, buf,
7374
"Number of bits generated for each index column",
74-
DEFAULT_BLOOM_BITS, 1, MAX_BLOOM_BITS);
75+
DEFAULT_BLOOM_BITS, 1, MAX_BLOOM_BITS,
76+
AccessExclusiveLock);
7577
bl_relopt_tab[i + 1].optname = MemoryContextStrdup(TopMemoryContext,
7678
buf);
7779
bl_relopt_tab[i + 1].opttype = RELOPT_TYPE_INT;

src/backend/access/common/reloptions.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,8 @@ add_reloption(relopt_gen *newoption)
621621
* (for types other than string)
622622
*/
623623
static relopt_gen *
624-
allocate_reloption(bits32 kinds, int type, const char *name, const char *desc)
624+
allocate_reloption(bits32 kinds, int type, const char *name, const char *desc,
625+
LOCKMODE lockmode)
625626
{
626627
MemoryContext oldcxt;
627628
size_t size;
@@ -658,13 +659,7 @@ allocate_reloption(bits32 kinds, int type, const char *name, const char *desc)
658659
newoption->kinds = kinds;
659660
newoption->namelen = strlen(name);
660661
newoption->type = type;
661-
662-
/*
663-
* Set the default lock mode for this option. There is no actual way
664-
* for a module to enforce it when declaring a custom relation option,
665-
* so just use the highest level, which is safe for all cases.
666-
*/
667-
newoption->lockmode = AccessExclusiveLock;
662+
newoption->lockmode = lockmode;
668663

669664
MemoryContextSwitchTo(oldcxt);
670665

@@ -676,12 +671,13 @@ allocate_reloption(bits32 kinds, int type, const char *name, const char *desc)
676671
* Add a new boolean reloption
677672
*/
678673
void
679-
add_bool_reloption(bits32 kinds, const char *name, const char *desc, bool default_val)
674+
add_bool_reloption(bits32 kinds, const char *name, const char *desc,
675+
bool default_val, LOCKMODE lockmode)
680676
{
681677
relopt_bool *newoption;
682678

683679
newoption = (relopt_bool *) allocate_reloption(kinds, RELOPT_TYPE_BOOL,
684-
name, desc);
680+
name, desc, lockmode);
685681
newoption->default_val = default_val;
686682

687683
add_reloption((relopt_gen *) newoption);
@@ -693,12 +689,12 @@ add_bool_reloption(bits32 kinds, const char *name, const char *desc, bool defaul
693689
*/
694690
void
695691
add_int_reloption(bits32 kinds, const char *name, const char *desc, int default_val,
696-
int min_val, int max_val)
692+
int min_val, int max_val, LOCKMODE lockmode)
697693
{
698694
relopt_int *newoption;
699695

700696
newoption = (relopt_int *) allocate_reloption(kinds, RELOPT_TYPE_INT,
701-
name, desc);
697+
name, desc, lockmode);
702698
newoption->default_val = default_val;
703699
newoption->min = min_val;
704700
newoption->max = max_val;
@@ -712,12 +708,12 @@ add_int_reloption(bits32 kinds, const char *name, const char *desc, int default_
712708
*/
713709
void
714710
add_real_reloption(bits32 kinds, const char *name, const char *desc, double default_val,
715-
double min_val, double max_val)
711+
double min_val, double max_val, LOCKMODE lockmode)
716712
{
717713
relopt_real *newoption;
718714

719715
newoption = (relopt_real *) allocate_reloption(kinds, RELOPT_TYPE_REAL,
720-
name, desc);
716+
name, desc, lockmode);
721717
newoption->default_val = default_val;
722718
newoption->min = min_val;
723719
newoption->max = max_val;
@@ -736,7 +732,7 @@ add_real_reloption(bits32 kinds, const char *name, const char *desc, double defa
736732
*/
737733
void
738734
add_string_reloption(bits32 kinds, const char *name, const char *desc, const char *default_val,
739-
validate_string_relopt validator)
735+
validate_string_relopt validator, LOCKMODE lockmode)
740736
{
741737
relopt_string *newoption;
742738

@@ -745,7 +741,7 @@ add_string_reloption(bits32 kinds, const char *name, const char *desc, const cha
745741
(validator) (default_val);
746742

747743
newoption = (relopt_string *) allocate_reloption(kinds, RELOPT_TYPE_STRING,
748-
name, desc);
744+
name, desc, lockmode);
749745
newoption->validate_cb = validator;
750746
if (default_val)
751747
{

src/include/access/reloptions.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,16 @@ typedef struct
247247

248248
extern relopt_kind add_reloption_kind(void);
249249
extern void add_bool_reloption(bits32 kinds, const char *name, const char *desc,
250-
bool default_val);
250+
bool default_val, LOCKMODE lockmode);
251251
extern void add_int_reloption(bits32 kinds, const char *name, const char *desc,
252-
int default_val, int min_val, int max_val);
252+
int default_val, int min_val, int max_val,
253+
LOCKMODE lockmode);
253254
extern void add_real_reloption(bits32 kinds, const char *name, const char *desc,
254-
double default_val, double min_val, double max_val);
255+
double default_val, double min_val, double max_val,
256+
LOCKMODE lockmode);
255257
extern void add_string_reloption(bits32 kinds, const char *name, const char *desc,
256-
const char *default_val, validate_string_relopt validator);
258+
const char *default_val, validate_string_relopt validator,
259+
LOCKMODE lockmode);
257260

258261
extern Datum transformRelOptions(Datum oldOptions, List *defList,
259262
const char *namspace, char *validnsps[],

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