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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
There was a problem hiding this 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.
#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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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