1 /* Copyright (c) 2012, 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
22 02110-1301 USA */
23
24 #include "rpl_gtid.h"
25
26
27 //const int Gtid_specification::MAX_TEXT_LENGTH;
28
29 #ifndef MYSQL_CLIENT
30
parse(Sid_map * sid_map,const char * text)31 enum_return_status Gtid_specification::parse(Sid_map *sid_map, const char *text)
32 {
33 DBUG_ENTER("Gtid_specification::parse");
34 assert(text != NULL);
35 if (my_strcasecmp(&my_charset_latin1, text, "AUTOMATIC") == 0)
36 {
37 type= AUTOMATIC_GROUP;
38 gtid.sidno= 0;
39 gtid.gno= 0;
40 }
41 else if (my_strcasecmp(&my_charset_latin1, text, "ANONYMOUS") == 0)
42 {
43 type= ANONYMOUS_GROUP;
44 gtid.sidno= 0;
45 gtid.gno= 0;
46 }
47 else
48 {
49 PROPAGATE_REPORTED_ERROR(gtid.parse(sid_map, text));
50 type= GTID_GROUP;
51 }
52 RETURN_OK;
53 };
54
55
is_valid(const char * text)56 bool Gtid_specification::is_valid(const char *text)
57 {
58 DBUG_ENTER("Gtid_specification::is_valid");
59 assert(text != NULL);
60 if (my_strcasecmp(&my_charset_latin1, text, "AUTOMATIC") == 0)
61 DBUG_RETURN(true);
62 else if (my_strcasecmp(&my_charset_latin1, text, "ANONYMOUS") == 0)
63 DBUG_RETURN(true);
64 else
65 DBUG_RETURN(Gtid::is_valid(text));
66 }
67
68 #endif // ifndef MYSQL_CLIENT
69
70
to_string(const rpl_sid * sid,char * buf) const71 int Gtid_specification::to_string(const rpl_sid *sid, char *buf) const
72 {
73 DBUG_ENTER("Gtid_specification::to_string(char*)");
74 switch (type)
75 {
76 case AUTOMATIC_GROUP:
77 strcpy(buf, "AUTOMATIC");
78 DBUG_RETURN(9);
79 case NOT_YET_DETERMINED_GROUP:
80 /*
81 This can happen if user issues SELECT @@SESSION.GTID_NEXT
82 immediately after a BINLOG statement containing a
83 Format_description_log_event.
84 */
85 strcpy(buf, "NOT_YET_DETERMINED");
86 DBUG_RETURN(18);
87 case ANONYMOUS_GROUP:
88 strcpy(buf, "ANONYMOUS");
89 DBUG_RETURN(9);
90 /*
91 UNDEFINED_GROUP must be printed like GTID_GROUP because of
92 SELECT @@SESSION.GTID_NEXT.
93 */
94 case UNDEFINED_GROUP:
95 case GTID_GROUP:
96 DBUG_RETURN(gtid.to_string(*sid, buf));
97 }
98 assert(0);
99 DBUG_RETURN(0);
100 }
101
102
to_string(const Sid_map * sid_map,char * buf,bool need_lock) const103 int Gtid_specification::to_string(const Sid_map *sid_map, char *buf, bool need_lock) const
104 {
105 return to_string(type == GTID_GROUP || type == UNDEFINED_GROUP ?
106 &sid_map->sidno_to_sid(gtid.sidno, need_lock) : NULL,
107 buf);
108 }
109