/Users/deen/code/yugabyte-db/src/yb/rocksdb/db/managed_iterator.h
Line | Count | Source (jump to first uncovered line) |
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 | | // |
6 | | // The following only applies to changes made to this file as part of YugaByte development. |
7 | | // |
8 | | // Portions Copyright (c) YugaByte, Inc. |
9 | | // |
10 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
11 | | // in compliance with the License. You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | // or implied. See the License for the specific language governing permissions and limitations |
18 | | // under the License. |
19 | | // |
20 | | |
21 | | #ifndef YB_ROCKSDB_DB_MANAGED_ITERATOR_H |
22 | | #define YB_ROCKSDB_DB_MANAGED_ITERATOR_H |
23 | | |
24 | | #pragma once |
25 | | |
26 | | #ifndef ROCKSDB_LITE |
27 | | |
28 | | #include <mutex> |
29 | | #include <queue> |
30 | | #include <string> |
31 | | #include <vector> |
32 | | |
33 | | #include "yb/gutil/thread_annotations.h" |
34 | | |
35 | | #include "yb/rocksdb/db/column_family.h" |
36 | | #include "yb/rocksdb/db.h" |
37 | | #include "yb/rocksdb/iterator.h" |
38 | | #include "yb/rocksdb/options.h" |
39 | | #include "yb/rocksdb/util/arena.h" |
40 | | |
41 | | namespace rocksdb { |
42 | | |
43 | | class DBImpl; |
44 | | struct SuperVersion; |
45 | | class ColumnFamilyData; |
46 | | |
47 | | /** |
48 | | * ManagedIterator is a special type of iterator that supports freeing the |
49 | | * underlying iterator and still being able to access the current key/value |
50 | | * pair. This is done by copying the key/value pair so that clients can |
51 | | * continue to access the data without getting a SIGSEGV. |
52 | | * The underlying iterator can be freed manually through the call to |
53 | | * ReleaseIter or automatically (as needed on space pressure or age.) |
54 | | * The iterator is recreated using the saved original arguments. |
55 | | */ |
56 | | class ManagedIterator : public Iterator { |
57 | | public: |
58 | | ManagedIterator(DBImpl* db, const ReadOptions& read_options, |
59 | | ColumnFamilyData* cfd); |
60 | | virtual ~ManagedIterator(); |
61 | | |
62 | | virtual void SeekToLast() override; |
63 | | virtual void Prev() override; |
64 | | virtual bool Valid() const override; |
65 | | void SeekToFirst() override; |
66 | | virtual void Seek(const Slice& target) override; |
67 | | virtual void Next() override; |
68 | | virtual Slice key() const override; |
69 | | virtual Slice value() const override; |
70 | | virtual Status status() const override; |
71 | | void ReleaseIter(bool only_old); |
72 | 0 | void SetDropOld(bool only_old) { |
73 | 0 | only_drop_old_ = read_options_.tailing || only_old; |
74 | 0 | } |
75 | | |
76 | | private: |
77 | | void RebuildIterator(); |
78 | | void UpdateCurrent(); |
79 | | void SeekInternal(const Slice& user_key, bool seek_to_first); |
80 | | bool NeedToRebuild(); |
81 | | void Lock() ACQUIRE(); |
82 | | bool TryLock() TRY_ACQUIRE(true); |
83 | | void UnLock() RELEASE(); |
84 | | DBImpl* const db_; |
85 | | ReadOptions read_options_; |
86 | | ColumnFamilyData* const cfd_; |
87 | | ColumnFamilyHandleInternal cfh_; |
88 | | |
89 | | uint64_t svnum_; |
90 | | std::unique_ptr<Iterator> mutable_iter_; |
91 | | // internal iterator status |
92 | | Status status_; |
93 | | bool valid_; |
94 | | |
95 | | IterKey cached_key_; |
96 | | IterKey cached_value_; |
97 | | |
98 | | bool only_drop_old_ = true; |
99 | | bool snapshot_created_; |
100 | | bool release_supported_; |
101 | | std::mutex in_use_; // is managed iterator in use |
102 | | }; |
103 | | |
104 | | } // namespace rocksdb |
105 | | #endif // !ROCKSDB_LITE |
106 | | |
107 | | #endif // YB_ROCKSDB_DB_MANAGED_ITERATOR_H |