|
@ -26,7 +26,8 @@ void InsertData(DB *db, uint64_t ttl/* second */) { |
|
|
int key_ = rand() % key_num+1; |
|
|
int key_ = rand() % key_num+1; |
|
|
std::string key = std::to_string(key_); |
|
|
std::string key = std::to_string(key_); |
|
|
std::string value(value_size, 'a'); |
|
|
std::string value(value_size, 'a'); |
|
|
db->Put(writeOptions, key, value, ttl); |
|
|
|
|
|
|
|
|
db->Put(writeOptions, std::to_string(i+1), value, ttl); |
|
|
|
|
|
// db->Put(writeOptions, key, value, ttl);
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -45,13 +46,14 @@ void GetData(DB *db, int size = (1 << 30)) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
TEST(TestTTL, ReadTTL) { |
|
|
TEST(TestTTL, ReadTTL) { |
|
|
|
|
|
DestroyDB("testdb",Options()); |
|
|
DB *db; |
|
|
DB *db; |
|
|
if(OpenDB("testdb", &db).ok() == false) { |
|
|
if(OpenDB("testdb", &db).ok() == false) { |
|
|
std::cerr << "open db failed" << std::endl; |
|
|
std::cerr << "open db failed" << std::endl; |
|
|
abort(); |
|
|
abort(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
uint64_t ttl = 20; |
|
|
|
|
|
|
|
|
uint64_t ttl = 15; |
|
|
|
|
|
|
|
|
InsertData(db, ttl); |
|
|
InsertData(db, ttl); |
|
|
|
|
|
|
|
@ -64,47 +66,53 @@ TEST(TestTTL, ReadTTL) { |
|
|
std::string key = std::to_string(key_); |
|
|
std::string key = std::to_string(key_); |
|
|
std::string value; |
|
|
std::string value; |
|
|
status = db->Get(readOptions, key, &value); |
|
|
status = db->Get(readOptions, key, &value); |
|
|
|
|
|
std::cout<<key<<" "<<value[0]<<std::endl; |
|
|
ASSERT_TRUE(status.ok()); |
|
|
ASSERT_TRUE(status.ok()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Env::Default()->SleepForMicroseconds(ttl * 1000000); |
|
|
|
|
|
|
|
|
Env::Default()->SleepForMicroseconds((ttl+1) * 1000000); |
|
|
|
|
|
|
|
|
for (int i = 0; i < 100; i++) { |
|
|
for (int i = 0; i < 100; i++) { |
|
|
int key_ = rand() % key_num+1; |
|
|
int key_ = rand() % key_num+1; |
|
|
std::string key = std::to_string(key_); |
|
|
std::string key = std::to_string(key_); |
|
|
std::string value; |
|
|
std::string value; |
|
|
status = db->Get(readOptions, key, &value); |
|
|
status = db->Get(readOptions, key, &value); |
|
|
|
|
|
std::cout<<key<<" "<<value<<std::endl; |
|
|
ASSERT_FALSE(status.ok()); |
|
|
ASSERT_FALSE(status.ok()); |
|
|
} |
|
|
} |
|
|
|
|
|
delete db; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TEST(TestTTL, CompactionTTL) {
|
|
|
|
|
|
// DB *db;
|
|
|
|
|
|
|
|
|
TEST(TestTTL, CompactionTTL) { |
|
|
|
|
|
DestroyDB("testdb",Options()); |
|
|
|
|
|
DB *db; |
|
|
|
|
|
|
|
|
// if(OpenDB("testdb", &db).ok() == false) {
|
|
|
|
|
|
// std::cerr << "open db failed" << std::endl;
|
|
|
|
|
|
// abort();
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
if(OpenDB("testdb", &db).ok() == false) { |
|
|
|
|
|
std::cerr << "open db failed" << std::endl; |
|
|
|
|
|
abort(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// uint64_t ttl = 20;
|
|
|
|
|
|
// InsertData(db, ttl);
|
|
|
|
|
|
|
|
|
uint64_t ttl = 10; |
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
leveldb::Range ranges[1]; |
|
|
|
|
|
ranges[0] = leveldb::Range("-", "A"); |
|
|
|
|
|
uint64_t sizes[1]; |
|
|
|
|
|
db->GetApproximateSizes(ranges, 1, sizes); |
|
|
|
|
|
ASSERT_GT(sizes[0], 0); |
|
|
|
|
|
|
|
|
// Env::Default()->SleepForMicroseconds(ttl * 1000000);
|
|
|
|
|
|
|
|
|
Env::Default()->SleepForMicroseconds((ttl+1) * 1000000); |
|
|
|
|
|
// Env::Default()->SleepForMicroseconds(ttl * 1000000);
|
|
|
|
|
|
|
|
|
// db->CompactRange(nullptr, nullptr);
|
|
|
|
|
|
|
|
|
db->CompactRange(nullptr, nullptr); |
|
|
|
|
|
|
|
|
// leveldb::Range ranges[1];
|
|
|
|
|
|
// ranges[0] = leveldb::Range("-", "A");
|
|
|
|
|
|
// uint64_t sizes[1];
|
|
|
|
|
|
// db->GetApproximateSizes(ranges, 1, sizes);
|
|
|
|
|
|
// ASSERT_EQ(sizes[0], 0);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
// leveldb::Range ranges[1];
|
|
|
|
|
|
ranges[0] = leveldb::Range("-", "A"); |
|
|
|
|
|
// uint64_t sizes[1];
|
|
|
|
|
|
db->GetApproximateSizes(ranges, 1, sizes); |
|
|
|
|
|
ASSERT_EQ(sizes[0], 0); |
|
|
|
|
|
delete db; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) { |
|
|
int main(int argc, char** argv) { |
|
|