|
@ -92,11 +92,9 @@ TEST(TestTTL, CompactionTTL) { |
|
|
uint64_t sizes[1]; |
|
|
uint64_t sizes[1]; |
|
|
db->GetApproximateSizes(ranges, 1, sizes); |
|
|
db->GetApproximateSizes(ranges, 1, sizes); |
|
|
ASSERT_GT(sizes[0], 0); |
|
|
ASSERT_GT(sizes[0], 0); |
|
|
|
|
|
|
|
|
Env::Default()->SleepForMicroseconds(ttl * 1000000); |
|
|
Env::Default()->SleepForMicroseconds(ttl * 1000000); |
|
|
|
|
|
|
|
|
db->CompactRange(nullptr, nullptr); |
|
|
db->CompactRange(nullptr, nullptr); |
|
|
|
|
|
|
|
|
leveldb::Range ranges1[1]; |
|
|
leveldb::Range ranges1[1]; |
|
|
ranges1[0] = leveldb::Range("-", "A"); |
|
|
ranges1[0] = leveldb::Range("-", "A"); |
|
|
uint64_t sizes1[1]; |
|
|
uint64_t sizes1[1]; |
|
@ -106,6 +104,44 @@ TEST(TestTTL, CompactionTTL) { |
|
|
delete db; |
|
|
delete db; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Time-consuming when kNumLevels is 7, so run this test when kNumLevels is set to 3,
|
|
|
|
|
|
// the codes on branch light_ver
|
|
|
|
|
|
// In this case level 2 is the last level with files
|
|
|
|
|
|
TEST(TestTTL, LastLevelCompaction) { |
|
|
|
|
|
DB *db; |
|
|
|
|
|
|
|
|
|
|
|
if(OpenDB("testdb", &db).ok() == false) { |
|
|
|
|
|
std::cerr << "open db failed" << std::endl; |
|
|
|
|
|
abort(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint64_t ttl = 20; |
|
|
|
|
|
InsertData(db, ttl); |
|
|
|
|
|
|
|
|
|
|
|
leveldb::Range ranges[1]; |
|
|
|
|
|
ranges[0] = leveldb::Range("-", "A"); |
|
|
|
|
|
uint64_t sizes[1]; |
|
|
|
|
|
db->GetApproximateSizes(ranges, 1, sizes); |
|
|
|
|
|
ASSERT_GT(sizes[0], 0); |
|
|
|
|
|
|
|
|
|
|
|
std::string last_level_file_num; |
|
|
|
|
|
std::string last_level = "2"; |
|
|
|
|
|
db->GetProperty("leveldb.num-files-at-level" + last_level, &last_level_file_num); |
|
|
|
|
|
std::cout << "File nums in last level: " << last_level_file_num << std::endl; |
|
|
|
|
|
ASSERT_GT(std::atoi(last_level_file_num.c_str()), 0); |
|
|
|
|
|
|
|
|
|
|
|
Env::Default()->SleepForMicroseconds(ttl * 1000000); |
|
|
|
|
|
|
|
|
|
|
|
db->CompactRange(nullptr, nullptr); |
|
|
|
|
|
leveldb::Range ranges1[1]; |
|
|
|
|
|
ranges1[0] = leveldb::Range("-", "A"); |
|
|
|
|
|
uint64_t sizes1[1]; |
|
|
|
|
|
db->GetApproximateSizes(ranges1, 1, sizes1); |
|
|
|
|
|
ASSERT_EQ(sizes1[0], 0); |
|
|
|
|
|
|
|
|
|
|
|
delete db; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) { |
|
|
int main(int argc, char** argv) { |
|
|
// All tests currently run with the same read-only file limits.
|
|
|
// All tests currently run with the same read-only file limits.
|
|
|