Преглед на файлове

optimize the structure of Put

master
王雪飞 преди 3 седмици
родител
ревизия
47f23b7d6b
променени са 1 файла, в които са добавени 14 реда и са изтрити 9 реда
  1. +14
    -9
      db/db_impl.cc

+ 14
- 9
db/db_impl.cc Целия файл

@ -1218,15 +1218,7 @@ Status DBImpl::Put(const WriteOptions& o, const Slice& key, const Slice& val) {
Status DBImpl::Put(const WriteOptions& opt, const Slice& key,
const Slice& value, uint64_t ttl) {
WriteBatch batch;
auto now = std::chrono::system_clock::now();
auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
auto microsecondsTimestamp = static_cast<uint64_t>(timestamp) + ttl*1000000;
std::string value_ttl = value.ToString();
value_ttl += "_" + std::to_string(microsecondsTimestamp);
Slice new_value(value_ttl.c_str(), value_ttl.size());
batch.Put(key, new_value);
return Write(opt, &batch);
return DB::Put(opt, key, value, ttl);
}
Status DBImpl::Delete(const WriteOptions& options, const Slice& key) {
@ -1521,6 +1513,19 @@ Status DB::Put(const WriteOptions& opt, const Slice& key, const Slice& value) {
batch.Put(key, value);
return Write(opt, &batch);
}
// for TTL
Status DB::Put(const WriteOptions& opt, const Slice& key,
const Slice& value, uint64_t ttl) {
WriteBatch batch;
auto now = std::chrono::system_clock::now();
auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
auto microsecondsTimestamp = static_cast<uint64_t>(timestamp) + ttl*1000000;
std::string value_ttl = value.ToString();
value_ttl += "_" + std::to_string(microsecondsTimestamp);
Slice new_value(value_ttl.c_str(), value_ttl.size());
batch.Put(key, new_value);
return Write(opt, &batch);
}
Status DB::Delete(const WriteOptions& opt, const Slice& key) {
WriteBatch batch;

Зареждане…
Отказ
Запис