MySQL 8.3.0
Source Code Documentation
object_queue.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2015, 2023, 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 also distributed 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 included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#ifndef OBJECT_QUEUE_INCLUDED
26#define OBJECT_QUEUE_INCLUDED
27
28#include <sys/types.h>
29#include <atomic>
30#include <functional>
31#include <map>
32#include <mutex>
33#include <queue>
34
40#include "my_inttypes.h"
41
42namespace Mysql {
43namespace Tools {
44namespace Dump {
45
46/**
47 Wrapper to another Object Reader, adds all objects to read on queue. Allows
48 specified number of threads to dequeue and process objects.
49 */
51 public I_object_reader {
52 public:
53 Object_queue(std::function<bool(const Mysql::Tools::Base::Message_data &)>
54 *message_handler,
55 Simple_id_generator *object_id_generator, uint threads_count,
56 std::function<void(bool)> *thread_callback,
58
59 ~Object_queue() override;
60
61 void read_object(Item_processing_data *item_to_process) override;
62
63 // Fix "inherits ... via dominance" warnings
65 I_progress_watcher *new_progress_watcher) override {
67 }
68
69 // Fix "inherits ... via dominance" warnings
70 uint64 get_id() const override { return Abstract_chain_element::get_id(); }
71
72 void stop_queue();
73
74 protected:
75 // Fix "inherits ... via dominance" warnings
77 Item_processing_data *item_processed) override {
79 }
80
81 private:
82 void queue_thread();
83
84 void task_availability_callback(const Abstract_dump_task *available_task);
85
87 std::map<const I_dump_task *,
88 std::vector<Item_processing_data *> *>::iterator it);
89
90 /*
91 Group of threads to process objects on queue.
92 */
94 std::mutex m_queue_mutex;
95 /*
96 Maps task to all processing items that processes specified task.
97 */
98 std::map<const I_dump_task *, std::vector<Item_processing_data *> *>
100 std::queue<Item_processing_data *> m_items_ready_for_processing;
101 /*
102 Standard callback on task completion to run all possible dependent tasks.
103 */
105 /*
106 Indicates if queue is running. If set to false, all pending and being
107 processed tasks should complete, then queue is ready to close.
108 */
109 std::atomic<bool> m_is_queue_running;
110 /*
111 Callback called when created thread is starting or exiting. Call is done in
112 execution context of created thread. Parameter value
113 of true is used for thread start, false for thread exit.
114 */
115 std::function<void(bool)> *m_thread_callback;
117};
118
119} // namespace Dump
120} // namespace Tools
121} // namespace Mysql
122
123#endif
Base class for all MySQL client tools.
Definition: abstract_program.h:46
Structure to represent message from server sent after executing query.
Definition: message_data.h:48
void register_progress_watcher(I_progress_watcher *new_progress_watcher) override
Add new Progress Watcher to report to.
Definition: abstract_chain_element.h:57
uint64 get_id() const override
Returns an application unique ID of this chain element object.
Definition: abstract_chain_element.cc:35
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:149
Base class for most individual dump process tasks, not suitable for lightweight dump tasks (e....
Definition: abstract_dump_task.h:43
Implementation of common logic for classes that directs execution of dump tasks to Object Readers.
Definition: abstract_object_reader_wrapper.h:42
Interface for all individual dump process tasks.
Definition: i_dump_task.h:37
Definition: i_object_reader.h:35
Definition: i_progress_watcher.h:36
Data structure for objects that are processed in any chain.
Definition: item_processing_data.h:42
Wrapper to another Object Reader, adds all objects to read on queue.
Definition: object_queue.h:51
void read_object(Item_processing_data *item_to_process) override
Reads information on DB object related to task.
Definition: object_queue.cc:93
void stop_queue()
Definition: object_queue.cc:140
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:169
uint64 get_id() const override
Returns an application unique ID of this chain element object.
Definition: object_queue.h:70
void queue_thread()
Definition: object_queue.cc:58
std::map< const I_dump_task *, std::vector< Item_processing_data * > * > m_tasks_map
Definition: object_queue.h:99
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:76
Mysql::Tools::Base::Abstract_program * m_program
Definition: object_queue.h:116
std::function< void(const Abstract_dump_task *)> m_task_availability_callback
Definition: object_queue.h:104
std::function< void(bool)> * m_thread_callback
Definition: object_queue.h:115
void add_ready_items_to_queue(std::map< const I_dump_task *, std::vector< Item_processing_data * > * >::iterator it)
Definition: object_queue.cc:35
std::atomic< bool > m_is_queue_running
Definition: object_queue.h:109
~Object_queue() override
Definition: object_queue.cc:160
my_boost::thread_group m_thread_group
Definition: object_queue.h:93
std::mutex m_queue_mutex
Definition: object_queue.h:94
void register_progress_watcher(I_progress_watcher *new_progress_watcher) override
Add new Progress Watcher to report to.
Definition: object_queue.h:64
std::queue< Item_processing_data * > m_items_ready_for_processing
Definition: object_queue.h:100
void task_availability_callback(const Abstract_dump_task *available_task)
Definition: object_queue.cc:47
Definition: simple_id_generator.h:36
Definition: thread_group.h:34
Some integer typedefs for easier portability.
uint64_t uint64
Definition: my_inttypes.h:68
Definition: abstract_connection_program.h:39
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2891