Sfoglia il codice sorgente

Merge branch 'virgil' into jie

main
GUJIEJASON 1 mese fa
parent
commit
1c1970d241
3 ha cambiato i file con 24 aggiunte e 13 eliminazioni
  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 Vedi 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 Vedi 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 Vedi 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;
//}

Caricamento…
Annulla
Salva