1 /* Copyright (c) 2014, 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
21    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 #ifndef RPL_TRANSACTION_CTX_H
24 #define RPL_TRANSACTION_CTX_H
25 
26 #include "my_global.h"
27 #include "mysql/service_rpl_transaction_ctx.h" // Transaction_termination_ctx
28 
29 /**
30   Server side support to provide a service to plugins to report if
31   a given transaction should continue or be aborted.
32   Its value is reset on Transaction_ctx::cleanup().
33   Its value is set through service service_rpl_transaction_ctx.
34 */
35 class Rpl_transaction_ctx
36 {
37 public:
38   Rpl_transaction_ctx();
~Rpl_transaction_ctx()39   virtual ~Rpl_transaction_ctx() {}
40 
41   /**
42     Set transaction context, that is, notify the server that for
43     external reasons the ongoing transaction should continue or be
44     aborted.
45     See @file include/mysql/service_rpl_transaction_ctx.h
46 
47     @param transaction_termination_ctx  Transaction termination context
48     @return
49          @retval 0      success
50          @retval !=0    error
51   */
52   int set_rpl_transaction_ctx(Transaction_termination_ctx transaction_termination_ctx);
53 
54   /**
55     Get transaction outcome decision.
56     When both sidno and gno are equal or greater than zero,
57     transaction should continue.
58     By default sidno and gno are 0, transaction will continue.
59 
60     @return
61          @retval true      Transaction should abort
62          @retval false     Transaction should continue
63   */
64   bool is_transaction_rollback();
65 
66   /**
67     Was GTID generated externally?
68 
69     @return
70          @retval true      GTID was generated.
71          @retval false     GTID was not generated.
72   */
73   bool is_generated_gtid();
74 
75   /**
76     Get transaction sidno.
77 
78     @return sidno sidno value.
79   */
80   int get_sidno();
81 
82   /**
83     Get transaction gno.
84 
85     @return gno   gno value.
86   */
87   long long int get_gno();
88 
89   /**
90    Reset transaction context to default values.
91   */
92   void cleanup();
93 
94 private:
95   Transaction_termination_ctx m_transaction_ctx;
96 };
97 
98 #endif	/* RPL_TRANSACTION_CTX_H */
99