MySQL 8.3.0
Source Code Documentation
iterator.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2023, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef ITERATOR_INCLUDED
24#define ITERATOR_INCLUDED
25
26#include "cache.h" /* Datacache */
27
28namespace keyring_common {
29
30namespace iterator {
31template <typename Data_extension>
32class Iterator {
33 public:
34 /** Constructor */
35 Iterator() : it_(), end_(), version_(0), valid_(false), cached_(false) {}
38 : it_(datacache.at(metadata)),
39 end_(datacache.end()),
40 version_(datacache.version()),
41 valid_(it_ != end_),
42 cached_(false) {}
43
45 : it_(datacache.begin()),
46 end_(datacache.end()),
47 version_(datacache.version()),
48 valid_(true),
50 if (cached_) {
51 for (std::pair<meta::Metadata, Data_extension> element : datacache)
52 metadata_.store(element.first, element.second);
53
54 it_ = metadata_.begin();
55 end_ = metadata_.end();
56 }
57 }
58
59 /** Destructor */
60 ~Iterator() { metadata_.clear(); }
61
62 /** Get iterator */
64 return it_;
65 }
66
67 /** Move iterator forward */
68 bool next(size_t version) {
69 if (iterator_valid(version) == false) {
70 it_ = end_;
71 valid_ = false;
72 return false;
73 }
74 it_++;
75 return true;
76 }
77
79 if (iterator_valid(version) == false) {
80 it_ = end_;
81 valid_ = false;
82 return false;
83 }
84 metadata = it_->first;
85 return true;
86 }
87
88 bool data(size_t version, Data_extension &data) {
89 if (iterator_valid(version) == false) {
90 it_ = end_;
91 valid_ = false;
92 return false;
93 }
94 data = it_->second;
95 return true;
96 }
97
98 bool valid(size_t version) {
100 return valid_;
101 }
102
103 private:
104 /** Internal validity checker */
105 inline bool iterator_valid(size_t version) {
106 if (cached_) {
107 return valid_ && (it_ != end_);
108 }
109 return valid_ && (version == version_) && (it_ != end_);
110 }
111
112 private:
113 /** Const Iterator */
115 /** End */
117 /** Iterator version */
118 size_t version_;
119 /** validity of the iterator */
120 bool valid_;
121 /** Iterator type */
123 /** Local copy */
125};
126
127} // namespace iterator
128
129} // namespace keyring_common
130
131#endif // !ITERATOR_INCLUDED
Definition: cache.h:40
Definition: iterator.h:32
cache::Cache< Data_extension >::const_iterator get_iterator() const
Get iterator.
Definition: iterator.h:63
bool valid_
validity of the iterator
Definition: iterator.h:120
cache::Cache< Data_extension >::const_iterator it_
Const Iterator.
Definition: iterator.h:114
bool iterator_valid(size_t version)
Internal validity checker.
Definition: iterator.h:105
bool next(size_t version)
Move iterator forward.
Definition: iterator.h:68
cache::Datacache< Data_extension > metadata_
Local copy.
Definition: iterator.h:124
size_t version_
Iterator version.
Definition: iterator.h:118
Iterator(const cache::Datacache< Data_extension > &datacache, const meta::Metadata &metadata)
Definition: iterator.h:36
cache::Cache< Data_extension >::const_iterator end_
End.
Definition: iterator.h:116
bool metadata(size_t version, meta::Metadata &metadata)
Definition: iterator.h:78
bool data(size_t version, Data_extension &data)
Definition: iterator.h:88
bool cached_
Iterator type.
Definition: iterator.h:122
bool valid(size_t version)
Definition: iterator.h:98
Iterator(const cache::Datacache< Data_extension > &datacache, bool cached)
Definition: iterator.h:44
~Iterator()
Destructor.
Definition: iterator.h:60
Iterator()
Constructor.
Definition: iterator.h:35
Common metadata.
Definition: meta.h:38
void * begin(THD *thd, const TABLE *table, size_t data_size, size_t memory, size_t num_threads) noexcept
Definition: bulk_data_service.cc:1533
std::unordered_map< meta::Metadata, Data_extension, meta::Metadata::Hash > Cache
Definition: cache.h:37
Definition: keyring_encryption_service_definition.h:31
required uint64 version
Definition: replication_group_member_actions.proto:40
static double cached
Definition: xcom_statistics.cc:100