Bitcoin
snapshot.h
Go to the documentation of this file.
1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 
5 #ifndef STORAGE_LEVELDB_DB_SNAPSHOT_H_
6 #define STORAGE_LEVELDB_DB_SNAPSHOT_H_
7 
8 #include "db/dbformat.h"
9 #include "leveldb/db.h"
10 
11 namespace leveldb {
12 
13 class SnapshotList;
14 
15 // Snapshots are kept in a doubly-linked list in the DB.
16 // Each SnapshotImpl corresponds to a particular sequence number.
17 class SnapshotImpl : public Snapshot {
18  public:
19  SequenceNumber number_; // const after creation
20 
21  private:
22  friend class SnapshotList;
23 
24  // SnapshotImpl is kept in a doubly-linked circular list
27 
28  SnapshotList* list_; // just for sanity checks
29 };
30 
31 class SnapshotList {
32  public:
34  list_.prev_ = &list_;
35  list_.next_ = &list_;
36  }
37 
38  bool empty() const { return list_.next_ == &list_; }
39  SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; }
40  SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; }
41 
43  SnapshotImpl* s = new SnapshotImpl;
44  s->number_ = seq;
45  s->list_ = this;
46  s->next_ = &list_;
47  s->prev_ = list_.prev_;
48  s->prev_->next_ = s;
49  s->next_->prev_ = s;
50  return s;
51  }
52 
53  void Delete(const SnapshotImpl* s) {
54  assert(s->list_ == this);
55  s->prev_->next_ = s->next_;
56  s->next_->prev_ = s->prev_;
57  delete s;
58  }
59 
60  private:
61  // Dummy head of doubly-linked list of snapshots
63 };
64 
65 } // namespace leveldb
66 
67 #endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_
Definition: autocompact_test.cc:11
SequenceNumber number_
Definition: snapshot.h:19
SnapshotImpl * next_
Definition: snapshot.h:26
SnapshotList * list_
Definition: snapshot.h:28
uint64_t SequenceNumber
Definition: dbformat.h:63
Definition: snapshot.h:31
SnapshotImpl * oldest() const
Definition: snapshot.h:39
Definition: snapshot.h:17
bool empty() const
Definition: snapshot.h:38
void Delete(const SnapshotImpl *s)
Definition: snapshot.h:53
SnapshotList()
Definition: snapshot.h:33
SnapshotImpl * prev_
Definition: snapshot.h:25
SnapshotImpl * newest() const
Definition: snapshot.h:40
SnapshotImpl list_
Definition: snapshot.h:62
Definition: db.h:27
const SnapshotImpl * New(SequenceNumber seq)
Definition: snapshot.h:42