]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/managed_iterator.h
bump version to 12.2.12-pve1
[ceph.git] / ceph / src / rocksdb / db / managed_iterator.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
5 #pragma once
6
7 #ifndef ROCKSDB_LITE
8
9 #include <mutex>
10 #include <queue>
11 #include <string>
12 #include <vector>
13
14 #include "db/column_family.h"
15 #include "rocksdb/db.h"
16 #include "rocksdb/iterator.h"
17 #include "rocksdb/options.h"
18 #include "util/arena.h"
19
20 namespace rocksdb {
21
22 class DBImpl;
23 struct SuperVersion;
24 class ColumnFamilyData;
25
26 /**
27 * ManagedIterator is a special type of iterator that supports freeing the
28 * underlying iterator and still being able to access the current key/value
29 * pair. This is done by copying the key/value pair so that clients can
30 * continue to access the data without getting a SIGSEGV.
31 * The underlying iterator can be freed manually through the call to
32 * ReleaseIter or automatically (as needed on space pressure or age.)
33 * The iterator is recreated using the saved original arguments.
34 */
35 class ManagedIterator : public Iterator {
36 public:
37 ManagedIterator(DBImpl* db, const ReadOptions& read_options,
38 ColumnFamilyData* cfd);
39 virtual ~ManagedIterator();
40
41 virtual void SeekToLast() override;
42 virtual void Prev() override;
43 virtual bool Valid() const override;
44 void SeekToFirst() override;
45 virtual void Seek(const Slice& target) override;
46 virtual void SeekForPrev(const Slice& target) override;
47 virtual void Next() override;
48 virtual Slice key() const override;
49 virtual Slice value() const override;
50 virtual Status status() const override;
51 void ReleaseIter(bool only_old);
52 void SetDropOld(bool only_old) {
53 only_drop_old_ = read_options_.tailing || only_old;
54 }
55
56 private:
57 void RebuildIterator();
58 void UpdateCurrent();
59 void SeekInternal(const Slice& user_key, bool seek_to_first);
60 bool NeedToRebuild();
61 void Lock();
62 bool TryLock();
63 void UnLock();
64 DBImpl* const db_;
65 ReadOptions read_options_;
66 ColumnFamilyData* const cfd_;
67 ColumnFamilyHandleInternal cfh_;
68
69 uint64_t svnum_;
70 std::unique_ptr<Iterator> mutable_iter_;
71 // internal iterator status
72 Status status_;
73 bool valid_;
74
75 IterKey cached_key_;
76 IterKey cached_value_;
77
78 bool only_drop_old_ = true;
79 bool snapshot_created_;
80 bool release_supported_;
81 std::mutex in_use_; // is managed iterator in use
82 };
83
84 } // namespace rocksdb
85 #endif // !ROCKSDB_LITE