Skip to content

PKG-895: Allow citus and timescaledb to compile #469

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

Open
wants to merge 1 commit into
base: TDE_REL_17_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contrib/pg_tde/src/pg_tde.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ _PG_init(void)
shmem_request_hook = tde_shmem_request;
prev_shmem_startup_hook = shmem_startup_hook;
shmem_startup_hook = tde_shmem_startup;

allow_upstream_smgr_api = false;
}

static void
Expand Down
8 changes: 4 additions & 4 deletions src/backend/access/heap/heapam_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ heapam_relation_set_new_filelocator(Relation rel,
*/
*minmulti = GetOldestMultiXactId();

srel = RelationCreateStorage(oldlocator, *newrlocator, persistence, true);
srel = RelationCreateStorage2(oldlocator, *newrlocator, persistence, true);

/*
* If required, set up an init fork for an unlogged table so that it can
Expand All @@ -618,7 +618,7 @@ heapam_relation_set_new_filelocator(Relation rel,
Assert(rel->rd_rel->relkind == RELKIND_RELATION ||
rel->rd_rel->relkind == RELKIND_MATVIEW ||
rel->rd_rel->relkind == RELKIND_TOASTVALUE);
smgrcreate(oldlocator, srel, INIT_FORKNUM, false);
smgrcreate2(oldlocator, srel, INIT_FORKNUM, false);
log_smgrcreate(newrlocator, INIT_FORKNUM);
}

Expand Down Expand Up @@ -651,7 +651,7 @@ heapam_relation_copy_data(Relation rel, const RelFileLocator *newrlocator)
* NOTE: any conflict in relfilenumber value will be caught in
* RelationCreateStorage().
*/
dstrel = RelationCreateStorage(rel->rd_locator, *newrlocator, rel->rd_rel->relpersistence, true);
dstrel = RelationCreateStorage2(rel->rd_locator, *newrlocator, rel->rd_rel->relpersistence, true);

/* copy main fork */
RelationCopyStorage(RelationGetSmgr(rel), dstrel, MAIN_FORKNUM,
Expand All @@ -663,7 +663,7 @@ heapam_relation_copy_data(Relation rel, const RelFileLocator *newrlocator)
{
if (smgrexists(RelationGetSmgr(rel), forkNum))
{
smgrcreate(rel->rd_locator, dstrel, forkNum, false);
smgrcreate2(rel->rd_locator, dstrel, forkNum, false);

/*
* WAL log creation if the relation is persistent, or this is the
Expand Down
2 changes: 1 addition & 1 deletion src/backend/access/transam/xlogutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ XLogReadBufferExtended(RelFileLocator rlocator, ForkNumber forknum,
* filesystem loses an inode during a crash. Better to write the data
* until we are actually told to delete the file.)
*/
smgrcreate(rlocator, smgr, forknum, true);
smgrcreate2(rlocator, smgr, forknum, true);

lastblock = smgrnblocks(smgr, forknum);

Expand Down
2 changes: 1 addition & 1 deletion src/backend/catalog/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ heap_create(const char *relname,
relpersistence,
relfrozenxid, relminmxid);
else if (RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
RelationCreateStorage(prev_rlocator, new_rlocator, relpersistence, true);
RelationCreateStorage2(prev_rlocator, new_rlocator, relpersistence, true);
else
Assert(false);

Expand Down
35 changes: 32 additions & 3 deletions src/backend/catalog/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,35 @@ UpdateIndexRelation(Oid indexoid,
heap_freetuple(tuple);
}

extern Oid index_create(Relation heapRelation,
const char *indexRelationName,
Oid indexRelationId,
Oid parentIndexRelid,
Oid parentConstraintId,
RelFileNumber relFileNumber,
IndexInfo *indexInfo,
const List *indexColNames,
Oid accessMethodId,
Oid tableSpaceId,
const Oid *collationIds,
const Oid *opclassIds,
const Datum *opclassOptions,
const int16 *coloptions,
const NullableDatum *stattargets,
Datum reloptions,
bits16 flags,
bits16 constr_flags,
bool allow_system_table_mods,
bool is_internal,
Oid *constraintId)
{
if(!allow_upstream_smgr_api) {
elog(FATAL, "An extension is trying to use the traditional index_create method, while another loaded extension (pg_tde) requires the new API.");
}
return index_create2(heapRelation, indexRelationName, indexRelationId, parentIndexRelid, parentConstraintId, relFileNumber,
indexInfo, indexColNames, accessMethodId, tableSpaceId, collationIds, opclassIds, opclassOptions, coloptions, stattargets, reloptions,
flags, constr_flags, allow_system_table_mods, is_internal, constraintId, NULL);
}

/*
* index_create
Expand Down Expand Up @@ -721,7 +750,7 @@ UpdateIndexRelation(Oid indexoid,
* Returns the OID of the created index.
*/
Oid
index_create(Relation heapRelation,
index_create2(Relation heapRelation,
const char *indexRelationName,
Oid indexRelationId,
Oid parentIndexRelid,
Expand Down Expand Up @@ -1441,7 +1470,7 @@ index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId,
* ensure a consistent state at all times. That is why parentIndexRelid
* is not set here.
*/
newIndexId = index_create(heapRelation,
newIndexId = index_create2(heapRelation,
newName,
InvalidOid, /* indexRelationId */
InvalidOid, /* parentIndexRelid */
Expand Down Expand Up @@ -3030,7 +3059,7 @@ index_build(Relation heapRelation,
if (indexRelation->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
!smgrexists(RelationGetSmgr(indexRelation), INIT_FORKNUM))
{
smgrcreate(indexRelation->rd_locator, RelationGetSmgr(indexRelation), INIT_FORKNUM, false);
smgrcreate2(indexRelation->rd_locator, RelationGetSmgr(indexRelation), INIT_FORKNUM, false);
log_smgrcreate(&indexRelation->rd_locator, INIT_FORKNUM);
indexRelation->rd_indam->ambuildempty(indexRelation);
}
Expand Down
18 changes: 14 additions & 4 deletions src/backend/catalog/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ AddPendingSync(const RelFileLocator *rlocator)
pending->is_truncated = false;
}

extern SMgrRelation RelationCreateStorage(RelFileLocator rlocator,
char relpersistence,
bool register_delete)
{
if(!allow_upstream_smgr_api) {
elog(FATAL, "An extension is trying to use the traditional RelationCreateStorage method, while another loaded extension (pg_tde) requires the new API.");
}
return RelationCreateStorage2(rlocator, rlocator, relpersistence, register_delete);
}

/*
* RelationCreateStorage
* Create physical storage for a relation.
Expand All @@ -118,7 +128,7 @@ AddPendingSync(const RelFileLocator *rlocator)
* pass register_delete = false.
*/
SMgrRelation
RelationCreateStorage(RelFileLocator oldlocator, RelFileLocator rlocator, char relpersistence,
RelationCreateStorage2(RelFileLocator oldlocator, RelFileLocator rlocator, char relpersistence,
bool register_delete)
{
SMgrRelation srel;
Expand Down Expand Up @@ -147,7 +157,7 @@ RelationCreateStorage(RelFileLocator oldlocator, RelFileLocator rlocator, char r
}

srel = smgropen(rlocator, procNumber);
smgrcreate(oldlocator, srel, MAIN_FORKNUM, false);
smgrcreate2(oldlocator, srel, MAIN_FORKNUM, false);

if (needs_wal)
log_smgrcreate(&srel->smgr_rlocator.locator, MAIN_FORKNUM);
Expand Down Expand Up @@ -976,7 +986,7 @@ smgr_redo(XLogReaderState *record)
SMgrRelation reln;

reln = smgropen(xlrec->rlocator, INVALID_PROC_NUMBER);
smgrcreate(xlrec->rlocator, reln, xlrec->forkNum, true);
smgrcreate2(xlrec->rlocator, reln, xlrec->forkNum, true);
}
else if (info == XLOG_SMGR_TRUNCATE)
{
Expand All @@ -997,7 +1007,7 @@ smgr_redo(XLogReaderState *record)
* XLogReadBufferForRedo, we prefer to recreate the rel and replay the
* log as best we can until the drop is seen.
*/
smgrcreate(xlrec->rlocator, reln, MAIN_FORKNUM, true);
smgrcreate2(xlrec->rlocator, reln, MAIN_FORKNUM, true);

/*
* Before we perform the truncation, update minimum recovery point to
Expand Down
2 changes: 1 addition & 1 deletion src/backend/catalog/toasting.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
coloptions[0] = 0;
coloptions[1] = 0;

index_create(toast_rel, toast_idxname, toastIndexOid, InvalidOid,
index_create2(toast_rel, toast_idxname, toastIndexOid, InvalidOid,
InvalidOid, InvalidOid,
indexInfo,
list_make2("chunk_id", "chunk_seq"),
Expand Down
2 changes: 1 addition & 1 deletion src/backend/commands/indexcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ DefineIndex(Oid tableId,
constr_flags |= INDEX_CONSTR_CREATE_INIT_DEFERRED;

indexRelationId =
index_create(rel, indexRelationName, indexRelationId, parentIndexId,
index_create2(rel, indexRelationName, indexRelationId, parentIndexId,
parentConstraintId,
stmt->oldNumber, indexInfo, indexColNames,
accessMethodId, tablespaceId,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/commands/sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ fill_seq_with_data(Relation rel, HeapTuple tuple)
SMgrRelation srel;

srel = smgropen(rel->rd_locator, INVALID_PROC_NUMBER);
smgrcreate(rel->rd_locator, srel, INIT_FORKNUM, false);
smgrcreate2(rel->rd_locator, srel, INIT_FORKNUM, false);
log_smgrcreate(&rel->rd_locator, INIT_FORKNUM);
fill_seq_fork_with_data(rel, tuple, INIT_FORKNUM);
FlushRelationBuffers(rel);
Expand Down
4 changes: 2 additions & 2 deletions src/backend/commands/tablecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -15540,7 +15540,7 @@ index_copy_data(Relation rel, RelFileLocator newrlocator)
* NOTE: any conflict in relfilenumber value will be caught in
* RelationCreateStorage().
*/
dstrel = RelationCreateStorage(rel->rd_locator, newrlocator, rel->rd_rel->relpersistence, true);
dstrel = RelationCreateStorage2(rel->rd_locator, newrlocator, rel->rd_rel->relpersistence, true);

/* copy main fork */
RelationCopyStorage(RelationGetSmgr(rel), dstrel, MAIN_FORKNUM,
Expand All @@ -15552,7 +15552,7 @@ index_copy_data(Relation rel, RelFileLocator newrlocator)
{
if (smgrexists(RelationGetSmgr(rel), forkNum))
{
smgrcreate(rel->rd_locator, dstrel, forkNum, false);
smgrcreate2(rel->rd_locator, dstrel, forkNum, false);

/*
* WAL log creation if the relation is persistent, or this is the
Expand Down
6 changes: 3 additions & 3 deletions src/backend/storage/buffer/bufmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ ExtendBufferedRelTo(BufferManagerRelation bmr,

/* recheck, fork might have been created concurrently */
if (!smgrexists(bmr.smgr, fork))
smgrcreate(bmr.rel->rd_locator, bmr.smgr, fork, flags & EB_PERFORMING_RECOVERY);
smgrcreate2(bmr.rel->rd_locator, bmr.smgr, fork, flags & EB_PERFORMING_RECOVERY);

UnlockRelationForExtension(bmr.rel, ExclusiveLock);
}
Expand Down Expand Up @@ -4788,7 +4788,7 @@ CreateAndCopyRelationData(RelFileLocator src_rlocator,
* directory. Therefore, each individual relation doesn't need to be
* registered for cleanup.
*/
RelationCreateStorage(src_rlocator, dst_rlocator, relpersistence, false);
RelationCreateStorage2(src_rlocator, dst_rlocator, relpersistence, false);

/* copy main fork. */
RelationCopyStorageUsingBuffer(src_rlocator, dst_rlocator, MAIN_FORKNUM,
Expand All @@ -4801,7 +4801,7 @@ CreateAndCopyRelationData(RelFileLocator src_rlocator,
if (smgrexists(src_rel, forkNum))
{
/* TODO: for sure? */
smgrcreate(src_rel->smgr_rlocator.locator, dst_rel, forkNum, false);
smgrcreate2(src_rel->smgr_rlocator.locator, dst_rel, forkNum, false);

/*
* WAL log creation if the relation is persistent, or this is the
Expand Down
13 changes: 12 additions & 1 deletion src/backend/storage/smgr/smgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ static Size LargestSMgrRelationSize = 0;
char *storage_manager_string;
SMgrId storage_manager_id;

bool allow_upstream_smgr_api = true;

/*
* Each backend has a hashtable that stores all extant SMgrRelation objects.
* In addition, "unpinned" SMgrRelation objects are chained together in a list.
Expand Down Expand Up @@ -399,6 +401,15 @@ smgrexists(SMgrRelation reln, ForkNumber forknum)
return smgrsw[reln->smgr_which].smgr_exists(reln, forknum);
}

void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
{
if(!allow_upstream_smgr_api) {
elog(FATAL, "An extension is trying to use the traditional smgrcreate method, while another loaded extension (pg_tde) requires the new API.");
}

smgrcreate2(reln->smgr_rlocator.locator, reln, forknum, isRedo);
}

/*
* smgrcreate() -- Create a new relation.
*
Expand All @@ -407,7 +418,7 @@ smgrexists(SMgrRelation reln, ForkNumber forknum)
* to be created.
*/
void
smgrcreate(RelFileLocator relold, SMgrRelation reln, ForkNumber forknum, bool isRedo)
smgrcreate2(RelFileLocator relold, SMgrRelation reln, ForkNumber forknum, bool isRedo)
{
smgrsw[reln->smgr_which].smgr_create(relold, reln, forknum, isRedo);
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/utils/cache/relcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -3876,7 +3876,7 @@ RelationSetNewRelfilenumber(Relation relation, char persistence)
/* handle these directly, at least for now */
SMgrRelation srel;

srel = RelationCreateStorage(relation->rd_locator, newrlocator, persistence, true);
srel = RelationCreateStorage2(relation->rd_locator, newrlocator, persistence, true);
smgrclose(srel);
}
else
Expand Down
22 changes: 22 additions & 0 deletions src/include/catalog/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ extern void index_check_primary_key(Relation heapRel,
#define INDEX_CREATE_INVALID (1 << 6)

extern Oid index_create(Relation heapRelation,
const char *indexRelationName,
Oid indexRelationId,
Oid parentIndexRelid,
Oid parentConstraintId,
RelFileNumber relFileNumber,
IndexInfo *indexInfo,
const List *indexColNames,
Oid accessMethodId,
Oid tableSpaceId,
const Oid *collationIds,
const Oid *opclassIds,
const Datum *opclassOptions,
const int16 *coloptions,
const NullableDatum *stattargets,
Datum reloptions,
bits16 flags,
bits16 constr_flags,
bool allow_system_table_mods,
bool is_internal,
Oid *constraintId);

extern Oid index_create2(Relation heapRelation,
const char *indexRelationName,
Oid indexRelationId,
Oid parentIndexRelid,
Expand Down
5 changes: 4 additions & 1 deletion src/include/catalog/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
/* GUC variables */
extern PGDLLIMPORT int wal_skip_threshold;

extern SMgrRelation RelationCreateStorage(RelFileLocator oldlocator,
extern SMgrRelation RelationCreateStorage(RelFileLocator rlocator,
char relpersistence,
bool register_delete);
extern SMgrRelation RelationCreateStorage2(RelFileLocator oldlocator,
RelFileLocator rlocator,
char relpersistence,
bool register_delete);
Expand Down
4 changes: 3 additions & 1 deletion src/include/storage/smgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef uint8 SMgrId;
#define MaxSMgrId UINT8_MAX

extern PGDLLIMPORT SMgrId storage_manager_id;
extern bool allow_upstream_smgr_api;

/*
* smgr.c maintains a table of SMgrRelation objects, which are essentially
Expand Down Expand Up @@ -130,7 +131,8 @@ extern void smgrdestroyall(void);
extern void smgrrelease(SMgrRelation reln);
extern void smgrreleaseall(void);
extern void smgrreleaserellocator(RelFileLocatorBackend rlocator);
extern void smgrcreate(RelFileLocator relold, SMgrRelation reln, ForkNumber forknum, bool isRedo);
extern void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo);
extern void smgrcreate2(RelFileLocator relold, SMgrRelation reln, ForkNumber forknum, bool isRedo);
extern void smgrdosyncall(SMgrRelation *rels, int nrels);
extern void smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo);
extern void smgrextend(SMgrRelation reln, ForkNumber forknum,
Expand Down
Loading