Skip to content
Jingyu Zhou edited this page May 3, 2023 · 1 revision

Quote from Steve on https://github.com/apple/foundationdb/pull/10111

It's true that the best solution would be to prevent the same file from being opened multiple times for write and make subsequent opens wait for the prior instance to be dropped, but I'm not taking on that task right now. I think the open file map needed already exists, it's just not being used in this way and doing so is likely to hit some tricky correctness issues around process killing and restarts.

When you open a file, it's actually opened many times at once by a stack of IAsyncFiles which proxy each other. The stack is something like:

  • AsyncFileCached, optional based on cached/uncached open() option. This class has a static map of open files so multiple opens return the same handle.
  • AsyncFileWriteChecker, optionally injected
  • AsyncFileChaos, optionally injected
  • AsyncFileDetachable
  • AsyncFileNonDurable - These handles are stored in g_simulator->getCurrentProcess()->machine->openFiles by name and are not closed until the virtual process/machine is killed/rebooted.
  • SimpleFile

The serialization point should probably be where the AsyncFileNonDurable handle is read from the openFiles map for the virtual process. It could be possible for multiple instances of any of the classes above this point in the stack to exist at the same time for the same underlying file, they just would not be used at the same time since the open() calls will wait for underlying AsyncFileNonDurable handle to become free.

Clone this wiki locally