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

Method write_impl

fdbrpc/sim2.actor.cpp:681–728  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

679 }
680
681 ACTOR static Future<Void> write_impl(SimpleFile* self, StringRef data, int64_t offset) {
682 state UID opId = deterministicRandom()->randomUniqueID();
683 if (randLog) {
684 uint32_t a = crc32c_append(0, data.begin(), data.size());
685 fmt::print(randLog,
686 "SFW1 {0} {1} {2} {3} {4} {5}\n",
687 self->dbgId.shortString(),
688 self->filename,
689 opId.shortString(),
690 a,
691 data.size(),
692 offset);
693 }
694
695 if (self->delayOnWrite)
696 wait(waitUntilDiskReady(self->diskParameters, data.size()));
697
698 if (_lseeki64(self->h, offset, SEEK_SET) == -1) {
699 TraceEvent(SevWarn, "SimpleFileIOError").detail("Location", 3);
700 throw io_error();
701 }
702
703 unsigned int write_bytes = 0;
704 if ((write_bytes = _write(self->h, (void*)data.begin(), data.size())) == -1) {
705 TraceEvent(SevWarn, "SimpleFileIOError").detail("Location", 4);
706 throw io_error();
707 }
708
709 if (write_bytes != data.size()) {
710 TraceEvent(SevWarn, "SimpleFileIOError").detail("Location", 5);
711 throw io_error();
712 }
713
714 if (randLog) {
715 fprintf(randLog,
716 "SFW2 %s %s %s\n",
717 self->dbgId.shortString().c_str(),
718 self->filename.c_str(),
719 opId.shortString().c_str());
720 }
721
722 debugFileCheck("SimpleFileWrite", self->filename, (void*)data.begin(), offset, data.size());
723
724 INJECT_FAULT(io_timeout, "SimpleFile::write"); // SimpleFile::write inject io_timeout
725 INJECT_FAULT(io_error, "SimpleFile::write"); // SimpleFile::write inject io_error
726
727 return Void();
728 }
729
730 ACTOR static Future<Void> truncate_impl(SimpleFile* self, int64_t size) {
731 state UID opId = deterministicRandom()->randomUniqueID();

Callers

nothing calls this directly

Calls 14

deterministicRandomFunction · 0.85
crc32c_appendFunction · 0.85
waitUntilDiskReadyFunction · 0.85
TraceEventClass · 0.85
fprintfFunction · 0.85
debugFileCheckFunction · 0.85
randomUniqueIDMethod · 0.80
shortStringMethod · 0.80
detailMethod · 0.80
VoidClass · 0.70
printFunction · 0.50
beginMethod · 0.45

Tested by

no test coverage detected