MCPcopy Create free account
hub / github.com/apple/foundationdb / open

Method open

fdbrpc/sim2.actor.cpp:514–571  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

512 static bool should_poll() { return false; }
513
514 ACTOR static Future<Reference<IAsyncFile>> open(
515 std::string filename,
516 int flags,
517 int mode,
518 Reference<DiskParameters> diskParameters = makeReference<DiskParameters>(25000, 150000000),
519 bool delayOnWrite = true) {
520 state ISimulator::ProcessInfo* currentProcess = g_simulator.getCurrentProcess();
521 state TaskPriority currentTaskID = g_network->getCurrentTask();
522
523 if (++openCount >= 3000) {
524 TraceEvent(SevError, "TooManyFiles").log();
525 ASSERT(false);
526 }
527
528 if (openCount == 2000) {
529 TraceEvent(SevWarnAlways, "DisableConnectionFailures_TooManyFiles").log();
530 g_simulator.speedUpSimulation = true;
531 g_simulator.connectionFailuresDisableDuration = 1e6;
532 }
533
534 // Filesystems on average these days seem to start to have limits of around 255 characters for a
535 // filename. We add ".part" below, so we need to stay under 250.
536 ASSERT(basename(filename).size() < 250);
537
538 wait(g_simulator.onMachine(currentProcess));
539 try {
540 wait(delay(FLOW_KNOBS->MIN_OPEN_TIME +
541 deterministicRandom()->random01() * (FLOW_KNOBS->MAX_OPEN_TIME - FLOW_KNOBS->MIN_OPEN_TIME)));
542
543 std::string open_filename = filename;
544 if (flags & OPEN_ATOMIC_WRITE_AND_CREATE) {
545 ASSERT((flags & OPEN_CREATE) && (flags & OPEN_READWRITE) && !(flags & OPEN_EXCLUSIVE));
546 open_filename = filename + ".part";
547 }
548
549 int h = sf_open(open_filename.c_str(), flags, flagConversion(flags), mode);
550 if (h == -1) {
551 bool notFound = errno == ENOENT;
552 Error e = notFound ? file_not_found() : io_error();
553 TraceEvent(notFound ? SevWarn : SevWarnAlways, "FileOpenError")
554 .error(e)
555 .GetLastError()
556 .detail("File", filename)
557 .detail("Flags", flags);
558 throw e;
559 }
560
561 platform::makeTemporary(open_filename.c_str());
562 SimpleFile* simpleFile = new SimpleFile(h, diskParameters, delayOnWrite, filename, open_filename, flags);
563 state Reference<IAsyncFile> file = Reference<IAsyncFile>(simpleFile);
564 wait(g_simulator.onProcess(currentProcess, currentTaskID));
565 return file;
566 } catch (Error& e) {
567 state Error err = e;
568 wait(g_simulator.onProcess(currentProcess, currentTaskID));
569 throw err;
570 }
571 }

Callers

nothing calls this directly

Calls 14

TraceEventClass · 0.85
basenameFunction · 0.85
delayFunction · 0.85
deterministicRandomFunction · 0.85
sf_openFunction · 0.85
makeTemporaryFunction · 0.85
getCurrentProcessMethod · 0.80
random01Method · 0.80
detailMethod · 0.80
getCurrentTaskMethod · 0.45
logMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected