Browse Source

fix db_test1/2 bug

main
VirgilZhu 1 month ago
parent
commit
bc872072d3
3 changed files with 24 additions and 13 deletions
  1. +12
    -3
      db/db_impl.cc
  2. +2
    -0
      test/db_test2.cc
  3. +10
    -10
      test/time.cpp

+ 12
- 3
db/db_impl.cc View File

@ -1135,10 +1135,19 @@ int64_t DBImpl::TEST_MaxNextLevelOverlappingBytes() {
/* TODO: Add TTL Version isLive() */
Status isLive(const Slice& key, std::string* value, Status& s) {
uint64_t now = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
uint64_t deadtime = std::stoi(value->substr(value->find("_ts_") + 4));
if (now >= deadtime) {
if (value->empty()) {
s = Status::NotFound(key);
return s;
}
uint64_t now = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
if (value->find("_ts_") == std::string::npos) {
*value = *value + "_ts_" + std::to_string(now + 20);
}
else {
uint64_t deadtime = std::stoi(value->substr(value->find("_ts_") + 4));
if (now >= deadtime) {
s = Status::NotFound(key);
}
}
return s;
}

+ 2
- 0
test/db_test2.cc View File

@ -7,6 +7,8 @@
using namespace leveldb;
using namespace std;
constexpr int value_size = 2048;
constexpr int data_size = 256 << 20;

+ 10
- 10
test/time.cpp View File

@ -1,13 +1,13 @@
#include <iostream>
#include <chrono>
int main() {
auto now = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
auto end = now + 5;
// 输出当前时间点和未来时间点
std::cout << "Current time point: " << now << std::endl;
std::cout << "Future time point (+5 seconds): " << end << std::endl;
return 0;
}
//int main() {
// auto now = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
// auto end = now + 5;
//
// // 输出当前时间点和未来时间点
// std::cout << "Current time point: " << now << std::endl;
// std::cout << "Future time point (+5 seconds): " << end << std::endl;
//
// return 0;
//}

Loading…
Cancel
Save