提供基本的ttl测试用例
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.7 KiB

  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. #ifndef STORAGE_LEVELDB_DB_SNAPSHOT_H_
  5. #define STORAGE_LEVELDB_DB_SNAPSHOT_H_
  6. #include "db/dbformat.h"
  7. #include "leveldb/db.h"
  8. namespace leveldb {
  9. class SnapshotList;
  10. // Snapshots are kept in a doubly-linked list in the DB.
  11. // Each SnapshotImpl corresponds to a particular sequence number.
  12. class SnapshotImpl : public Snapshot {
  13. public:
  14. SequenceNumber number_; // const after creation
  15. private:
  16. friend class SnapshotList;
  17. // SnapshotImpl is kept in a doubly-linked circular list
  18. SnapshotImpl* prev_;
  19. SnapshotImpl* next_;
  20. SnapshotList* list_; // just for sanity checks
  21. };
  22. class SnapshotList {
  23. public:
  24. SnapshotList() {
  25. list_.prev_ = &list_;
  26. list_.next_ = &list_;
  27. }
  28. bool empty() const { return list_.next_ == &list_; }
  29. SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; }
  30. SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; }
  31. const SnapshotImpl* New(SequenceNumber seq) {
  32. SnapshotImpl* s = new SnapshotImpl;
  33. s->number_ = seq;
  34. s->list_ = this;
  35. s->next_ = &list_;
  36. s->prev_ = list_.prev_;
  37. s->prev_->next_ = s;
  38. s->next_->prev_ = s;
  39. return s;
  40. }
  41. void Delete(const SnapshotImpl* s) {
  42. assert(s->list_ == this);
  43. s->prev_->next_ = s->next_;
  44. s->next_->prev_ = s->prev_;
  45. delete s;
  46. }
  47. private:
  48. // Dummy head of doubly-linked list of snapshots
  49. SnapshotImpl list_;
  50. };
  51. } // namespace leveldb
  52. #endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_