| 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 | } |
nothing calls this directly
no test coverage detected