Skip to content
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
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 @@ -607,7 +607,7 @@ heapam_relation_set_new_filelocator(Relation rel,
*/
*minmulti = GetOldestMultiXactId();

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

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

Expand Down Expand Up @@ -650,7 +650,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 = RelationCreateStoragePercona(rel->rd_locator, *newrlocator, rel->rd_rel->relpersistence, true);

/* copy main fork */
RelationCopyStorage(RelationGetSmgr(rel), dstrel, MAIN_FORKNUM,
Expand All @@ -662,7 +662,7 @@ heapam_relation_copy_data(Relation rel, const RelFileLocator *newrlocator)
{
if (smgrexists(RelationGetSmgr(rel), forkNum))
{
smgrcreate(rel->rd_locator, dstrel, forkNum, false);
smgrcreate_percona(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 @@ -487,7 +487,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);
smgrcreate_percona(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 @@ -401,7 +401,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);
RelationCreateStoragePercona(prev_rlocator, new_rlocator, relpersistence, true);
else
Assert(false);

Expand Down
124 changes: 79 additions & 45 deletions src/backend/catalog/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,39 @@ UpdateIndexRelation(Oid indexoid,
heap_freetuple(tuple);
}

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 (!percona_allow_upstream_smgr_api)
elog(ERROR, "An extension is trying to use the traditional index_create method, while another loaded extension (pg_tde) requires the new API.");

return index_create_percona(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 @@ -723,28 +756,28 @@ UpdateIndexRelation(Oid indexoid,
* Returns the OID of the created index.
*/
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,
RelFileLocator *old_rlocator)
index_create_percona(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,
RelFileLocator *old_rlocator)
{
Oid heapRelationId = RelationGetRelid(heapRelation);
Relation pg_class;
Expand Down Expand Up @@ -1444,28 +1477,29 @@ 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,
newName,
InvalidOid, /* indexRelationId */
InvalidOid, /* parentIndexRelid */
InvalidOid, /* parentConstraintId */
InvalidRelFileNumber, /* relFileNumber */
newInfo,
indexColNames,
indexRelation->rd_rel->relam,
tablespaceOid,
indexRelation->rd_indcollation,
indclass->values,
opclassOptions,
indcoloptions->values,
stattargets,
reloptionsDatum,
INDEX_CREATE_SKIP_BUILD | INDEX_CREATE_CONCURRENT,
0,
true, /* allow table to be a system catalog? */
false, /* is_internal? */
NULL,
&indexRelation->rd_locator);
newIndexId = index_create_percona(heapRelation,
newName,
InvalidOid, /* indexRelationId */
InvalidOid, /* parentIndexRelid */
InvalidOid, /* parentConstraintId */
InvalidRelFileNumber, /* relFileNumber */
newInfo,
indexColNames,
indexRelation->rd_rel->relam,
tablespaceOid,
indexRelation->rd_indcollation,
indclass->values,
opclassOptions,
indcoloptions->values,
stattargets,
reloptionsDatum,
INDEX_CREATE_SKIP_BUILD | INDEX_CREATE_CONCURRENT,
0,
true, /* allow table to be a system
* catalog? */
false, /* is_internal? */
NULL,
&indexRelation->rd_locator);

/* Close the relations used and clean up */
index_close(indexRelation, NoLock);
Expand Down Expand Up @@ -3092,7 +3126,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);
smgrcreate_percona(indexRelation->rd_locator, RelationGetSmgr(indexRelation), INIT_FORKNUM, false);
log_smgrcreate(&indexRelation->rd_locator, INIT_FORKNUM);
indexRelation->rd_indam->ambuildempty(indexRelation);
}
Expand Down
21 changes: 16 additions & 5 deletions src/backend/catalog/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ AddPendingSync(const RelFileLocator *rlocator)
pending->is_truncated = false;
}

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

return RelationCreateStoragePercona(rlocator, rlocator, relpersistence, register_delete);
}

/*
* RelationCreateStorage
* Create physical storage for a relation.
Expand All @@ -119,8 +130,8 @@ AddPendingSync(const RelFileLocator *rlocator)
* pass register_delete = false.
*/
SMgrRelation
RelationCreateStorage(RelFileLocator oldlocator, RelFileLocator rlocator, char relpersistence,
bool register_delete)
RelationCreateStoragePercona(RelFileLocator oldlocator, RelFileLocator rlocator, char relpersistence,
bool register_delete)
{
SMgrRelation srel;
ProcNumber procNumber;
Expand Down Expand Up @@ -148,7 +159,7 @@ RelationCreateStorage(RelFileLocator oldlocator, RelFileLocator rlocator, char r
}

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

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

reln = smgropen(xlrec->rlocator, INVALID_PROC_NUMBER);
smgrcreate(xlrec->rlocator, reln, xlrec->forkNum, true);
smgrcreate_percona(xlrec->rlocator, reln, xlrec->forkNum, true);
}
else if (info == XLOG_SMGR_TRUNCATE)
{
Expand All @@ -1013,7 +1024,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);
smgrcreate_percona(xlrec->rlocator, reln, MAIN_FORKNUM, true);

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

index_create(toast_rel, toast_idxname, toastIndexOid, InvalidOid,
InvalidOid, InvalidOid,
indexInfo,
list_make2("chunk_id", "chunk_seq"),
BTREE_AM_OID,
rel->rd_rel->reltablespace,
collationIds, opclassIds, NULL, coloptions, NULL, (Datum) 0,
INDEX_CREATE_IS_PRIMARY, 0, true, true, NULL, NULL);
index_create_percona(toast_rel, toast_idxname, toastIndexOid, InvalidOid,
InvalidOid, InvalidOid,
indexInfo,
list_make2("chunk_id", "chunk_seq"),
BTREE_AM_OID,
rel->rd_rel->reltablespace,
collationIds, opclassIds, NULL, coloptions, NULL, (Datum) 0,
INDEX_CREATE_IS_PRIMARY, 0, true, true, NULL, NULL);

table_close(toast_rel, NoLock);

Expand Down
18 changes: 9 additions & 9 deletions src/backend/commands/indexcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1245,15 +1245,15 @@ DefineIndex(Oid tableId,
constr_flags |= INDEX_CONSTR_CREATE_WITHOUT_OVERLAPS;

indexRelationId =
index_create(rel, indexRelationName, indexRelationId, parentIndexId,
parentConstraintId,
stmt->oldNumber, indexInfo, indexColNames,
accessMethodId, tablespaceId,
collationIds, opclassIds, opclassOptions,
coloptions, NULL, reloptions,
flags, constr_flags,
allowSystemTableMods, !check_rights,
&createdConstraintId, NULL);
index_create_percona(rel, indexRelationName, indexRelationId, parentIndexId,
parentConstraintId,
stmt->oldNumber, indexInfo, indexColNames,
accessMethodId, tablespaceId,
collationIds, opclassIds, opclassOptions,
coloptions, NULL, reloptions,
flags, constr_flags,
allowSystemTableMods, !check_rights,
&createdConstraintId, NULL);

ObjectAddressSet(address, RelationRelationId, indexRelationId);

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);
smgrcreate_percona(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 @@ -17165,7 +17165,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 = RelationCreateStoragePercona(rel->rd_locator, newrlocator, rel->rd_rel->relpersistence, true);

/* copy main fork */
RelationCopyStorage(RelationGetSmgr(rel), dstrel, MAIN_FORKNUM,
Expand All @@ -17177,7 +17177,7 @@ index_copy_data(Relation rel, RelFileLocator newrlocator)
{
if (smgrexists(RelationGetSmgr(rel), forkNum))
{
smgrcreate(rel->rd_locator, dstrel, forkNum, false);
smgrcreate_percona(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 @@ -955,7 +955,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);
smgrcreate_percona(bmr.rel->rd_locator, bmr.smgr, fork, flags & EB_PERFORMING_RECOVERY);

UnlockRelationForExtension(bmr.rel, ExclusiveLock);
}
Expand Down Expand Up @@ -5257,7 +5257,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);
RelationCreateStoragePercona(src_rlocator, dst_rlocator, relpersistence, false);

/* copy main fork. */
RelationCopyStorageUsingBuffer(src_rlocator, dst_rlocator, MAIN_FORKNUM,
Expand All @@ -5270,7 +5270,7 @@ CreateAndCopyRelationData(RelFileLocator src_rlocator,
if (smgrexists(src_rel, forkNum))
{
/* TODO: for sure? */
smgrcreate(src_rel->smgr_rlocator.locator, dst_rel, forkNum, false);
smgrcreate_percona(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 @@ -84,6 +84,8 @@ static Size LargestSMgrRelationSize = 0;

SMgrId storage_manager_id;

bool percona_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 @@ -459,6 +461,15 @@ smgrexists(SMgrRelation reln, ForkNumber forknum)
return ret;
}

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

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

/*
* smgrcreate() -- Create a new relation.
*
Expand All @@ -467,7 +478,7 @@ smgrexists(SMgrRelation reln, ForkNumber forknum)
* to be created.
*/
void
smgrcreate(RelFileLocator relold, SMgrRelation reln, ForkNumber forknum, bool isRedo)
smgrcreate_percona(RelFileLocator relold, SMgrRelation reln, ForkNumber forknum, bool isRedo)
{
HOLD_INTERRUPTS();
smgrsw[reln->smgr_which].smgr_create(relold, reln, forknum, isRedo);
Expand Down
Loading