| 1439 | } |
| 1440 | |
| 1441 | Compaction* VersionSet::CompactRange(int level, const InternalKey* begin, |
| 1442 | const InternalKey* end) { |
| 1443 | std::vector<FileMetaData*> inputs; |
| 1444 | current_->GetOverlappingInputs(level, begin, end, &inputs); |
| 1445 | if (inputs.empty()) { |
| 1446 | return nullptr; |
| 1447 | } |
| 1448 | |
| 1449 | // Avoid compacting too much in one shot in case the range is large. |
| 1450 | // But we cannot do this for level-0 since level-0 files can overlap |
| 1451 | // and we must not pick one file and drop another older file if the |
| 1452 | // two files overlap. |
| 1453 | if (level > 0) { |
| 1454 | const uint64_t limit = MaxFileSizeForLevel(options_, level); |
| 1455 | uint64_t total = 0; |
| 1456 | for (size_t i = 0; i < inputs.size(); i++) { |
| 1457 | uint64_t s = inputs[i]->file_size; |
| 1458 | total += s; |
| 1459 | if (total >= limit) { |
| 1460 | inputs.resize(i + 1); |
| 1461 | break; |
| 1462 | } |
| 1463 | } |
| 1464 | } |
| 1465 | |
| 1466 | Compaction* c = new Compaction(options_, level); |
| 1467 | c->input_version_ = current_; |
| 1468 | c->input_version_->Ref(); |
| 1469 | c->inputs_[0] = inputs; |
| 1470 | SetupOtherInputs(c); |
| 1471 | return c; |
| 1472 | } |
| 1473 | |
| 1474 | Compaction::Compaction(const Options* options, int level) |
| 1475 | : level_(level), |
nothing calls this directly
no test coverage detected