1 /* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License, version 2.0, 5 as published by the Free Software Foundation. 6 7 This program is also distributed with certain software (including 8 but not limited to OpenSSL) that is licensed under separate terms, 9 as designated in a particular file or component or in included license 10 documentation. The authors of MySQL hereby grant you an additional 11 permission to link the program and your derivative works with the 12 separately licensed software that they have included with MySQL. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License, version 2.0, for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 22 23 /** 24 @file clone/include/clone_local.h 25 Clone Plugin: Local clone interface 26 27 */ 28 29 #ifndef CLONE_LOCAL_H 30 #define CLONE_LOCAL_H 31 32 #include "plugin/clone/include/clone.h" 33 #include "plugin/clone/include/clone_client.h" 34 #include "plugin/clone/include/clone_hton.h" 35 #include "plugin/clone/include/clone_server.h" 36 37 /* Namespace for all clone data types */ 38 namespace myclone { 39 /** We create it for Local Clone. It retrieves data from Storage Engines 40 and applies to the cloned data directory. It uses embedded "Clone Client" 41 and "Clone Server" object to accomplish the job. "Clone Server" is used to 42 fetch the data from server which is returned via callbacks. "Clone Client" 43 handle applies the data to create a cloned database. */ 44 class Local { 45 public: 46 /** Construct clone local. Initialize "Clone Client" and 47 "Clone Server" objects. 48 @param[in,out] thd server thread handle 49 @param[in] server shared server handle 50 @param[in] share shared client information 51 @param[in] index index of current thread 52 @param[in] is_master true, if it is master thread */ 53 Local(THD *thd, Server *server, Client_Share *share, uint32_t index, 54 bool is_master); 55 56 /** Get clone client for data transfer. 57 @return clone client handle */ get_client()58 Client *get_client() { return (&m_clone_client); } 59 60 /** Get clone server for data transfer. 61 @return clone server handle */ get_server()62 Server *get_server() { return (m_clone_server); } 63 64 /** Clone current database and update PFS. 65 @return error code */ 66 int clone(); 67 68 /** Clone current database to the destination data directory. 69 @return error code */ 70 int clone_exec(); 71 72 private: 73 /** "Clone Server" object to copy data */ 74 Server *m_clone_server; 75 76 /** "Clone Client" object to apply data */ 77 Client m_clone_client; 78 }; 79 80 /** Clone Local interface to handle callback from Storage Engines */ 81 class Local_Callback : public Ha_clone_cbk { 82 public: 83 /** Construct Callback. Set clone local object. 84 @param[in] clone clone local object */ Local_Callback(Local * clone)85 Local_Callback(Local *clone) : m_clone_local(clone), m_apply_data(false) {} 86 87 /** Get clone client object 88 @return clone client */ get_clone_client()89 Client *get_clone_client() { return (m_clone_local->get_client()); } 90 91 /** Get clone server object 92 @return clone server */ get_clone_server()93 Server *get_clone_server() { return (m_clone_local->get_server()); } 94 95 /** Get external handle of "Clone Client" 96 @return client external handle */ get_client_data_link()97 Data_Link *get_client_data_link() { 98 auto client = m_clone_local->get_client(); 99 MYSQL *conn; 100 101 return (client->get_data_link(conn)); 102 } 103 104 /** Clone local file callback: Set source file as external handle 105 for embedded "Clone Client" object and apply data using storage 106 engine interface. 107 @param[in] from_file source file descriptor 108 @param[in] len data length 109 @return error code */ 110 int file_cbk(Ha_clone_file from_file, uint len) override; 111 112 /** Clone local buffer callback: Set source buffer as external handle 113 for embedded "Clone Client" object and apply data using storage 114 engine interface. 115 @param[in] from_buffer source buffer 116 @param[in] buf_len data length 117 @return error code */ 118 int buffer_cbk(uchar *from_buffer, uint buf_len) override; 119 120 /** Clone local apply file callback: Copy data from "Clone Client" 121 external handle to storage engine file. 122 @param[in] to_file destination file 123 @return error code */ 124 int apply_file_cbk(Ha_clone_file to_file) override; 125 126 /** Clone local apply callback: get data in buffer 127 @param[out] to_buffer data buffer 128 @param[out] len data length 129 @return error code */ 130 int apply_buffer_cbk(uchar *&to_buffer, uint &len) override; 131 132 private: 133 /** Apply data using storage engine apply interface. 134 @return error code */ 135 int apply_data(); 136 137 /** Acknowledge data transfer. 138 @return error code */ 139 int apply_ack(); 140 141 /** Apply data to local file or buffer. 142 @param[in,out] to_file destination file 143 @param[in] apply_file copy data to file 144 @param[out] to_buffer data buffer 145 @param[out] to_len data length 146 @return error code */ 147 int apply_cbk(Ha_clone_file to_file, bool apply_file, uchar *&to_buffer, 148 uint &to_len); 149 150 private: 151 /** Clone local object */ 152 Local *m_clone_local; 153 154 /** Applying cloned data */ 155 bool m_apply_data; 156 }; 157 158 } // namespace myclone 159 160 #endif /* CLONE_LOCAL_H */ 161