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

Method WriteLevel0Table

src/leveldb/db/db_impl.cc:501–543  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

499}
500
501Status DBImpl::WriteLevel0Table(MemTable* mem, VersionEdit* edit,
502 Version* base) {
503 mutex_.AssertHeld();
504 const uint64_t start_micros = env_->NowMicros();
505 FileMetaData meta;
506 meta.number = versions_->NewFileNumber();
507 pending_outputs_.insert(meta.number);
508 Iterator* iter = mem->NewIterator();
509 Log(options_.info_log, "Level-0 table #%llu: started",
510 (unsigned long long)meta.number);
511
512 Status s;
513 {
514 mutex_.Unlock();
515 s = BuildTable(dbname_, env_, options_, table_cache_, iter, &meta);
516 mutex_.Lock();
517 }
518
519 Log(options_.info_log, "Level-0 table #%llu: %lld bytes %s",
520 (unsigned long long)meta.number, (unsigned long long)meta.file_size,
521 s.ToString().c_str());
522 delete iter;
523 pending_outputs_.erase(meta.number);
524
525 // Note that if file_size is zero, the file has been deleted and
526 // should not be added to the manifest.
527 int level = 0;
528 if (s.ok() && meta.file_size > 0) {
529 const Slice min_user_key = meta.smallest.user_key();
530 const Slice max_user_key = meta.largest.user_key();
531 if (base != nullptr) {
532 level = base->PickLevelForMemTableOutput(min_user_key, max_user_key);
533 }
534 edit->AddFile(level, meta.number, meta.file_size, meta.smallest,
535 meta.largest);
536 }
537
538 CompactionStats stats;
539 stats.micros = env_->NowMicros() - start_micros;
540 stats.bytes_written = meta.file_size;
541 stats_[level].Add(stats);
542 return s;
543}
544
545void DBImpl::CompactMemTable() {
546 mutex_.AssertHeld();

Callers

nothing calls this directly

Calls 14

LogFunction · 0.85
BuildTableFunction · 0.85
NewFileNumberMethod · 0.80
UnlockMethod · 0.80
LockMethod · 0.80
AddFileMethod · 0.80
NowMicrosMethod · 0.45
insertMethod · 0.45
NewIteratorMethod · 0.45
ToStringMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected