| 1378 | } |
| 1379 | |
| 1380 | void VersionSet::SetupOtherInputs(Compaction* c) { |
| 1381 | const int level = c->level(); |
| 1382 | InternalKey smallest, largest; |
| 1383 | |
| 1384 | AddBoundaryInputs(icmp_, current_->files_[level], &c->inputs_[0]); |
| 1385 | GetRange(c->inputs_[0], &smallest, &largest); |
| 1386 | |
| 1387 | current_->GetOverlappingInputs(level + 1, &smallest, &largest, |
| 1388 | &c->inputs_[1]); |
| 1389 | |
| 1390 | // Get entire range covered by compaction |
| 1391 | InternalKey all_start, all_limit; |
| 1392 | GetRange2(c->inputs_[0], c->inputs_[1], &all_start, &all_limit); |
| 1393 | |
| 1394 | // See if we can grow the number of inputs in "level" without |
| 1395 | // changing the number of "level+1" files we pick up. |
| 1396 | if (!c->inputs_[1].empty()) { |
| 1397 | std::vector<FileMetaData*> expanded0; |
| 1398 | current_->GetOverlappingInputs(level, &all_start, &all_limit, &expanded0); |
| 1399 | AddBoundaryInputs(icmp_, current_->files_[level], &expanded0); |
| 1400 | const int64_t inputs0_size = TotalFileSize(c->inputs_[0]); |
| 1401 | const int64_t inputs1_size = TotalFileSize(c->inputs_[1]); |
| 1402 | const int64_t expanded0_size = TotalFileSize(expanded0); |
| 1403 | if (expanded0.size() > c->inputs_[0].size() && |
| 1404 | inputs1_size + expanded0_size < |
| 1405 | ExpandedCompactionByteSizeLimit(options_)) { |
| 1406 | InternalKey new_start, new_limit; |
| 1407 | GetRange(expanded0, &new_start, &new_limit); |
| 1408 | std::vector<FileMetaData*> expanded1; |
| 1409 | current_->GetOverlappingInputs(level + 1, &new_start, &new_limit, |
| 1410 | &expanded1); |
| 1411 | if (expanded1.size() == c->inputs_[1].size()) { |
| 1412 | Log(options_->info_log, |
| 1413 | "Expanding@%d %d+%d (%ld+%ld bytes) to %d+%d (%ld+%ld bytes)\n", |
| 1414 | level, int(c->inputs_[0].size()), int(c->inputs_[1].size()), |
| 1415 | long(inputs0_size), long(inputs1_size), int(expanded0.size()), |
| 1416 | int(expanded1.size()), long(expanded0_size), long(inputs1_size)); |
| 1417 | smallest = new_start; |
| 1418 | largest = new_limit; |
| 1419 | c->inputs_[0] = expanded0; |
| 1420 | c->inputs_[1] = expanded1; |
| 1421 | GetRange2(c->inputs_[0], c->inputs_[1], &all_start, &all_limit); |
| 1422 | } |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | // Compute the set of grandparent files that overlap this compaction |
| 1427 | // (parent == level+1; grandparent == level+2) |
| 1428 | if (level + 2 < config::kNumLevels) { |
| 1429 | current_->GetOverlappingInputs(level + 2, &all_start, &all_limit, |
| 1430 | &c->grandparents_); |
| 1431 | } |
| 1432 | |
| 1433 | // Update the place where we will do the next compaction for this level. |
| 1434 | // We update this immediately instead of waiting for the VersionEdit |
| 1435 | // to be applied so that if the compaction fails, we will try a different |
| 1436 | // key range next time. |
| 1437 | compact_pointer_[level] = largest.Encode().ToString(); |
nothing calls this directly
no test coverage detected