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

Method RecoverLogFile

src/leveldb/db/db_impl.cc:381–499  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

379}
380
381Status DBImpl::RecoverLogFile(uint64_t log_number, bool last_log,
382 bool* save_manifest, VersionEdit* edit,
383 SequenceNumber* max_sequence) {
384 struct LogReporter : public log::Reader::Reporter {
385 Env* env;
386 Logger* info_log;
387 const char* fname;
388 Status* status; // null if options_.paranoid_checks==false
389 void Corruption(size_t bytes, const Status& s) override {
390 Log(info_log, "%s%s: dropping %d bytes; %s",
391 (this->status == nullptr ? "(ignoring error) " : ""), fname,
392 static_cast<int>(bytes), s.ToString().c_str());
393 if (this->status != nullptr && this->status->ok()) *this->status = s;
394 }
395 };
396
397 mutex_.AssertHeld();
398
399 // Open the log file
400 std::string fname = LogFileName(dbname_, log_number);
401 SequentialFile* file;
402 Status status = env_->NewSequentialFile(fname, &file);
403 if (!status.ok()) {
404 MaybeIgnoreError(&status);
405 return status;
406 }
407
408 // Create the log reader.
409 LogReporter reporter;
410 reporter.env = env_;
411 reporter.info_log = options_.info_log;
412 reporter.fname = fname.c_str();
413 reporter.status = (options_.paranoid_checks ? &status : nullptr);
414 // We intentionally make log::Reader do checksumming even if
415 // paranoid_checks==false so that corruptions cause entire commits
416 // to be skipped instead of propagating bad information (like overly
417 // large sequence numbers).
418 log::Reader reader(file, &reporter, true /*checksum*/, 0 /*initial_offset*/);
419 Log(options_.info_log, "Recovering log #%llu",
420 (unsigned long long)log_number);
421
422 // Read all the records and add to a memtable
423 std::string scratch;
424 Slice record;
425 WriteBatch batch;
426 int compactions = 0;
427 MemTable* mem = nullptr;
428 while (reader.ReadRecord(&record, &scratch) && status.ok()) {
429 if (record.size() < 12) {
430 reporter.Corruption(record.size(),
431 Status::Corruption("log record too small", fname));
432 continue;
433 }
434 WriteBatchInternal::SetContents(&batch, record);
435
436 if (mem == nullptr) {
437 mem = new MemTable(internal_comparator_);
438 mem->Ref();

Callers

nothing calls this directly

Calls 12

LogFileNameFunction · 0.85
LogFunction · 0.85
CorruptionFunction · 0.85
ReadRecordMethod · 0.80
NewSequentialFileMethod · 0.45
sizeMethod · 0.45
CorruptionMethod · 0.45
RefMethod · 0.45
UnrefMethod · 0.45
GetFileSizeMethod · 0.45
NewAppendableFileMethod · 0.45

Tested by

no test coverage detected