1433 |
1433 |
ASSERT_EQ(4, vstorage_->NextCompactionIndex(1 /* level */));
|
1434 |
1434 |
}
|
1435 |
1435 |
|
|
1436 |
uint32_t GetPathId(
|
|
1437 |
const ImmutableCFOptions& ioptions,
|
|
1438 |
const MutableCFOptions& mutable_cf_options, int level) {
|
|
1439 |
uint32_t p = 0;
|
|
1440 |
assert(!ioptions.db_paths.empty());
|
|
1441 |
|
|
1442 |
// size remaining in the most recent path
|
|
1443 |
uint64_t current_path_size = ioptions.db_paths[0].target_size;
|
|
1444 |
|
|
1445 |
uint64_t level_size;
|
|
1446 |
int cur_level = 0;
|
|
1447 |
|
|
1448 |
// max_bytes_for_level_base denotes L1 size.
|
|
1449 |
// We estimate L0 size to be the same as L1.
|
|
1450 |
level_size = mutable_cf_options.max_bytes_for_level_base;
|
|
1451 |
|
|
1452 |
// Last path is the fallback
|
|
1453 |
while (p < ioptions.db_paths.size() - 1) {
|
|
1454 |
if (level_size <= current_path_size) {
|
|
1455 |
if (cur_level == level) {
|
|
1456 |
// Does desired level fit in this path?
|
|
1457 |
return p;
|
|
1458 |
} else {
|
|
1459 |
current_path_size -= level_size;
|
|
1460 |
if (cur_level > 0) {
|
|
1461 |
if (ioptions.level_compaction_dynamic_level_bytes) {
|
|
1462 |
// Currently, level_compaction_dynamic_level_bytes is ignored when
|
|
1463 |
// multiple db paths are specified. https://github.com/facebook/
|
|
1464 |
// rocksdb/blob/master/db/column_family.cc.
|
|
1465 |
// Still, adding this check to avoid accidentally using
|
|
1466 |
// max_bytes_for_level_multiplier_additional
|
|
1467 |
level_size = static_cast<uint64_t>(
|
|
1468 |
level_size * mutable_cf_options.max_bytes_for_level_multiplier);
|
|
1469 |
} else {
|
|
1470 |
level_size = static_cast<uint64_t>(
|
|
1471 |
level_size * mutable_cf_options.max_bytes_for_level_multiplier
|
|
1472 |
* mutable_cf_options.MaxBytesMultiplerAdditional(cur_level));
|
|
1473 |
}
|
|
1474 |
}
|
|
1475 |
cur_level++;
|
|
1476 |
continue;
|
|
1477 |
}
|
|
1478 |
}
|
|
1479 |
p++;
|
|
1480 |
current_path_size = ioptions.db_paths[p].target_size;
|
|
1481 |
}
|
|
1482 |
return p;
|
|
1483 |
}
|
|
1484 |
|
|
1485 |
uint32_t GetPathId12(
|
|
1486 |
const ImmutableCFOptions& ioptions,
|
|
1487 |
const MutableCFOptions& mutable_cf_options, int level) {
|
|
1488 |
uint32_t p = 0;
|
|
1489 |
assert(!ioptions.db_paths.empty());
|
|
1490 |
|
|
1491 |
// size remaining in the most recent path
|
|
1492 |
uint64_t current_path_size = ioptions.db_paths[0].target_size;
|
|
1493 |
|
|
1494 |
uint64_t level_size;
|
|
1495 |
int cur_level = 0;
|
|
1496 |
|
|
1497 |
level_size = mutable_cf_options.max_bytes_for_level_base;
|
|
1498 |
|
|
1499 |
// Last path is the fallback
|
|
1500 |
while (p < ioptions.db_paths.size() - 1) {
|
|
1501 |
if (level_size <= current_path_size) {
|
|
1502 |
if (cur_level == level) {
|
|
1503 |
// Does desired level fit in this path?
|
|
1504 |
return p;
|
|
1505 |
} else {
|
|
1506 |
current_path_size -= level_size;
|
|
1507 |
level_size = static_cast<uint64_t>(
|
|
1508 |
level_size * mutable_cf_options.max_bytes_for_level_multiplier);
|
|
1509 |
cur_level++;
|
|
1510 |
continue;
|
|
1511 |
}
|
|
1512 |
}
|
|
1513 |
p++;
|
|
1514 |
current_path_size = ioptions.db_paths[p].target_size;
|
|
1515 |
}
|
|
1516 |
return p;
|
|
1517 |
}
|
|
1518 |
|
|
1519 |
TEST_F(CompactionPickerTest, GetPathId) {
|
|
1520 |
mutable_cf_options_.max_bytes_for_level_base = 250u * 1024 * 1024;
|
|
1521 |
mutable_cf_options_.max_bytes_for_level_multiplier = 10;
|
|
1522 |
ioptions_.level_compaction_dynamic_level_bytes = false;
|
|
1523 |
ioptions_.db_paths.resize(2);
|
|
1524 |
ioptions_.db_paths[0].target_size = uint64_t(50u) * 1024 * 1024 * 1024;
|
|
1525 |
ioptions_.db_paths[1].target_size = uint64_t(280) * 1024 * 1024 * 1024;
|
|
1526 |
|
|
1527 |
ASSERT_EQ(0, GetPathId(ioptions_, mutable_cf_options_, 1));
|
|
1528 |
ASSERT_EQ(0, GetPathId(ioptions_, mutable_cf_options_, 3));
|
|
1529 |
ASSERT_EQ(1, GetPathId(ioptions_, mutable_cf_options_, 4));
|
|
1530 |
|
|
1531 |
ASSERT_EQ(0, GetPathId12(ioptions_, mutable_cf_options_, 1));
|
|
1532 |
ASSERT_EQ(0, GetPathId12(ioptions_, mutable_cf_options_, 3));
|
|
1533 |
ASSERT_EQ(1, GetPathId12(ioptions_, mutable_cf_options_, 4));
|
|
1534 |
}
|
|
1535 |
|
1436 |
1536 |
} // namespace rocksdb
|
1437 |
1537 |
|
1438 |
1538 |
int main(int argc, char** argv) {
|