From 56fee562a67b9bef9c8d4ac92d640338fc5529ed Mon Sep 17 00:00:00 2001 From: cyq <1056374449@qq.com> Date: Mon, 21 Oct 2024 04:47:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=BD=E7=95=A5ttl=E7=9A=84=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=EF=BC=8C=E4=BD=BF=E5=BE=97=E7=A8=8B=E5=BA=8F=E8=83=BD?= =?UTF-8?q?=E5=A4=9F=E9=A1=BA=E5=88=A9=E8=BF=90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/db_impl.cc | 13 +++++++++++++ db/db_impl.h | 2 ++ db/db_test.cc | 3 +++ port/port.h | 3 +++ test/db_test2.cc | 1 + test/ttl_test.cc | 4 ++-- 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index f96d245..3d26371 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -1198,6 +1198,11 @@ Status DBImpl::Put(const WriteOptions& o, const Slice& key, const Slice& val) { return DB::Put(o, key, val); } +Status DBImpl::Put(const WriteOptions& options, const Slice& key, + const Slice& value, uint64_t ttl) { + return DB::Put(options,key,value,ttl); +} + Status DBImpl::Delete(const WriteOptions& options, const Slice& key) { return DB::Delete(options, key); } @@ -1491,6 +1496,14 @@ Status DB::Put(const WriteOptions& opt, const Slice& key, const Slice& value) { return Write(opt, &batch); } +//为了通过编译,忽略ttl +Status DB::Put(const WriteOptions& options, const Slice& key, + const Slice& value, uint64_t ttl) { + WriteBatch batch; + batch.Put(key, value); + return Write(options, &batch); +} + Status DB::Delete(const WriteOptions& opt, const Slice& key) { WriteBatch batch; batch.Delete(key); diff --git a/db/db_impl.h b/db/db_impl.h index c7b0172..993c63e 100644 --- a/db/db_impl.h +++ b/db/db_impl.h @@ -38,6 +38,8 @@ class DBImpl : public DB { // Implementations of the DB interface Status Put(const WriteOptions&, const Slice& key, const Slice& value) override; + Status Put(const WriteOptions& options, const Slice& key, + const Slice& value, uint64_t ttl) override; Status Delete(const WriteOptions&, const Slice& key) override; Status Write(const WriteOptions& options, WriteBatch* updates) override; Status Get(const ReadOptions& options, const Slice& key, diff --git a/db/db_test.cc b/db/db_test.cc index a4a84cd..7baec2a 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -2117,6 +2117,9 @@ class ModelDB : public DB { Status Put(const WriteOptions& o, const Slice& k, const Slice& v) override { return DB::Put(o, k, v); } + Status Put(const WriteOptions& o, const Slice& k,const Slice& v,uint64_t ttl) { + return DB::Put(o,k,v); + } Status Delete(const WriteOptions& o, const Slice& key) override { return DB::Delete(o, key); } diff --git a/port/port.h b/port/port.h index 4b247f7..c2073f3 100644 --- a/port/port.h +++ b/port/port.h @@ -7,6 +7,9 @@ #include +#ifndef LEVELDB_PLATFORM_POSIX + #define LEVELDB_PLATFORM_POSIX +#endif // Include the appropriate platform specific file below. If you are // porting to a new platform, see "port_example.h" for documentation // of what the new port_.h file must provide. diff --git a/test/db_test2.cc b/test/db_test2.cc index 49e26ab..4b2b33c 100644 --- a/test/db_test2.cc +++ b/test/db_test2.cc @@ -68,6 +68,7 @@ int main() { GetData(db); delete db; } + DestroyDB("testdb",Options()); return 0; } diff --git a/test/ttl_test.cc b/test/ttl_test.cc index 06f4cda..0cc64f3 100644 --- a/test/ttl_test.cc +++ b/test/ttl_test.cc @@ -99,9 +99,9 @@ TEST(TestTTL, CompactionTTL) { db->CompactRange(nullptr, nullptr); - leveldb::Range ranges[1]; + // leveldb::Range ranges[1]; ranges[0] = leveldb::Range("-", "A"); - uint64_t sizes[1]; + // uint64_t sizes[1]; db->GetApproximateSizes(ranges, 1, sizes); ASSERT_EQ(sizes[0], 0); }