1 /* Copyright (c) 2015, 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 #include "auto_increment.h"
24 #include "plugin_log.h"
25 #include "plugin.h"
26 
27 
28 Plugin_group_replication_auto_increment::
Plugin_group_replication_auto_increment()29 Plugin_group_replication_auto_increment()
30   : group_replication_auto_increment(0),
31     group_replication_auto_offset(0)
32 {
33 }
34 
35 void
36 Plugin_group_replication_auto_increment::
reset_auto_increment_variables()37 reset_auto_increment_variables()
38 {
39   /* get server auto_increment variables value */
40   ulong current_server_increment= get_auto_increment_increment();
41   ulong current_server_offset= get_auto_increment_offset();
42 
43   /*
44     Verify whether auto_increment variables were modified by user
45     or by group_replication, by checking their last saved values in
46     group_replication_auto_increment_increment and
47     group_replication_auto_increment_offset
48   */
49   if (group_replication_auto_increment == current_server_increment &&
50       group_replication_auto_offset == current_server_offset)
51   {
52     /* set to default values i.e. 1 */
53     set_auto_increment_increment(SERVER_DEFAULT_AUTO_INCREMENT);
54     set_auto_increment_offset(SERVER_DEFAULT_AUTO_OFFSET);
55 
56     log_message(MY_INFORMATION_LEVEL,
57                 "auto_increment_increment is reset to %lu",
58                 SERVER_DEFAULT_AUTO_INCREMENT);
59 
60     log_message(MY_INFORMATION_LEVEL,
61                 "auto_increment_offset is reset to %lu",
62                 SERVER_DEFAULT_AUTO_OFFSET);
63   }
64 }
65 
66 void
67 Plugin_group_replication_auto_increment::
set_auto_increment_variables(ulong increment,ulong offset)68 set_auto_increment_variables(ulong increment, ulong offset)
69 {
70   /* get server auto_increment variables value */
71   ulong current_server_increment= get_auto_increment_increment();
72   ulong current_server_offset= get_auto_increment_offset();
73 
74   if (current_server_increment == 1 &&
75       current_server_offset == 1)
76   {
77     /* set server auto_increment variables */
78     set_auto_increment_increment(increment);
79     set_auto_increment_offset(offset);
80 
81     /*
82       store auto_increment variables in local variables to verify later
83       in destructor if auto_increment variables were modified by user.
84     */
85     group_replication_auto_increment= increment;
86     group_replication_auto_offset= offset;
87 
88     log_message(MY_INFORMATION_LEVEL,
89                 "auto_increment_increment is set to %lu",
90                 increment);
91 
92     log_message(MY_INFORMATION_LEVEL,
93                 "auto_increment_offset is set to %lu",
94                 offset);
95   }
96 }
97