1 /* Copyright (C) 2007 Google Inc.
2    Copyright (c) 2000, 2021, 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 SEMISYNC_H
26 #define SEMISYNC_H
27 
28 #define MYSQL_SERVER
29 #define HAVE_REPLICATION
30 
31 #include <my_global.h>
32 #include <my_thread.h>
33 #include <mysql/plugin.h>
34 #include <replication.h>
35 #include "log.h"                                /* sql_print_information */
36 
37 typedef struct st_mysql_show_var SHOW_VAR;
38 typedef struct st_mysql_sys_var SYS_VAR;
39 
40 
41 /**
42    This class is used to trace function calls and other process
43    information
44 */
45 class Trace {
46 public:
47   static const unsigned long kTraceFunction;
48   static const unsigned long kTraceGeneral;
49   static const unsigned long kTraceDetail;
50   static const unsigned long kTraceNetWait;
51 
52   unsigned long           trace_level_;                      /* the level for tracing */
53 
function_enter(const char * func_name)54   inline void function_enter(const char *func_name)
55   {
56     if (trace_level_ & kTraceFunction)
57       sql_print_information("---> %s enter", func_name);
58   }
59 
function_exit(const char * func_name,int exit_code)60   inline int  function_exit(const char *func_name, int exit_code)
61   {
62     if (trace_level_ & kTraceFunction)
63       sql_print_information("<--- %s exit (%d)", func_name, exit_code);
64     return exit_code;
65   }
66 
function_exit(const char * func_name,bool exit_code)67   inline bool function_exit(const char *func_name, bool exit_code)
68   {
69     if (trace_level_ & kTraceFunction)
70       sql_print_information("<--- %s exit (%s)", func_name,
71                             exit_code ? "True" : "False");
72     return exit_code;
73   }
74 
function_exit(const char * func_name)75   inline void function_exit(const char *func_name)
76   {
77     if (trace_level_ & kTraceFunction)
78       sql_print_information("<--- %s exit", func_name);
79   }
80 
Trace()81 Trace()
82     :trace_level_(0L)
83   {}
Trace(unsigned long trace_level)84   Trace(unsigned long trace_level)
85     :trace_level_(trace_level)
86   {}
87 };
88 
89 /**
90    Base class for semi-sync master and slave classes
91 */
92 class ReplSemiSyncBase
93   :public Trace {
94 public:
95   static const unsigned char  kSyncHeader[2];     /* three byte packet header */
96 
97   /* Constants in network packet header. */
98   static const unsigned char kPacketMagicNum;
99   static const unsigned char kPacketFlagSync;
100 };
101 
102 /* The layout of a semisync slave reply packet:
103    1 byte for the magic num
104    8 bytes for the binlog positon
105    n bytes for the binlog filename, terminated with a '\0'
106 */
107 #define REPLY_MAGIC_NUM_LEN 1
108 #define REPLY_BINLOG_POS_LEN 8
109 #define REPLY_BINLOG_NAME_LEN (FN_REFLEN + 1)
110 #define REPLY_MESSAGE_MAX_LENGTH \
111   (REPLY_MAGIC_NUM_LEN + REPLY_BINLOG_POS_LEN + REPLY_BINLOG_NAME_LEN)
112 #define REPLY_MAGIC_NUM_OFFSET 0
113 #define REPLY_BINLOG_POS_OFFSET (REPLY_MAGIC_NUM_OFFSET + REPLY_MAGIC_NUM_LEN)
114 #define REPLY_BINLOG_NAME_OFFSET (REPLY_BINLOG_POS_OFFSET + REPLY_BINLOG_POS_LEN)
115 
116 #endif /* SEMISYNC_H */
117