MCPcopy Create free account
hub / github.com/ElementsProject/elements / Apply

Method Apply

src/leveldb/db/version_set.cc:630–670  ·  view source on GitHub ↗

Apply all of the edits in *edit to the current state.

Source from the content-addressed store, hash-verified

628
629 // Apply all of the edits in *edit to the current state.
630 void Apply(VersionEdit* edit) {
631 // Update compaction pointers
632 for (size_t i = 0; i < edit->compact_pointers_.size(); i++) {
633 const int level = edit->compact_pointers_[i].first;
634 vset_->compact_pointer_[level] =
635 edit->compact_pointers_[i].second.Encode().ToString();
636 }
637
638 // Delete files
639 for (const auto& deleted_file_set_kvp : edit->deleted_files_) {
640 const int level = deleted_file_set_kvp.first;
641 const uint64_t number = deleted_file_set_kvp.second;
642 levels_[level].deleted_files.insert(number);
643 }
644
645 // Add new files
646 for (size_t i = 0; i < edit->new_files_.size(); i++) {
647 const int level = edit->new_files_[i].first;
648 FileMetaData* f = new FileMetaData(edit->new_files_[i].second);
649 f->refs = 1;
650
651 // We arrange to automatically compact this file after
652 // a certain number of seeks. Let's assume:
653 // (1) One seek costs 10ms
654 // (2) Writing or reading 1MB costs 10ms (100MB/s)
655 // (3) A compaction of 1MB does 25MB of IO:
656 // 1MB read from this level
657 // 10-12MB read from next level (boundaries may be misaligned)
658 // 10-12MB written to next level
659 // This implies that 25 seeks cost the same as the compaction
660 // of 1MB of data. I.e., one seek costs approximately the
661 // same as the compaction of 40KB of data. We are a little
662 // conservative and allow approximately one seek for every 16KB
663 // of data before triggering a compaction.
664 f->allowed_seeks = static_cast<int>((f->file_size / 16384U));
665 if (f->allowed_seeks < 100) f->allowed_seeks = 100;
666
667 levels_[level].deleted_files.erase(f->number);
668 levels_[level].added_files->insert(f);
669 }
670 }
671
672 // Save the current state in *v.
673 void SaveTo(Version* v) {

Callers 2

LogAndApplyMethod · 0.80
RecoverMethod · 0.80

Calls 5

sizeMethod · 0.45
ToStringMethod · 0.45
EncodeMethod · 0.45
insertMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected