Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use RelationGetSmgr instead of rd_smgr #5028

Merged
merged 1 commit into from Nov 28, 2022
Merged

Conversation

svenklemm
Copy link
Member

rd_smgr should not be accessed directly but RelationGetSmgr should be used instead. Accessing it directly can lead to segfaults when parallel relcache flushes are happening.

postgres/postgres@f10f0ae

@codecov
Copy link

codecov bot commented Nov 26, 2022

Codecov Report

Merging #5028 (52b0fbe) into main (26e3be1) will increase coverage by 0.01%.
The diff coverage is 84.24%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5028      +/-   ##
==========================================
+ Coverage   89.58%   89.60%   +0.01%     
==========================================
  Files         226      227       +1     
  Lines       51347    51584     +237     
==========================================
+ Hits        46001    46222     +221     
- Misses       5346     5362      +16     
Impacted Files Coverage Δ
src/chunk.h 100.00% <ø> (ø)
src/cross_module_fn.c 67.55% <0.00%> (-1.10%) ⬇️
src/process_utility.c 90.19% <0.00%> (-0.09%) ⬇️
src/ts_catalog/continuous_agg.h 100.00% <ø> (ø)
tsl/src/chunk_api.c 95.67% <ø> (ø)
tsl/src/init.c 96.00% <ø> (ø)
src/copy.c 90.32% <20.00%> (-0.63%) ⬇️
tsl/src/nodes/frozen_chunk_dml/frozen_chunk_dml.c 64.44% <64.44%> (ø)
tsl/src/fdw/modify_exec.c 85.22% <82.45%> (+0.25%) ⬆️
tsl/src/fdw/modify_plan.c 91.25% <83.33%> (-0.75%) ⬇️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2d0087a...52b0fbe. Read the comment docs.

@svenklemm svenklemm self-assigned this Nov 26, 2022
Copy link
Contributor

@fabriziomello fabriziomello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a minor comment but approved anyway.

Comment on lines +706 to +729
#if PG13_GE
/*
* RelationGetSmgr
* Returns smgr file handle for a relation, opening it if needed.
*
* Very little code is authorized to touch rel->rd_smgr directly. Instead
* use this function to fetch its value.
*
* Note: since a relcache flush can cause the file handle to be closed again,
* it's unwise to hold onto the pointer returned by this function for any
* long period. Recommended practice is to just re-execute RelationGetSmgr
* each time you need to access the SMgrRelation. It's quite cheap in
* comparison to whatever an smgr function is going to do.
*
* copied verbatim from postgres because it is a static function
*/
static inline SMgrRelation
RelationGetSmgr(Relation rel)
{
if (unlikely(rel->rd_smgr == NULL))
smgrsetowner(&(rel->rd_smgr), smgropen(rel->rd_node, rel->rd_backend));
return rel->rd_smgr;
}
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this code reside in the compat module?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use compat for wrapper functions that abstract API differences between the PG versions. For verbatim imports from PG source we use src/import but since copy.c was the only call site i put it there directly

rd_smgr should not be accessed directly but RelationGetSmgr should
be used instead. Accessing it directly can lead to segfaults when
parallel relcache flushes are happening.

postgres/postgres@f10f0ae
@svenklemm svenklemm enabled auto-merge (rebase) November 28, 2022 12:24
@svenklemm svenklemm merged commit 558da2c into timescale:main Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants