* Merge the specified updates into the appropriate "real" map, * and write out the changes. This function must be used for committing * updates during normal multiuser operation. */
| 962 | * updates during normal multiuser operation. |
| 963 | */ |
| 964 | static void |
| 965 | perform_relmap_update(bool shared, const RelMapFile *updates) |
| 966 | { |
| 967 | RelMapFile newmap; |
| 968 | |
| 969 | /* |
| 970 | * Anyone updating a relation's mapping info should take exclusive lock on |
| 971 | * that rel and hold it until commit. This ensures that there will not be |
| 972 | * concurrent updates on the same mapping value; but there could easily be |
| 973 | * concurrent updates on different values in the same file. We cover that |
| 974 | * by acquiring the RelationMappingLock, re-reading the target file to |
| 975 | * ensure it's up to date, applying the updates, and writing the data |
| 976 | * before releasing RelationMappingLock. |
| 977 | * |
| 978 | * There is only one RelationMappingLock. In principle we could try to |
| 979 | * have one per mapping file, but it seems unlikely to be worth the |
| 980 | * trouble. |
| 981 | */ |
| 982 | LWLockAcquire(RelationMappingLock, LW_EXCLUSIVE); |
| 983 | |
| 984 | /* Be certain we see any other updates just made */ |
| 985 | load_relmap_file(shared, true); |
| 986 | |
| 987 | /* Prepare updated data in a local variable */ |
| 988 | if (shared) |
| 989 | memcpy(&newmap, &shared_map, sizeof(RelMapFile)); |
| 990 | else |
| 991 | memcpy(&newmap, &local_map, sizeof(RelMapFile)); |
| 992 | |
| 993 | /* |
| 994 | * Apply the updates to newmap. No new mappings should appear, unless |
| 995 | * somebody is adding indexes to system catalogs. |
| 996 | */ |
| 997 | merge_map_updates(&newmap, updates, false); |
| 998 | |
| 999 | /* Write out the updated map and do other necessary tasks */ |
| 1000 | write_relmap_file(shared, &newmap, true, true, true, |
| 1001 | (shared ? InvalidOid : MyDatabaseId), |
| 1002 | (shared ? GLOBALTABLESPACE_OID : MyDatabaseTableSpace), |
| 1003 | DatabasePath); |
| 1004 | |
| 1005 | /* Now we can release the lock */ |
| 1006 | LWLockRelease(RelationMappingLock); |
| 1007 | } |
| 1008 | |
| 1009 | /* |
| 1010 | * RELMAP resource manager's routines |
no test coverage detected