* GetNewRelFileNode * Generate a new relfilenode number that is unique within the * database of the given tablespace. * * If the relfilenode will also be used as the relation's OID, pass the * opened pg_class catalog, and this routine will guarantee that the result * is also an unused OID within pg_class. If the result is to be used only * as a relfilenode for an existing relation, pass
| 820 | * created by bootstrap have preassigned OIDs, so there's no need. |
| 821 | */ |
| 822 | Oid |
| 823 | GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence) |
| 824 | { |
| 825 | RelFileNodeBackend rnode; |
| 826 | bool collides; |
| 827 | BackendId backend; |
| 828 | |
| 829 | /* |
| 830 | * If we ever get here during pg_upgrade, there's something wrong; all |
| 831 | * relfilenode assignments during a binary-upgrade run should be |
| 832 | * determined by commands in the dump script. |
| 833 | * |
| 834 | * GPDB: Totally OK in Cloudberry. We don't use the table's OID as its |
| 835 | * initial relfilenode, and rely on this in binary upgrade, too. |
| 836 | */ |
| 837 | //Assert(!IsBinaryUpgrade); |
| 838 | |
| 839 | switch (relpersistence) |
| 840 | { |
| 841 | case RELPERSISTENCE_TEMP: |
| 842 | backend = BackendIdForTempRelations(); |
| 843 | break; |
| 844 | case RELPERSISTENCE_UNLOGGED: |
| 845 | case RELPERSISTENCE_PERMANENT: |
| 846 | backend = InvalidBackendId; |
| 847 | break; |
| 848 | default: |
| 849 | elog(ERROR, "invalid relpersistence: %c", relpersistence); |
| 850 | return InvalidOid; /* placate compiler */ |
| 851 | } |
| 852 | |
| 853 | /* This logic should match RelationInitPhysicalAddr */ |
| 854 | rnode.node.spcNode = reltablespace ? reltablespace : MyDatabaseTableSpace; |
| 855 | rnode.node.dbNode = (rnode.node.spcNode == GLOBALTABLESPACE_OID) ? InvalidOid : MyDatabaseId; |
| 856 | |
| 857 | /* |
| 858 | * The relpath will vary based on the backend ID, so we must initialize |
| 859 | * that properly here to make sure that any collisions based on filename |
| 860 | * are properly detected. |
| 861 | */ |
| 862 | rnode.backend = backend; |
| 863 | |
| 864 | do |
| 865 | { |
| 866 | CHECK_FOR_INTERRUPTS(); |
| 867 | |
| 868 | /* Generate the Relfilenode */ |
| 869 | rnode.node.relNode = GetNewSegRelfilenode(); |
| 870 | |
| 871 | collides = GpCheckRelFileCollision(rnode); |
| 872 | |
| 873 | if (!collides && rnode.node.spcNode != GLOBALTABLESPACE_OID) |
| 874 | { |
| 875 | /* |
| 876 | * GPDB_91_MERGE_FIXME: check again for a collision with a temp |
| 877 | * table (if this is a normal relation) or a normal table (if this |
| 878 | * is a temp relation). |
| 879 | * |
no test coverage detected