| 819 | } |
| 820 | |
| 821 | Status DBImpl::FinishCompactionOutputFile(CompactionState* compact, |
| 822 | Iterator* input) { |
| 823 | assert(compact != nullptr); |
| 824 | assert(compact->outfile != nullptr); |
| 825 | assert(compact->builder != nullptr); |
| 826 | |
| 827 | const uint64_t output_number = compact->current_output()->number; |
| 828 | assert(output_number != 0); |
| 829 | |
| 830 | // Check for iterator errors |
| 831 | Status s = input->status(); |
| 832 | const uint64_t current_entries = compact->builder->NumEntries(); |
| 833 | if (s.ok()) { |
| 834 | s = compact->builder->Finish(); |
| 835 | } else { |
| 836 | compact->builder->Abandon(); |
| 837 | } |
| 838 | const uint64_t current_bytes = compact->builder->FileSize(); |
| 839 | compact->current_output()->file_size = current_bytes; |
| 840 | compact->total_bytes += current_bytes; |
| 841 | delete compact->builder; |
| 842 | compact->builder = nullptr; |
| 843 | |
| 844 | // Finish and check for file errors |
| 845 | if (s.ok()) { |
| 846 | s = compact->outfile->Sync(); |
| 847 | } |
| 848 | if (s.ok()) { |
| 849 | s = compact->outfile->Close(); |
| 850 | } |
| 851 | delete compact->outfile; |
| 852 | compact->outfile = nullptr; |
| 853 | |
| 854 | if (s.ok() && current_entries > 0) { |
| 855 | // Verify that the table is usable |
| 856 | Iterator* iter = |
| 857 | table_cache_->NewIterator(ReadOptions(), output_number, current_bytes); |
| 858 | s = iter->status(); |
| 859 | delete iter; |
| 860 | if (s.ok()) { |
| 861 | Log(options_.info_log, "Generated table #%llu@%d: %lld keys, %lld bytes", |
| 862 | (unsigned long long)output_number, compact->compaction->level(), |
| 863 | (unsigned long long)current_entries, |
| 864 | (unsigned long long)current_bytes); |
| 865 | } |
| 866 | } |
| 867 | return s; |
| 868 | } |
| 869 | |
| 870 | Status DBImpl::InstallCompactionResults(CompactionState* compact) { |
| 871 | mutex_.AssertHeld(); |
nothing calls this directly
no test coverage detected