MCPcopy Create free account
hub / github.com/apache/cloudberry / RelationCreateStorage

Function RelationCreateStorage

src/backend/catalog/storage.c:124–177  ·  view source on GitHub ↗

* RelationCreateStorage * Create physical storage for a relation. * * Create the underlying disk file storage for the relation. This only * creates the main fork; additional forks are created lazily by the * modules that need them. * * This function is transactional. The creation is WAL-logged, and if the * transaction aborts later on, the storage will be destroyed. */

Source from the content-addressed store, hash-verified

122 * transaction aborts later on, the storage will be destroyed.
123 */
124SMgrRelation
125RelationCreateStorage(RelFileNode rnode, char relpersistence, SMgrImpl smgr_which, Relation rel)
126{
127 PendingRelDelete *pending;
128 SMgrRelation srel;
129 BackendId backend;
130 bool needs_wal;
131
132 Assert(!IsInParallelMode()); /* couldn't update pendingSyncHash */
133
134 switch (relpersistence)
135 {
136 case RELPERSISTENCE_TEMP:
137 backend = BackendIdForTempRelations();
138 needs_wal = false;
139 break;
140 case RELPERSISTENCE_UNLOGGED:
141 backend = InvalidBackendId;
142 needs_wal = false;
143 break;
144 case RELPERSISTENCE_PERMANENT:
145 backend = InvalidBackendId;
146 needs_wal = true;
147 break;
148 default:
149 elog(ERROR, "invalid relpersistence: %c", relpersistence);
150 return NULL; /* placate compiler */
151 }
152
153 srel = smgropen(rnode, backend, smgr_which, rel);
154 smgrcreate(srel, MAIN_FORKNUM, false);
155
156 if (needs_wal)
157 log_smgrcreate(&srel->smgr_rnode.node, MAIN_FORKNUM, smgr_which);
158
159 /* Add the relation to the list of stuff to delete at abort */
160 pending = (PendingRelDelete *)
161 MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete));
162 pending->relnode.node = rnode;
163 pending->relnode.isTempRelation = backend == TempRelBackendId;
164 pending->atCommit = false; /* delete if abort */
165 pending->nestLevel = GetCurrentTransactionNestLevel();
166 pending->relnode.smgr_which = smgr_which;
167 pending->action = &storage_pending_rel_deletes_action;
168 RegisterPendingDelete(pending);
169
170 if (relpersistence == RELPERSISTENCE_PERMANENT && !XLogIsNeeded())
171 {
172 Assert(backend == InvalidBackendId);
173 AddPendingSync(&rnode);
174 }
175
176 return srel;
177}
178
179/*
180 * Perform XLogInsert of an XLOG_SMGR_CREATE record to WAL.

Callers 10

PaxRelationCreateStorageFunction · 0.85
index_copy_dataFunction · 0.85
aoco_relation_copy_dataFunction · 0.85
heap_createFunction · 0.85

Calls 8

IsInParallelModeFunction · 0.85
smgropenFunction · 0.85
smgrcreateFunction · 0.85
log_smgrcreateFunction · 0.85
MemoryContextAllocFunction · 0.85
RegisterPendingDeleteFunction · 0.85
AddPendingSyncFunction · 0.85

Tested by

no test coverage detected