]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/monitoring/in_memory_stats_history.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rocksdb / monitoring / 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 "monitoring/in_memory_stats_history.h"
10 #include "db/db_impl/db_impl.h"
11
12 namespace ROCKSDB_NAMESPACE {
13
14 InMemoryStatsHistoryIterator::~InMemoryStatsHistoryIterator() {}
15
16 bool InMemoryStatsHistoryIterator::Valid() const { return valid_; }
17
18 Status InMemoryStatsHistoryIterator::status() const { return status_; }
19
20 // Because of garbage collection, the next stats snapshot may or may not be
21 // right after the current one. When reading from DBImpl::stats_history_, this
22 // call will be protected by DB Mutex so it will not return partial or
23 // corrupted results.
24 void InMemoryStatsHistoryIterator::Next() {
25 // increment start_time by 1 to avoid infinite loop
26 AdvanceIteratorByTime(GetStatsTime() + 1, end_time_);
27 }
28
29 uint64_t InMemoryStatsHistoryIterator::GetStatsTime() const { return time_; }
30
31 const std::map<std::string, uint64_t>&
32 InMemoryStatsHistoryIterator::GetStatsMap() const {
33 return stats_map_;
34 }
35
36 // advance the iterator to the next time between [start_time, end_time)
37 // if success, update time_ and stats_map_ with new_time and stats_map
38 void InMemoryStatsHistoryIterator::AdvanceIteratorByTime(uint64_t start_time,
39 uint64_t end_time) {
40 // try to find next entry in stats_history_ map
41 if (db_impl_ != nullptr) {
42 valid_ =
43 db_impl_->FindStatsByTime(start_time, end_time, &time_, &stats_map_);
44 } else {
45 valid_ = false;
46 }
47 }
48
49 } // namespace ROCKSDB_NAMESPACE