1 /* Copyright (c) 2013, 2021, Oracle and/or its affiliates.
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 Foundation,
21    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #ifndef OBSERVER_TRANS
24 #define OBSERVER_TRANS
25 
26 #include <mysql/gcs/gcs_communication_interface.h>
27 #include "gcs_plugin_messages.h"
28 #include "plugin.h"
29 
30 /**
31   Initialize transactions observer structures.
32 */
33 void observer_trans_initialize();
34 
35 /**
36   Terminate transactions observer structures.
37 */
38 void observer_trans_terminate();
39 
40 /**
41   Clear server sessions opened caches.
42 */
43 void observer_trans_clear_io_cache_unused_list();
44 
45 /*
46   Transaction lifecycle events observers.
47 */
48 int group_replication_trans_before_dml(Trans_param *param, int& out);
49 
50 int group_replication_trans_before_commit(Trans_param *param);
51 
52 int group_replication_trans_before_rollback(Trans_param *param);
53 
54 int group_replication_trans_after_commit(Trans_param *param);
55 
56 int group_replication_trans_after_rollback(Trans_param *param);
57 
58 extern Trans_observer trans_observer;
59 
60 /*
61   @class Transaction_Message
62   Class to convey the serialized contents of the TCLE
63  */
64 class Transaction_Message: public Plugin_gcs_message
65 {
66 public:
67   enum enum_payload_item_type
68   {
69     // This type should not be used anywhere.
70     PIT_UNKNOWN= 0,
71 
72     // Length of the payload item: variable
73     PIT_TRANSACTION_DATA= 1,
74 
75     // No valid type codes can appear after this one.
76     PIT_MAX= 2
77   };
78 
79   /**
80    Default constructor
81    */
82   Transaction_Message();
83   virtual ~Transaction_Message();
84 
85   /**
86     Appends IO_CACHE data to the internal buffer
87 
88     @param[in] src the IO_CACHE to copy data from
89 
90     @return true in case of error
91    */
92   bool append_cache(IO_CACHE *src);
93 
94 protected:
95   /*
96    Implementation of the template methods
97    */
98   void encode_payload(std::vector<unsigned char>* buffer) const;
99   void decode_payload(const unsigned char* buffer, const unsigned char* length);
100 
101 private:
102   std::vector<uchar> data;
103 };
104 
105 /**
106   Broadcasts the Transaction Message
107 
108   @param msg the message to broadcast
109 
110   @return the communication engine broadcast message error
111     @retval GCS_OK, when message is transmitted successfully
112     @retval GCS_NOK, when error occurred while transmitting message
113     @retval GCS_MESSAGE_TOO_BIG, when message is bigger than
114                                  communication engine can handle
115  */
116 enum enum_gcs_error send_transaction_message(Transaction_Message* msg);
117 
118 #endif /* OBSERVER_TRANS */
119