Expose unix time in rocksdb::Snapshot (#9923)

Summary:
RocksDB snapshot already has a member unix_time_ set after
snapshot is taken. It is now exposed through GetSnapshotTime() API.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9923

Test Plan: Update unit tests

Reviewed By: riversand963

Differential Revision: D36048275

Pulled By: akankshamahajan15

fbshipit-source-id: 825210ec287deb0bc3aaa9b8e1f079f07ad686fa
main
Akanksha Mahajan 3 years ago committed by Facebook GitHub Bot
parent 8e9d9156b0
commit 700d597bd8
  1. 2
      HISTORY.md
  2. 16
      db/db_test.cc
  3. 4
      db/snapshot_impl.h
  4. 5
      include/rocksdb/snapshot.h

@ -1,5 +1,7 @@
# Rocksdb Change Log
## Unreleased
### Public API changes
* Add new API GetUnixTime in Snapshot class which returns the unix time at which Snapshot is taken.
## 7.3.0 (05/20/2022)
### Bug Fixes

@ -1844,6 +1844,8 @@ TEST_F(DBTest, Snapshot) {
uint64_t time_snap1 = GetTimeOldestSnapshots();
ASSERT_GT(time_snap1, 0U);
ASSERT_EQ(GetSequenceOldestSnapshots(), s1->GetSequenceNumber());
ASSERT_EQ(GetTimeOldestSnapshots(),
static_cast<uint64_t>(s1->GetUnixTime()));
ASSERT_OK(Put(0, "foo", "0v2"));
ASSERT_OK(Put(1, "foo", "1v2"));
@ -1853,6 +1855,8 @@ TEST_F(DBTest, Snapshot) {
ASSERT_EQ(2U, GetNumSnapshots());
ASSERT_EQ(time_snap1, GetTimeOldestSnapshots());
ASSERT_EQ(GetSequenceOldestSnapshots(), s1->GetSequenceNumber());
ASSERT_EQ(GetTimeOldestSnapshots(),
static_cast<uint64_t>(s1->GetUnixTime()));
ASSERT_OK(Put(0, "foo", "0v3"));
ASSERT_OK(Put(1, "foo", "1v3"));
@ -1861,6 +1865,8 @@ TEST_F(DBTest, Snapshot) {
ASSERT_EQ(3U, GetNumSnapshots());
ASSERT_EQ(time_snap1, GetTimeOldestSnapshots());
ASSERT_EQ(GetSequenceOldestSnapshots(), s1->GetSequenceNumber());
ASSERT_EQ(GetTimeOldestSnapshots(),
static_cast<uint64_t>(s1->GetUnixTime()));
ASSERT_OK(Put(0, "foo", "0v4"));
ASSERT_OK(Put(1, "foo", "1v4"));
@ -1877,6 +1883,8 @@ TEST_F(DBTest, Snapshot) {
ASSERT_EQ(2U, GetNumSnapshots());
ASSERT_EQ(time_snap1, GetTimeOldestSnapshots());
ASSERT_EQ(GetSequenceOldestSnapshots(), s1->GetSequenceNumber());
ASSERT_EQ(GetTimeOldestSnapshots(),
static_cast<uint64_t>(s1->GetUnixTime()));
ASSERT_EQ("0v1", Get(0, "foo", s1));
ASSERT_EQ("1v1", Get(1, "foo", s1));
ASSERT_EQ("0v2", Get(0, "foo", s2));
@ -1892,6 +1900,8 @@ TEST_F(DBTest, Snapshot) {
ASSERT_EQ(1U, GetNumSnapshots());
ASSERT_LT(time_snap1, GetTimeOldestSnapshots());
ASSERT_EQ(GetSequenceOldestSnapshots(), s2->GetSequenceNumber());
ASSERT_EQ(GetTimeOldestSnapshots(),
static_cast<uint64_t>(s2->GetUnixTime()));
db_->ReleaseSnapshot(s2);
ASSERT_EQ(0U, GetNumSnapshots());
@ -2859,6 +2869,12 @@ class ModelDB : public DB {
assert(false);
return 0;
}
int64_t GetUnixTime() const override {
// no need to call this
assert(false);
return 0;
}
};
explicit ModelDB(const Options& options) : options_(options) {}

@ -27,7 +27,9 @@ class SnapshotImpl : public Snapshot {
// scope of queries to IsInSnapshot.
SequenceNumber min_uncommitted_ = kMinUnCommittedSeq;
virtual SequenceNumber GetSequenceNumber() const override { return number_; }
SequenceNumber GetSequenceNumber() const override { return number_; }
int64_t GetUnixTime() const override { return unix_time_; }
private:
friend class SnapshotList;

@ -19,9 +19,12 @@ class DB;
// To Destroy a Snapshot, call DB::ReleaseSnapshot(snapshot).
class Snapshot {
public:
// returns Snapshot's sequence number
virtual SequenceNumber GetSequenceNumber() const = 0;
// Returns unix time i.e. the number of seconds since the Epoch, 1970-01-01
// 00:00:00 (UTC).
virtual int64_t GetUnixTime() const = 0;
protected:
virtual ~Snapshot();
};

Loading…
Cancel
Save