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

Method DoCompactionWork

src/leveldb/db/db_impl.cc:888–1047  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

886}
887
888Status DBImpl::DoCompactionWork(CompactionState* compact) {
889 const uint64_t start_micros = env_->NowMicros();
890 int64_t imm_micros = 0; // Micros spent doing imm_ compactions
891
892 Log(options_.info_log, "Compacting %d@%d + %d@%d files",
893 compact->compaction->num_input_files(0), compact->compaction->level(),
894 compact->compaction->num_input_files(1),
895 compact->compaction->level() + 1);
896
897 assert(versions_->NumLevelFiles(compact->compaction->level()) > 0);
898 assert(compact->builder == nullptr);
899 assert(compact->outfile == nullptr);
900 if (snapshots_.empty()) {
901 compact->smallest_snapshot = versions_->LastSequence();
902 } else {
903 compact->smallest_snapshot = snapshots_.oldest()->sequence_number();
904 }
905
906 Iterator* input = versions_->MakeInputIterator(compact->compaction);
907
908 // Release mutex while we're actually doing the compaction work
909 mutex_.Unlock();
910
911 input->SeekToFirst();
912 Status status;
913 ParsedInternalKey ikey;
914 std::string current_user_key;
915 bool has_current_user_key = false;
916 SequenceNumber last_sequence_for_key = kMaxSequenceNumber;
917 while (input->Valid() && !shutting_down_.load(std::memory_order_acquire)) {
918 // Prioritize immutable compaction work
919 if (has_imm_.load(std::memory_order_relaxed)) {
920 const uint64_t imm_start = env_->NowMicros();
921 mutex_.Lock();
922 if (imm_ != nullptr) {
923 CompactMemTable();
924 // Wake up MakeRoomForWrite() if necessary.
925 background_work_finished_signal_.SignalAll();
926 }
927 mutex_.Unlock();
928 imm_micros += (env_->NowMicros() - imm_start);
929 }
930
931 Slice key = input->key();
932 if (compact->compaction->ShouldStopBefore(key) &&
933 compact->builder != nullptr) {
934 status = FinishCompactionOutputFile(compact, input);
935 if (!status.ok()) {
936 break;
937 }
938 }
939
940 // Handle key/value, add to state, etc.
941 bool drop = false;
942 if (!ParseInternalKey(key, &ikey)) {
943 // Do not hide error keys
944 current_user_key.clear();
945 has_current_user_key = false;

Callers

nothing calls this directly

Calls 15

LogFunction · 0.85
ParseInternalKeyFunction · 0.85
IOErrorFunction · 0.85
num_input_filesMethod · 0.80
levelMethod · 0.80
NumLevelFilesMethod · 0.80
LastSequenceMethod · 0.80
sequence_numberMethod · 0.80
oldestMethod · 0.80
MakeInputIteratorMethod · 0.80
UnlockMethod · 0.80
LockMethod · 0.80

Tested by

no test coverage detected