-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip expired object when using DBWithTtl
Currently even if objects have been expired we still return them until compaction delete those objects. This commit adds a skip_expired_data to the ReadOptions, if this option is true, it Get and MultiGet will not return objects that have been expired by the configured ttl. Currently this feature does not include support of the flag for Merge operation or for iterator.
- Loading branch information
Or Friedmann
committed
Feb 16, 2023
1 parent
ea5b771
commit 3ddffa1
Showing
10 changed files
with
161 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (C) 2023 Speedb Ltd. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <unistd.h> | ||
|
||
#include <iostream> | ||
|
||
#include "rocksdb/db.h" | ||
#include "rocksdb/options.h" | ||
#include "rocksdb/slice.h" | ||
#include "rocksdb/utilities/db_ttl.h" | ||
|
||
using namespace ROCKSDB_NAMESPACE; | ||
|
||
#if defined(OS_WIN) | ||
std::string kDBPath = "C:\\Windows\\TEMP\\speedb_is_awesome_example"; | ||
#else | ||
std::string kDBPath = "/tmp/speedb_is_awesome_example"; | ||
#endif | ||
|
||
int main() { | ||
// Open the storage | ||
DBWithTTL* db = nullptr; | ||
Options options; | ||
// create the DB if it's not already present | ||
options.create_if_missing = true; | ||
Status s = DBWithTTL::Open(options, kDBPath, &db, 1); | ||
assert(s.ok()); | ||
|
||
// append new entry | ||
std::string key1 = "key_1"; | ||
std::string key2 = "key_2"; | ||
std::string put_value = "Speedb is awesome!"; | ||
s = db->Put(WriteOptions(), key1, put_value); | ||
s = db->Put(WriteOptions(), key2, put_value); | ||
assert(s.ok()); | ||
sleep(2); | ||
// retrieve entry | ||
std::string get_value; | ||
ReadOptions ropts = ReadOptions(); | ||
ropts.skip_expired_data = true; | ||
s = db->Get(ropts, key1, &get_value); | ||
if (s.IsNotFound()) { | ||
std::cout << "Key has been expired as expected" << std::endl; | ||
} | ||
std::vector<rocksdb::Slice> keys = {key1, key2}; | ||
std::vector<std::string> values; | ||
auto statuses = db->MultiGet(ropts, keys, &values); | ||
for (const auto& i : statuses) { | ||
if (s.IsNotFound()) { | ||
std::cout << "Key has been expired as expected by MultiGet" << std::endl; | ||
} | ||
} | ||
// close DB | ||
s = db->Close(); | ||
delete db; | ||
assert(s.ok()); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters