Procházet zdrojové kódy

fix db_test1/2 bug

main
VirgilZhu před 4 týdny
rodič
revize
bc872072d3
3 změnil soubory, kde provedl 24 přidání a 13 odebrání
  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 Zobrazit soubor

@ -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 Zobrazit soubor

@ -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 Zobrazit soubor

@ -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;
//}

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