* 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. */
| 122 | * transaction aborts later on, the storage will be destroyed. |
| 123 | */ |
| 124 | SMgrRelation |
| 125 | RelationCreateStorage(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. |
no test coverage detected