Use smgrexists() instead of access() to enforce uniqueness of generated relfilenumber (#7992)

## Problem

Postgres is using `access()` function in `GetNewRelFileNumber` to check
if assigned relfilenumber is not used for any other relation. This check
will not work in Neon, because we do not have all files in local
storage.

## Summary of changes

Use smgrexists() instead which will check at page server if such
relfilenode is used.

## Checklist before requesting a review

- [ ] I have performed a self-review of my code.
- [ ] If it is a core feature, I have added thorough tests.
- [ ] Do we need to implement analytics? if so did you add the relevant
metrics to the dashboard?
- [ ] If this PR requires public announcement, mark it with
/release-notes label and add several sentences in this section.

## Checklist before merging

- [ ] Do not forget to reformat commit message to not include the above
checklist

---------

Co-authored-by: Konstantin Knizhnik <knizhnik@neon.tech>
This commit is contained in:
Konstantin Knizhnik
2024-07-23 18:41:55 +03:00
committed by GitHub
parent 1a4c1eba92
commit 563d73d923
8 changed files with 83 additions and 6 deletions

View File

@@ -7,6 +7,12 @@ AS 'MODULE_PATHNAME', 'test_consume_xids'
LANGUAGE C STRICT
PARALLEL UNSAFE;
CREATE FUNCTION test_consume_oids(oid int)
RETURNS VOID
AS 'MODULE_PATHNAME', 'test_consume_oids'
LANGUAGE C STRICT
PARALLEL UNSAFE;
CREATE FUNCTION test_consume_cpu(seconds int)
RETURNS VOID
AS 'MODULE_PATHNAME', 'test_consume_cpu'

View File

@@ -35,6 +35,7 @@ PG_MODULE_MAGIC;
extern void _PG_init(void);
PG_FUNCTION_INFO_V1(test_consume_xids);
PG_FUNCTION_INFO_V1(test_consume_oids);
PG_FUNCTION_INFO_V1(test_consume_cpu);
PG_FUNCTION_INFO_V1(test_consume_memory);
PG_FUNCTION_INFO_V1(test_release_memory);
@@ -74,6 +75,21 @@ _PG_init(void)
#define neon_read_at_lsn neon_read_at_lsn_ptr
/*
* test_consume_oids(int4), for rapidly consuming OIDs, to test wraparound.
* Unlike test_consume_xids which is passed number of xids to be consumed,
* this function is given the target Oid.
*/
Datum
test_consume_oids(PG_FUNCTION_ARGS)
{
int32 oid = PG_GETARG_INT32(0);
while (oid != GetNewObjectId());
PG_RETURN_VOID();
}
/*
* test_consume_xids(int4), for rapidly consuming XIDs, to test wraparound.
*/