MySQL 8.0.37
Source Code Documentation
abstract_progress_watcher.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2015, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License, version 2.0, for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ABSTRACT_PROGRESS_WATCHER_INCLUDED
27#define ABSTRACT_PROGRESS_WATCHER_INCLUDED
28
29#include <atomic>
30#include <chrono>
31#include <functional>
32
35#include "my_inttypes.h"
36
37namespace Mysql {
38namespace Tools {
39namespace Dump {
40
41/**
42 Gathers information about progress of current dump progress and format
43 messages on progress.Also it should expose API for receiving processed
44 progress information: collected objects and rows information along with time
45 elapsed, ETA.
46 */
49 public:
50 void new_chain_created(Item_processing_data *new_chain_process_data) override;
51
52 void object_processing_started(Item_processing_data *process_data) override;
53
55 Item_processing_data *finished_process_data) override;
56
57 void crawler_completed(I_crawler *crawler) override;
58
59 // Fix "inherits ... via dominance" warnings
61 I_progress_watcher *new_progress_watcher) override {
63 }
64
65 // Fix "inherits ... via dominance" warnings
66 uint64 get_id() const override { return Abstract_chain_element::get_id(); }
67
68 protected:
70 std::function<bool(const Mysql::Tools::Base::Message_data &)>
71 *message_handler,
72 Simple_id_generator *object_id_generator);
73
75 public:
77 Progress_data(const Progress_data &to_copy);
78 Progress_data &operator=(const Progress_data &to_copy);
79 Progress_data operator-(const Progress_data &to_subtract);
80 std::atomic<uint64_t> m_table_count;
81 std::atomic<uint64_t> m_row_data;
82 std::atomic<uint64_t> m_row_count;
83 };
84
85 virtual void process_progress_step(Progress_data &change) = 0;
86
90
91 // Fix "inherits ... via dominance" warnings
93 Item_processing_data *item_processed) override {
95 }
96
97 private:
98 /**
99 Throttles progress changes to be reported to progress_changed() about 1 in
100 second. It uses 10 stages, each 100ms long, in each there is number of
101 iterations to prevent calling std::chrono::system_clock::now() on each
102 function call.
103 */
104 void progress_changed();
105
106 static const int STAGES = 10;
107 static const int REPORT_DELAY_MS = 1000;
108
109 std::chrono::system_clock::time_point m_last_stage_time;
110 std::atomic<int64_t> m_step_countdown;
111 std::atomic<int64_t> m_stage_countdown;
113};
114
115} // namespace Dump
116} // namespace Tools
117} // namespace Mysql
118
119#endif
Structure to represent message from server sent after executing query.
Definition: message_data.h:49
Definition: abstract_chain_element.h:45
void register_progress_watcher(I_progress_watcher *new_progress_watcher) override
Add new Progress Watcher to report to.
Definition: abstract_chain_element.h:58
uint64 get_id() const override
Returns an application unique ID of this chain element object.
Definition: abstract_chain_element.cc:36
void item_completion_in_child_callback(Item_processing_data *item_processed) override
This callback can be requested to be called by child for any object processing.
Definition: abstract_chain_element.cc:150
Definition: abstract_progress_watcher.h:74
std::atomic< uint64_t > m_row_data
Definition: abstract_progress_watcher.h:81
Progress_data()
Definition: abstract_progress_watcher.cc:153
std::atomic< uint64_t > m_table_count
Definition: abstract_progress_watcher.h:80
std::atomic< uint64_t > m_row_count
Definition: abstract_progress_watcher.h:82
Progress_data operator-(const Progress_data &to_subtract)
Definition: abstract_progress_watcher.cc:128
Progress_data & operator=(const Progress_data &to_copy)
Definition: abstract_progress_watcher.cc:139
Gathers information about progress of current dump progress and format messages on progress....
Definition: abstract_progress_watcher.h:48
void item_completion_in_child_callback(Item_processing_data *item_processed) override
This callback can be requested to be called by child for any object processing.
Definition: abstract_progress_watcher.h:92
void new_chain_created(Item_processing_data *new_chain_process_data) override
Reports new non-empty chain being created by Chain Maker or new row fetched from table by Table Reade...
Definition: abstract_progress_watcher.cc:113
void object_processing_started(Item_processing_data *process_data) override
Report new object(table, row or any other) was started processing by specified Object Reader,...
Definition: abstract_progress_watcher.cc:110
static const int STAGES
Definition: abstract_progress_watcher.h:106
Progress_data m_last_progress
Definition: abstract_progress_watcher.h:89
Progress_data m_total
Definition: abstract_progress_watcher.h:87
std::chrono::system_clock::time_point m_last_stage_time
Definition: abstract_progress_watcher.h:109
uint64 get_id() const override
Returns an application unique ID of this chain element object.
Definition: abstract_progress_watcher.h:66
void progress_changed()
Throttles progress changes to be reported to progress_changed() about 1 in second.
Definition: abstract_progress_watcher.cc:39
Progress_data m_progress
Definition: abstract_progress_watcher.h:88
void object_processing_ended(Item_processing_data *finished_process_data) override
Report object(table, row or any other) finished being processed.
Definition: abstract_progress_watcher.cc:81
std::atomic< int64_t > m_stage_countdown
Definition: abstract_progress_watcher.h:111
virtual void process_progress_step(Progress_data &change)=0
static const int REPORT_DELAY_MS
Definition: abstract_progress_watcher.h:107
Abstract_progress_watcher(std::function< bool(const Mysql::Tools::Base::Message_data &)> *message_handler, Simple_id_generator *object_id_generator)
Definition: abstract_progress_watcher.cc:70
void register_progress_watcher(I_progress_watcher *new_progress_watcher) override
Add new Progress Watcher to report to.
Definition: abstract_progress_watcher.h:60
void crawler_completed(I_crawler *crawler) override
Reports crawler ended enumerating objects and creating chains for them.
Definition: abstract_progress_watcher.cc:79
int64 m_last_step_countdown
Definition: abstract_progress_watcher.h:112
std::atomic< int64_t > m_step_countdown
Definition: abstract_progress_watcher.h:110
Definition: i_crawler.h:36
Definition: i_progress_watcher.h:37
Data structure for objects that are processed in any chain.
Definition: item_processing_data.h:43
Definition: simple_id_generator.h:37
Some integer typedefs for easier portability.
int64_t int64
Definition: my_inttypes.h:68
uint64_t uint64
Definition: my_inttypes.h:69
Definition: abstract_connection_program.h:38