MySQL 8.0.39
Source Code Documentation
object_queue.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 OBJECT_QUEUE_INCLUDED
27#define OBJECT_QUEUE_INCLUDED
28
29#include <sys/types.h>
30#include <atomic>
31#include <functional>
32#include <map>
33#include <mutex>
34#include <queue>
35
41#include "my_inttypes.h"
42
43namespace Mysql {
44namespace Tools {
45namespace Dump {
46
47/**
48 Wrapper to another Object Reader, adds all objects to read on queue. Allows
49 specified number of threads to dequeue and process objects.
50 */
52 public I_object_reader {
53 public:
54 Object_queue(std::function<bool(const Mysql::Tools::Base::Message_data &)>
55 *message_handler,
56 Simple_id_generator *object_id_generator, uint threads_count,
57 std::function<void(bool)> *thread_callback,
59
60 ~Object_queue() override;
61
62 void read_object(Item_processing_data *item_to_process) override;
63
64 // Fix "inherits ... via dominance" warnings
66 I_progress_watcher *new_progress_watcher) override {
68 }
69
70 // Fix "inherits ... via dominance" warnings
71 uint64 get_id() const override { return Abstract_chain_element::get_id(); }
72
73 void stop_queue();
74
75 protected:
76 // Fix "inherits ... via dominance" warnings
78 Item_processing_data *item_processed) override {
80 }
81
82 private:
83 void queue_thread();
84
85 void task_availability_callback(const Abstract_dump_task *available_task);
86
88 std::map<const I_dump_task *,
89 std::vector<Item_processing_data *> *>::iterator it);
90
91 /*
92 Group of threads to process objects on queue.
93 */
95 std::mutex m_queue_mutex;
96 /*
97 Maps task to all processing items that processes specified task.
98 */
99 std::map<const I_dump_task *, std::vector<Item_processing_data *> *>
101 std::queue<Item_processing_data *> m_items_ready_for_processing;
102 /*
103 Standard callback on task completion to run all possible dependent tasks.
104 */
106 /*
107 Indicates if queue is running. If set to false, all pending and being
108 processed tasks should complete, then queue is ready to close.
109 */
110 std::atomic<bool> m_is_queue_running;
111 /*
112 Callback called when created thread is starting or exiting. Call is done in
113 execution context of created thread. Parameter value
114 of true is used for thread start, false for thread exit.
115 */
116 std::function<void(bool)> *m_thread_callback;
118};
119
120} // namespace Dump
121} // namespace Tools
122} // namespace Mysql
123
124#endif
Base class for all MySQL client tools.
Definition: abstract_program.h:47
Structure to represent message from server sent after executing query.
Definition: message_data.h:49
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
Base class for most individual dump process tasks, not suitable for lightweight dump tasks (e....
Definition: abstract_dump_task.h:44
Implementation of common logic for classes that directs execution of dump tasks to Object Readers.
Definition: abstract_object_reader_wrapper.h:43
Interface for all individual dump process tasks.
Definition: i_dump_task.h:38
Definition: i_object_reader.h:36
Definition: i_progress_watcher.h:37
Data structure for objects that are processed in any chain.
Definition: item_processing_data.h:43
Wrapper to another Object Reader, adds all objects to read on queue.
Definition: object_queue.h:52
void read_object(Item_processing_data *item_to_process) override
Reads information on DB object related to task.
Definition: object_queue.cc:94
void stop_queue()
Definition: object_queue.cc:141
Object_queue(std::function< bool(const Mysql::Tools::Base::Message_data &)> *message_handler, Simple_id_generator *object_id_generator, uint threads_count, std::function< void(bool)> *thread_callback, Mysql::Tools::Base::Abstract_program *program)
Definition: object_queue.cc:170
uint64 get_id() const override
Returns an application unique ID of this chain element object.
Definition: object_queue.h:71
void queue_thread()
Definition: object_queue.cc:59
std::map< const I_dump_task *, std::vector< Item_processing_data * > * > m_tasks_map
Definition: object_queue.h:100
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: object_queue.h:77
Mysql::Tools::Base::Abstract_program * m_program
Definition: object_queue.h:117
std::function< void(const Abstract_dump_task *)> m_task_availability_callback
Definition: object_queue.h:105
std::function< void(bool)> * m_thread_callback
Definition: object_queue.h:116
void add_ready_items_to_queue(std::map< const I_dump_task *, std::vector< Item_processing_data * > * >::iterator it)
Definition: object_queue.cc:36
std::atomic< bool > m_is_queue_running
Definition: object_queue.h:110
~Object_queue() override
Definition: object_queue.cc:161
my_boost::thread_group m_thread_group
Definition: object_queue.h:94
std::mutex m_queue_mutex
Definition: object_queue.h:95
void register_progress_watcher(I_progress_watcher *new_progress_watcher) override
Add new Progress Watcher to report to.
Definition: object_queue.h:65
std::queue< Item_processing_data * > m_items_ready_for_processing
Definition: object_queue.h:101
void task_availability_callback(const Abstract_dump_task *available_task)
Definition: object_queue.cc:48
Definition: simple_id_generator.h:37
Definition: thread_group.h:35
Some integer typedefs for easier portability.
uint64_t uint64
Definition: my_inttypes.h:69
Definition: abstract_connection_program.h:38
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2892
unsigned int uint
Definition: uca9-dump.cc:75