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

Method LogAndApply

src/leveldb/db/version_set.cc:778–861  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

776}
777
778Status VersionSet::LogAndApply(VersionEdit* edit, port::Mutex* mu) {
779 if (edit->has_log_number_) {
780 assert(edit->log_number_ >= log_number_);
781 assert(edit->log_number_ < next_file_number_);
782 } else {
783 edit->SetLogNumber(log_number_);
784 }
785
786 if (!edit->has_prev_log_number_) {
787 edit->SetPrevLogNumber(prev_log_number_);
788 }
789
790 edit->SetNextFile(next_file_number_);
791 edit->SetLastSequence(last_sequence_);
792
793 Version* v = new Version(this);
794 {
795 Builder builder(this, current_);
796 builder.Apply(edit);
797 builder.SaveTo(v);
798 }
799 Finalize(v);
800
801 // Initialize new descriptor log file if necessary by creating
802 // a temporary file that contains a snapshot of the current version.
803 std::string new_manifest_file;
804 Status s;
805 if (descriptor_log_ == nullptr) {
806 // No reason to unlock *mu here since we only hit this path in the
807 // first call to LogAndApply (when opening the database).
808 assert(descriptor_file_ == nullptr);
809 new_manifest_file = DescriptorFileName(dbname_, manifest_file_number_);
810 edit->SetNextFile(next_file_number_);
811 s = env_->NewWritableFile(new_manifest_file, &descriptor_file_);
812 if (s.ok()) {
813 descriptor_log_ = new log::Writer(descriptor_file_);
814 s = WriteSnapshot(descriptor_log_);
815 }
816 }
817
818 // Unlock during expensive MANIFEST log write
819 {
820 mu->Unlock();
821
822 // Write new record to MANIFEST log
823 if (s.ok()) {
824 std::string record;
825 edit->EncodeTo(&record);
826 s = descriptor_log_->AddRecord(record);
827 if (s.ok()) {
828 s = descriptor_file_->Sync();
829 }
830 if (!s.ok()) {
831 Log(options_->info_log, "MANIFEST write: %s\n", s.ToString().c_str());
832 }
833 }
834
835 // If we just created a new descriptor file, install it by writing a

Callers 5

BM_LogAndApplyFunction · 0.80
CompactMemTableMethod · 0.80
BackgroundCompactionMethod · 0.80
OpenMethod · 0.80

Calls 15

DescriptorFileNameFunction · 0.85
LogFunction · 0.85
SetCurrentFileFunction · 0.85
SetLogNumberMethod · 0.80
SetPrevLogNumberMethod · 0.80
SetNextFileMethod · 0.80
ApplyMethod · 0.80
SaveToMethod · 0.80
UnlockMethod · 0.80
AddRecordMethod · 0.80
LockMethod · 0.80
SetLastSequenceMethod · 0.45

Tested by 1

BM_LogAndApplyFunction · 0.64