From 78e81e514a46ebf758e766aca9de3811df518ab5 Mon Sep 17 00:00:00 2001 From: Evan Tschannen Date: Fri, 19 Mar 2021 13:11:52 -0700 Subject: [PATCH] fix: OPEN_ATOMIC_WRITE_AND_CREATE did not create a new file handle for the replacement file, so when the disk queue calls replaceFile, truncates against the old file handle will happen on the new file resulting in corruption --- fdbrpc/sim2.actor.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/fdbrpc/sim2.actor.cpp b/fdbrpc/sim2.actor.cpp index b169a62911..16b18ff00b 100644 --- a/fdbrpc/sim2.actor.cpp +++ b/fdbrpc/sim2.actor.cpp @@ -738,7 +738,6 @@ private: .detail("FileCount", machineCache.count(self->filename)); renameFile(sourceFilename.c_str(), self->filename.c_str()); - ASSERT(!machineCache.count(self->filename)); machineCache[self->filename] = machineCache[sourceFilename]; machineCache.erase(sourceFilename); self->actualFilename = self->filename; @@ -2479,19 +2478,19 @@ Future> Sim2FileSystem::open(const std::string& file if (flags & IAsyncFile::OPEN_UNCACHED) { auto& machineCache = g_simulator.getCurrentProcess()->machine->openFiles; std::string actualFilename = filename; - if (machineCache.find(filename) == machineCache.end()) { - if (flags & IAsyncFile::OPEN_ATOMIC_WRITE_AND_CREATE) { - actualFilename = filename + ".part"; - auto partFile = machineCache.find(actualFilename); - if (partFile != machineCache.end()) { - Future> f = AsyncFileDetachable::open(partFile->second); - if (FLOW_KNOBS->PAGE_WRITE_CHECKSUM_HISTORY > 0) - f = map(f, [=](Reference r) { - return Reference(new AsyncFileWriteChecker(r)); - }); - return f; - } + if (flags & IAsyncFile::OPEN_ATOMIC_WRITE_AND_CREATE) { + actualFilename = filename + ".part"; + auto partFile = machineCache.find(actualFilename); + if (partFile != machineCache.end()) { + Future> f = AsyncFileDetachable::open(partFile->second); + if (FLOW_KNOBS->PAGE_WRITE_CHECKSUM_HISTORY > 0) + f = map(f, [=](Reference r) { + return Reference(new AsyncFileWriteChecker(r)); + }); + return f; } + } + if (machineCache.find(actualFilename) == machineCache.end()) { // Simulated disk parameters are shared by the AsyncFileNonDurable and the underlying SimpleFile. // This way, they can both keep up with the time to start the next operation auto diskParameters =