1 /* Copyright (C) 2007 Google Inc. 2 Copyright (C) 2008 MySQL AB 3 Use is subject to license terms 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed with certain software (including 10 but not limited to OpenSSL) that is licensed under separate terms, 11 as designated in a particular file or component or in included license 12 documentation. The authors of MySQL hereby grant you an additional 13 permission to link the program and your derivative works with the 14 separately licensed software that they have included with MySQL. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License, version 2.0, for more details. 20 21 You should have received a copy of the GNU General Public License 22 along with this program; if not, write to the Free Software 23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 24 25 26 #ifndef SEMISYNC_H 27 #define SEMISYNC_H 28 29 #define MYSQL_SERVER 30 #define HAVE_REPLICATION 31 #include <sql_priv.h> 32 #include "unireg.h" 33 #include <my_global.h> 34 #include <my_pthread.h> 35 #include <mysql/plugin.h> 36 #include <replication.h> 37 #include "log.h" /* sql_print_information */ 38 39 typedef struct st_mysql_show_var SHOW_VAR; 40 typedef struct st_mysql_sys_var SYS_VAR; 41 42 43 /** 44 This class is used to trace function calls and other process 45 information 46 */ 47 class Trace { 48 public: 49 static const unsigned long kTraceFunction; 50 static const unsigned long kTraceGeneral; 51 static const unsigned long kTraceDetail; 52 static const unsigned long kTraceNetWait; 53 54 unsigned long trace_level_; /* the level for tracing */ 55 function_enter(const char * func_name)56 inline void function_enter(const char *func_name) 57 { 58 if (trace_level_ & kTraceFunction) 59 sql_print_information("---> %s enter", func_name); 60 } function_exit(const char * func_name,int exit_code)61 inline int function_exit(const char *func_name, int exit_code) 62 { 63 if (trace_level_ & kTraceFunction) 64 sql_print_information("<--- %s exit (%d)", func_name, exit_code); 65 return exit_code; 66 } 67 Trace()68 Trace() 69 :trace_level_(0L) 70 {} Trace(unsigned long trace_level)71 Trace(unsigned long trace_level) 72 :trace_level_(trace_level) 73 {} 74 }; 75 76 /** 77 Base class for semi-sync master and slave classes 78 */ 79 class ReplSemiSyncBase 80 :public Trace { 81 public: 82 static const unsigned char kSyncHeader[2]; /* three byte packet header */ 83 84 /* Constants in network packet header. */ 85 static const unsigned char kPacketMagicNum; 86 static const unsigned char kPacketFlagSync; 87 }; 88 89 /* The layout of a semisync slave reply packet: 90 1 byte for the magic num 91 8 bytes for the binlog positon 92 n bytes for the binlog filename, terminated with a '\0' 93 */ 94 #define REPLY_MAGIC_NUM_LEN 1 95 #define REPLY_BINLOG_POS_LEN 8 96 #define REPLY_BINLOG_NAME_LEN (FN_REFLEN + 1) 97 #define REPLY_MAGIC_NUM_OFFSET 0 98 #define REPLY_BINLOG_POS_OFFSET (REPLY_MAGIC_NUM_OFFSET + REPLY_MAGIC_NUM_LEN) 99 #define REPLY_BINLOG_NAME_OFFSET (REPLY_BINLOG_POS_OFFSET + REPLY_BINLOG_POS_LEN) 100 101 #endif /* SEMISYNC_H */ 102