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

Method writeKV_impl

fdbclient/FileBackupAgent.actor.cpp:652–678  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

650
651 // Start a new block if needed, then write the key and value
652 ACTOR static Future<Void> writeKV_impl(LogFileWriter* self, Key k, Value v) {
653 // If key and value do not fit in this block, end it and start a new one
654 int toWrite = sizeof(int32_t) + k.size() + sizeof(int32_t) + v.size();
655 if (self->file->size() + toWrite > self->blockEnd) {
656 // Write padding if needed
657 int bytesLeft = self->blockEnd - self->file->size();
658 if (bytesLeft > 0) {
659 state Value paddingFFs = makePadding(bytesLeft);
660 wait(self->file->append(paddingFFs.begin(), bytesLeft));
661 }
662
663 // Set new blockEnd
664 self->blockEnd += self->blockSize;
665
666 // write the block header
667 wait(self->file->append((uint8_t*)&BACKUP_AGENT_MLOG_VERSION, sizeof(BACKUP_AGENT_MLOG_VERSION)));
668 }
669
670 wait(self->file->appendStringRefWithLen(k));
671 wait(self->file->appendStringRefWithLen(v));
672
673 // At this point we should be in whatever the current block is or the block size is too small
674 if (self->file->size() > self->blockEnd)
675 throw backup_bad_block_size();
676
677 return Void();
678 }
679
680 Future<Void> writeKV(Key k, Value v) { return writeKV_impl(this, k, v); }
681

Callers

nothing calls this directly

Calls 6

makePaddingFunction · 0.85
VoidClass · 0.50
sizeMethod · 0.45
appendMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected