From f670195627c98f06219a7aa6bf94b141ad1ad8ce Mon Sep 17 00:00:00 2001 From: Jimmy Yih Date: Tue, 4 Apr 2017 11:21:15 -0700 Subject: [PATCH] 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. Signed-off-by: Xin Zhang --- src/backend/cdb/cdbmirroredbufferpool.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/cdb/cdbmirroredbufferpool.c b/src/backend/cdb/cdbmirroredbufferpool.c index 5823e176e1..84fb0a7387 100755 --- a/src/backend/cdb/cdbmirroredbufferpool.c +++ b/src/backend/cdb/cdbmirroredbufferpool.c @@ -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, -- GitLab