Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1bbbd78

Browse files
committed
introduce safe wrapper function pathman_cache_search_relid()
1 parentb8659fa commit1bbbd78

File tree

4 files changed

+73
-29
lines changed

4 files changed

+73
-29
lines changed

‎.gitignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ regression.out
99
*.gcda
1010
*.gcno
1111
*.gcov
12-
pg_pathman--1.3.sql
12+
pg_pathman--*.sql

‎src/init.c‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,44 @@ static uint32 build_sql_facade_version(char *version_cstr);
105105
staticuint32get_sql_facade_version(void);
106106
staticvoidvalidate_sql_facade_version(uint32ver);
107107

108+
109+
/*
110+
* Safe hash search (takes care of disabled pg_pathman).
111+
*/
112+
void*
113+
pathman_cache_search_relid(HTAB*cache_table,
114+
Oidrelid,
115+
HASHACTIONaction,
116+
bool*found)
117+
{
118+
switch (action)
119+
{
120+
/* May return NULL */
121+
caseHASH_FIND:
122+
caseHASH_REMOVE:
123+
if (!cache_table)
124+
returnNULL;
125+
break;
126+
127+
/* Must return valid pointer */
128+
caseHASH_ENTER:
129+
if (!cache_table)
130+
elog(ERROR,"pg_pathman is not initialized yet");
131+
break;
132+
133+
/* Something strange has just happened */
134+
default:
135+
elog(ERROR,"unexpected action in function "
136+
CppAsString(pathman_cache_search_relid));
137+
break;
138+
}
139+
140+
Assert(cache_table);
141+
142+
/* Everything is fine */
143+
returnhash_search(cache_table, (constvoid*)&relid,action,found);
144+
}
145+
108146
/*
109147
* Save and restore main init state.
110148
*/
@@ -279,6 +317,10 @@ init_local_cache(void)
279317
{
280318
HASHCTLctl;
281319

320+
/* Destroy caches, just in case */
321+
hash_destroy(partitioned_rels);
322+
hash_destroy(parent_cache);
323+
282324
memset(&ctl,0,sizeof(ctl));
283325
ctl.keysize=sizeof(Oid);
284326
ctl.entrysize=sizeof(PartRelationInfo);

‎src/init.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ extern PathmanInitState pg_pathman_init_state;
102102
#defineCURRENT_LIB_VERSION0x010300
103103

104104

105+
void*pathman_cache_search_relid(HTAB*cache_table,
106+
Oidrelid,
107+
HASHACTIONaction,
108+
bool*found);
109+
105110
/*
106111
* Save and restore PathmanInitState.
107112
*/

‎src/relation_info.c‎

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ refresh_pathman_relation_info(Oid relid,
8181
Datumparam_values[Natts_pathman_config_params];
8282
boolparam_isnull[Natts_pathman_config_params];
8383

84-
prel= (PartRelationInfo*)hash_search(partitioned_rels,
85-
(constvoid*)&relid,
86-
HASH_ENTER,&found_entry);
84+
prel= (PartRelationInfo*)pathman_cache_search_relid(partitioned_rels,
85+
relid,HASH_ENTER,
86+
&found_entry);
8787
elog(DEBUG2,
8888
found_entry ?
8989
"Refreshing record for relation %u in pg_pathman's cache [%u]" :
@@ -239,9 +239,9 @@ invalidate_pathman_relation_info(Oid relid, bool *found)
239239
HASHACTIONaction=found ?HASH_FIND :HASH_ENTER;
240240
PartRelationInfo*prel;
241241

242-
prel=hash_search(partitioned_rels,
243-
(constvoid*)&relid,
244-
action,&prel_found);
242+
prel=pathman_cache_search_relid(partitioned_rels,
243+
relid,action,
244+
&prel_found);
245245

246246
if ((action==HASH_FIND||
247247
(action==HASH_ENTER&&prel_found))&&PrelIsValid(prel))
@@ -272,10 +272,9 @@ invalidate_pathman_relation_info(Oid relid, bool *found)
272272
constPartRelationInfo*
273273
get_pathman_relation_info(Oidrelid)
274274
{
275-
constPartRelationInfo*prel=hash_search(partitioned_rels,
276-
(constvoid*)&relid,
277-
HASH_FIND,NULL);
278-
275+
constPartRelationInfo*prel=pathman_cache_search_relid(partitioned_rels,
276+
relid,HASH_FIND,
277+
NULL);
279278
/* Refresh PartRelationInfo if needed */
280279
if (prel&& !PrelIsValid(prel))
281280
{
@@ -345,20 +344,19 @@ get_pathman_relation_info_after_lock(Oid relid,
345344
void
346345
remove_pathman_relation_info(Oidrelid)
347346
{
348-
PartRelationInfo*prel=hash_search(partitioned_rels,
349-
(constvoid*)&relid,
350-
HASH_FIND,NULL);
351-
if (prel&&PrelIsValid(prel))
347+
PartRelationInfo*prel=pathman_cache_search_relid(partitioned_rels,
348+
relid,HASH_FIND,
349+
NULL);
350+
if (PrelIsValid(prel))
352351
{
353352
/* Free these arrays iff they're not NULL */
354353
FreeChildrenArray(prel);
355354
FreeRangesArray(prel);
356355
}
357356

358357
/* Now let's remove the entry completely */
359-
hash_search(partitioned_rels,
360-
(constvoid*)&relid,
361-
HASH_REMOVE,NULL);
358+
pathman_cache_search_relid(partitioned_rels,relid,
359+
HASH_REMOVE,NULL);
362360

363361
elog(DEBUG2,
364362
"Removing record for relation %u in pg_pathman's cache [%u]",
@@ -509,10 +507,10 @@ cache_parent_of_partition(Oid partition, Oid parent)
509507
boolfound;
510508
PartParentInfo*ppar;
511509

512-
ppar=hash_search(parent_cache,
513-
(constvoid*)&partition,
514-
HASH_ENTER,&found);
515-
510+
ppar=pathman_cache_search_relid(parent_cache,
511+
partition,
512+
HASH_ENTER,
513+
&found);
516514
elog(DEBUG2,
517515
found ?
518516
"Refreshing record for child %u in pg_pathman's cache [%u]" :
@@ -551,10 +549,10 @@ get_parent_of_partition_internal(Oid partition,
551549
{
552550
constchar*action_str;/* "Fetching"\"Resetting" */
553551
Oidparent;
554-
PartParentInfo*ppar=hash_search(parent_cache,
555-
(constvoid*)&partition,
556-
HASH_FIND,NULL);
557-
552+
PartParentInfo*ppar=pathman_cache_search_relid(parent_cache,
553+
partition,
554+
HASH_FIND,
555+
NULL);
558556
/* Set 'action_str' */
559557
switch (action)
560558
{
@@ -581,9 +579,8 @@ get_parent_of_partition_internal(Oid partition,
581579

582580
/* Remove entry if necessary */
583581
if (action==HASH_REMOVE)
584-
hash_search(parent_cache,
585-
(constvoid*)&partition,
586-
HASH_REMOVE,NULL);
582+
pathman_cache_search_relid(parent_cache,partition,
583+
HASH_REMOVE,NULL);
587584
}
588585
/* Try fetching parent from syscache if 'status' is provided */
589586
elseif (status)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp