1 //  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 //  This source code is licensed under both the GPLv2 (found in the
3 //  COPYING file in the root directory) and Apache 2.0 License
4 //  (found in the LICENSE.Apache file in the root directory).
5 
6 #pragma once
7 
8 #include "rocksdb/types.h"
9 
10 namespace ROCKSDB_NAMESPACE {
11 
12 class DB;
13 
14 // Abstract handle to particular state of a DB.
15 // A Snapshot is an immutable object and can therefore be safely
16 // accessed from multiple threads without any external synchronization.
17 //
18 // To Create a Snapshot, call DB::GetSnapshot().
19 // To Destroy a Snapshot, call DB::ReleaseSnapshot(snapshot).
20 class Snapshot {
21  public:
22   // returns Snapshot's sequence number
23   virtual SequenceNumber GetSequenceNumber() const = 0;
24 
25  protected:
26   virtual ~Snapshot();
27 };
28 
29 // Simple RAII wrapper class for Snapshot.
30 // Constructing this object will create a snapshot.  Destructing will
31 // release the snapshot.
32 class ManagedSnapshot {
33  public:
34   explicit ManagedSnapshot(DB* db);
35 
36   // Instead of creating a snapshot, take ownership of the input snapshot.
37   ManagedSnapshot(DB* db, const Snapshot* _snapshot);
38 
39   ~ManagedSnapshot();
40 
41   const Snapshot* snapshot();
42 
43  private:
44   DB* db_;
45   const Snapshot* snapshot_;
46 };
47 
48 }  // namespace ROCKSDB_NAMESPACE
49