|
|
@ -7,7 +7,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
using namespace leveldb; |
|
|
|
|
|
|
|
// 定义了数据的大小,用于插入大数据集,燕
|
|
|
|
constexpr int value_size = 2048; |
|
|
|
constexpr int data_size = 128 << 20; |
|
|
|
|
|
|
@ -23,7 +23,8 @@ void InsertData(DB *db, uint64_t ttl/* second */) { |
|
|
|
srand(static_cast<unsigned int>(time(0))); |
|
|
|
|
|
|
|
for (int i = 0; i < key_num; i++) { |
|
|
|
int key_ = rand() % key_num+1; |
|
|
|
//int key_ = rand() % key_num+1;
|
|
|
|
int key_ = i % key_num+1; |
|
|
|
std::string key = std::to_string(key_); |
|
|
|
std::string value(value_size, 'a'); |
|
|
|
db->Put(writeOptions, key, value, ttl); |
|
|
@ -34,10 +35,11 @@ void GetData(DB *db, int size = (1 << 30)) { |
|
|
|
ReadOptions readOptions; |
|
|
|
int key_num = data_size / value_size; |
|
|
|
|
|
|
|
// 点查
|
|
|
|
// 使用随机种子生成随机键进行点查(单次查询),燕
|
|
|
|
srand(static_cast<unsigned int>(time(0))); |
|
|
|
for (int i = 0; i < 100; i++) { |
|
|
|
int key_ = rand() % key_num+1; |
|
|
|
//int key_ = i % key_num+1;
|
|
|
|
std::string key = std::to_string(key_); |
|
|
|
std::string value; |
|
|
|
db->Get(readOptions, key, &value); |
|
|
@ -60,17 +62,19 @@ TEST(TestTTL, ReadTTL) { |
|
|
|
int key_num = data_size / value_size; |
|
|
|
srand(static_cast<unsigned int>(time(0))); |
|
|
|
for (int i = 0; i < 100; i++) { |
|
|
|
int key_ = rand() % key_num+1; |
|
|
|
//int key_ = rand() % key_num+1;
|
|
|
|
int key_ = i % key_num+1; |
|
|
|
std::string key = std::to_string(key_); |
|
|
|
std::string value; |
|
|
|
status = db->Get(readOptions, key, &value); |
|
|
|
ASSERT_TRUE(status.ok()); |
|
|
|
} |
|
|
|
|
|
|
|
// 等待TTL过期,使插入的数据变为“过期”状态,燕
|
|
|
|
Env::Default()->SleepForMicroseconds(ttl * 1000000); |
|
|
|
|
|
|
|
for (int i = 0; i < 100; i++) { |
|
|
|
int key_ = rand() % key_num+1; |
|
|
|
// int key_ = i % key_num+1;
|
|
|
|
std::string key = std::to_string(key_); |
|
|
|
std::string value; |
|
|
|
status = db->Get(readOptions, key, &value); |
|
|
@ -99,9 +103,10 @@ TEST(TestTTL, CompactionTTL) { |
|
|
|
|
|
|
|
db->CompactRange(nullptr, nullptr); |
|
|
|
|
|
|
|
leveldb::Range ranges[1]; |
|
|
|
// leveldb::Range ranges[1]; // 这里为什么要重复定义?心
|
|
|
|
ranges[0] = leveldb::Range("-", "A"); |
|
|
|
uint64_t sizes[1]; |
|
|
|
// uint64_t sizes[1]; // 心
|
|
|
|
|
|
|
|
db->GetApproximateSizes(ranges, 1, sizes); |
|
|
|
ASSERT_EQ(sizes[0], 0); |
|
|
|
} |
|
|
|