kevinyao0901 před 3 týdny
rodič
revize
85d42da3cf
2 změnil soubory, kde provedl 20 přidání a 7 odebrání
  1. +9
    -1
      db/db_impl.cc
  2. +11
    -6
      test/ttl_test.cc

+ 9
- 1
db/db_impl.cc Zobrazit soubor

@ -621,7 +621,7 @@ void DBImpl::CompactRange(const Slice* begin, const Slice* end) {
}
}
TEST_CompactMemTable(); // TODO(sanjay): Skip if memtable does not overlap
for (int level = 0; level < max_level_with_files; level++) {
for (int level = 0; level <= max_level_with_files; level++) {
TEST_CompactRange(level, begin, end);
}
}
@ -935,6 +935,12 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
int dropped_keys_count = 0; // 初始化计数器
int total_keys_count = 0;
std::cout << "Level 0: ";
for(int i=0;i<compact->compaction->num_input_files(0);i++) {
auto f = compact->compaction->input(0, i);
std::cout << f->number << " ";
}
Log(options_.info_log, "Compacting %d@%d + %d@%d files",
compact->compaction->num_input_files(0), compact->compaction->level(),
compact->compaction->num_input_files(1),
@ -1065,6 +1071,8 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
last_sequence_for_key = ikey.sequence;
}
input->SeekToLast();
std::cout << "Compation last key: " << input->key().ToString() << std::endl;
Log(options_.info_log, "Total dropped keys in compaction: %d\n", dropped_keys_count); // 输出统计结果
total_keys_count++;

+ 11
- 6
test/ttl_test.cc Zobrazit soubor

@ -21,12 +21,15 @@ void PrintAllKeys(DB *db) {
// 创建迭代器
std::unique_ptr<Iterator> it(db->NewIterator(readOptions));
int cnt = 20;
// 遍历所有键
for (it->SeekToFirst(); it->Valid(); it->Next()) {
// std::string key = it->key().ToString();
// std::string value = it->value().ToString();
// std::cout << "Key: " << key << std::endl;
for (it->SeekToFirst(); it->Valid()&&cnt; it->Next()) {
std::string key = it->key().ToString();
std::string value = it->value().ToString();
std::cout << "Key: " << key << std::endl;
LeftKeyCount++;
cnt--;
}
// 检查迭代器的有效性
@ -82,6 +85,8 @@ void InsertData(DB *db, uint64_t ttl/* second */) {
Iterator* iter = db->NewIterator(ReadOptions());
iter->SeekToFirst();
std::cout << "Data base First key: " << iter->key().ToString() << std::endl;
iter->SeekToLast();
std::cout << "Data base last key: " << iter->key().ToString() << std::endl;
delete iter;
// 打印成功写入的唯一键的数量
@ -115,7 +120,7 @@ void GetData(DB *db, int size = (1 << 30)) {
}
#if 0
TEST(TestTTL, ReadTTL) {
DB *db;
if(OpenDB("testdb", &db).ok() == false) {
@ -165,7 +170,7 @@ TEST(TestTTL, ReadTTL) {
delete db;
}
#endif
TEST(TestTTL, CompactionTTL) {
DB *db;

Načítá se…
Zrušit
Uložit