| 1224 | } |
| 1225 | |
| 1226 | Status Sorter::MergeAndSpill() { |
| 1227 | // The last minirun might have been created just before we ran out of memory. |
| 1228 | // In this case it should not be sorted and merged. |
| 1229 | if (unsorted_run_->run_size() == 0){ |
| 1230 | unsorted_run_ = nullptr; |
| 1231 | } else { |
| 1232 | RETURN_IF_ERROR(SortCurrentInputRun()); |
| 1233 | sorted_inmem_runs_.push_back(unsorted_run_); |
| 1234 | } |
| 1235 | |
| 1236 | // If only 1 run was created, do not merge. |
| 1237 | if (sorted_inmem_runs_.size() == 1) { |
| 1238 | sorted_runs_.push_back(sorted_inmem_runs_.back()); |
| 1239 | sorted_inmem_runs_.clear(); |
| 1240 | DCHECK_GT(sorted_runs_.back()->fixed_len_size(), 0); |
| 1241 | RETURN_IF_ERROR(sorted_runs_.back()->UnpinAllPages()); |
| 1242 | // If 'merge_output_run_' was initialized but no merge was executed, |
| 1243 | // set it back to nullptr. |
| 1244 | if (merge_output_run_ != nullptr){ |
| 1245 | merge_output_run_->CloseAllPages(); |
| 1246 | merge_output_run_ = nullptr; |
| 1247 | } |
| 1248 | } else { |
| 1249 | DCHECK(merge_output_run_ != nullptr) << "Should have reserved memory for the merger."; |
| 1250 | RETURN_IF_ERROR(MergeInMemoryRuns()); |
| 1251 | DCHECK(merge_output_run_ == nullptr) << "Should have finished previous merge."; |
| 1252 | } |
| 1253 | |
| 1254 | DCHECK(sorted_inmem_runs_.empty()); |
| 1255 | return Status::OK(); |
| 1256 | } |
| 1257 | |
| 1258 | bool Sorter::MustSortAndSpill(const int rows_added, const int batch_num_rows) { |
| 1259 | if (rows_added < batch_num_rows) { |
nothing calls this directly
no test coverage detected