]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/in_memory_stats_history.cc
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / rocksdb / db / in_memory_stats_history.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style license that can be
7 // found in the LICENSE file. See the AUTHORS file for names of contributors.
8
9 #include "db/db_impl.h"
10 #include "db/in_memory_stats_history.h"
11
12 namespace rocksdb {
13
14 InMemoryStatsHistoryIterator::~InMemoryStatsHistoryIterator() {}
15
16 bool InMemoryStatsHistoryIterator::Valid() const { return valid_; }
17
18 Status InMemoryStatsHistoryIterator::status() const { return status_; }
19
20 void InMemoryStatsHistoryIterator::Next() {
21 // increment start_time by 1 to avoid infinite loop
22 AdvanceIteratorByTime(GetStatsTime() + 1, end_time_);
23 }
24
25 uint64_t InMemoryStatsHistoryIterator::GetStatsTime() const { return time_; }
26
27 const std::map<std::string, uint64_t>&
28 InMemoryStatsHistoryIterator::GetStatsMap() const {
29 return stats_map_;
30 }
31
32 // advance the iterator to the next time between [start_time, end_time)
33 // if success, update time_ and stats_map_ with new_time and stats_map
34 void InMemoryStatsHistoryIterator::AdvanceIteratorByTime(uint64_t start_time,
35 uint64_t end_time) {
36 // try to find next entry in stats_history_ map
37 if (db_impl_ != nullptr) {
38 valid_ =
39 db_impl_->FindStatsByTime(start_time, end_time, &time_, &stats_map_);
40 } else {
41 valid_ = false;
42 }
43 }
44
45 } // namespace rocksdb