Add O_EXCL to MirroredBufferPool_DoOpen create file
This is needed to prevent relations possibly overwriting each
other. The O_EXCL is present in postgres's mdcreate() but for some
reason we don't have it here. This adds it back.
@@ -252,8 +252,9 @@ static void MirroredBufferPool_DoOpen(
*primaryError = 0;
*mirrorDataLossOccurred = false;
+ /* Using O_EXCL to make it atomic operation to avoid overwriting an existing file. */
if (create)
- fileFlags = O_CREAT | O_RDWR | PG_BINARY;
+ fileFlags = O_CREAT | O_RDWR | O_EXCL | PG_BINARY;
PersistentTablespace_GetPrimaryAndMirrorFilespaces(
relFileNode->spcNode,
