@@ -2434,6 +2434,16 @@ void PageManager::allocTableSpace(thread_db* tdbb, ULONG tableSpaceID, bool crea
24342434 if (create)
24352435 {
24362436 newPageSpace->file = PIO_create (tdbb, fileName, false , false );
2437+ // When opening an existing TS, a pointer to this PageSpace can be added to pageSpaces at the end of the method.
2438+ // When creating a new TS, there is a need to add a new PageSpace to pageSpaces earlier.
2439+ // Because of the need to update the SCN (if the database SCN is greater than zero) during the creation of new TS pages.
2440+ // This early addition of a pointer to PageSpace will not create a race anywhere
2441+ // (due to the fact that there is a pointer to an incompletely constructed object for some time),
2442+ // because the TS metadata is not yet in the system table and no one can access this TS.
2443+ {
2444+ WriteLockGuard writeGuard (pageSpacesLock, FB_FUNCTION);
2445+ pageSpaces.add (newPageSpace);
2446+ }
24372447 PAG_format_pip (tdbb, *newPageSpace);
24382448 }
24392449 else
@@ -2445,12 +2455,20 @@ void PageManager::allocTableSpace(thread_db* tdbb, ULONG tableSpaceID, bool crea
24452455 }
24462456 catch (...)
24472457 {
2458+ if (create)
2459+ {
2460+ WriteLockGuard writeGuard (pageSpacesLock, FB_FUNCTION);
2461+ pageSpaces.findAndRemove (tableSpaceID);
2462+ }
24482463 delete newPageSpace;
24492464 throw ;
24502465 }
24512466
2452- WriteLockGuard writeGuard (pageSpacesLock, FB_FUNCTION);
2453- pageSpaces.add (newPageSpace);
2467+ if (!create)
2468+ {
2469+ WriteLockGuard writeGuard (pageSpacesLock, FB_FUNCTION);
2470+ pageSpaces.add (newPageSpace);
2471+ }
24542472 }
24552473}
24562474
0 commit comments