22 #include "sql_class.h"
27 DBUG_ENTER(
"Gtid_state::clear()");
38 DBUG_ENTER(
"Gtid_state::acquire_ownership");
43 DBUG_PRINT(
"info", (
"group=%d:%lld", gtid.
sidno, gtid.
gno));
44 DBUG_ASSERT(thd->owned_gtid.sidno == 0);
45 if (owned_gtids.
add_gtid_owner(gtid, thd->thread_id) != RETURN_STATUS_OK)
47 if (thd->get_gtid_next_list() != NULL)
49 #ifdef HAVE_GTID_NEXT_LIST
50 if (thd->owned_gtid_set._add_gtid(gtid) != RETURN_STATUS_OK)
52 thd->owned_gtid.sidno= -1;
58 thd->owned_gtid= gtid;
60 #ifdef HAVE_GTID_NEXT_LIST
65 if (thd->get_gtid_next_list() != NULL)
67 #ifdef HAVE_GTID_NEXT_LIST
79 thd->owned_gtid_set.clear();
80 thd->owned_gtid.sidno= 0;
81 RETURN_REPORTED_ERROR;
84 #ifdef HAVE_GTID_NEXT_LIST
85 void Gtid_state::lock_owned_sidnos(
const THD *thd)
87 if (thd->owned_gtid.sidno == -1)
88 lock_sidnos(&thd->owned_gtid_set);
89 else if (thd->owned_gtid.sidno > 0)
95 void Gtid_state::unlock_owned_sidnos(
const THD *thd)
97 if (thd->owned_gtid.sidno == -1)
99 #ifdef HAVE_GTID_NEXT_LIST
100 unlock_sidnos(&thd->owned_gtid_set);
105 else if (thd->owned_gtid.sidno > 0)
112 void Gtid_state::broadcast_owned_sidnos(
const THD *thd)
114 if (thd->owned_gtid.sidno == -1)
116 #ifdef HAVE_GTID_NEXT_LIST
117 broadcast_sidnos(&thd->owned_gtid_set);
122 else if (thd->owned_gtid.sidno > 0)
131 DBUG_ENTER(
"Gtid_state::update_on_flush");
132 enum_return_status
ret= RETURN_STATUS_OK;
137 if (thd->owned_gtid.sidno == -1)
139 #ifdef HAVE_GTID_NEXT_LIST
140 rpl_sidno prev_sidno= 0;
145 if (g.
sidno != prev_sidno)
147 if (ret == RETURN_STATUS_OK)
156 else if (thd->owned_gtid.sidno > 0)
159 ret= logged_gtids.
_add_gtid(thd->owned_gtid);
170 thd->variables.gtid_next.set_undefined();
171 broadcast_owned_sidnos(thd);
172 unlock_owned_sidnos(thd);
180 DBUG_ENTER(
"Gtid_state::update_on_commit");
181 update_owned_gtids_impl(thd,
true);
188 DBUG_ENTER(
"Gtid_state::update_on_rollback");
189 update_owned_gtids_impl(thd,
false);
194 void Gtid_state::update_owned_gtids_impl(THD *thd,
bool is_commit)
196 DBUG_ENTER(
"Gtid_state::update_owned_gtids_impl");
201 if (thd->owned_gtid.sidno == -1)
203 #ifdef HAVE_GTID_NEXT_LIST
204 rpl_sidno prev_sidno= 0;
209 if (g.
sidno != prev_sidno)
219 else if (thd->owned_gtid.sidno > 0)
230 thd->variables.gtid_next.set_undefined();
232 broadcast_owned_sidnos(thd);
233 unlock_owned_sidnos(thd);
235 thd->clear_owned_gtids();
243 DBUG_ENTER(
"Gtid_state::get_automatic_gno");
246 Gtid next_candidate= { sidno, 1 };
250 rpl_gno next_interval_start= iv != NULL ? iv->
start : MAX_GNO;
251 while (next_candidate.
gno < next_interval_start)
253 if (owned_gtids.
get_owner(next_candidate) == 0)
254 DBUG_RETURN(next_candidate.
gno);
255 next_candidate.
gno++;
259 my_error(ER_GNO_EXHAUSTED, MYF(0));
262 next_candidate.
gno= iv->
end;
270 DBUG_ENTER(
"Gtid_state::wait_for_gtid");
273 DBUG_PRINT(
"info", (
"SIDNO=%d GNO=%lld owner(sidno,gno)=%lu thread_id=%lu",
275 owned_gtids.
get_owner(gtid), thd->thread_id));
276 DBUG_ASSERT(owned_gtids.
get_owner(gtid) != thd->thread_id);
278 &stage_waiting_for_gtid_to_be_written_to_binary_log,
282 thd->EXIT_COND(&old_stage);
288 #ifdef HAVE_GTID_NEXT_LIST
289 void Gtid_state::lock_sidnos(
const Gtid_set *gs)
293 for (rpl_sidno sidno= 1; sidno <= max_sidno; sidno++)
299 void Gtid_state::unlock_sidnos(
const Gtid_set *gs)
303 for (rpl_sidno sidno= 1; sidno <= max_sidno; sidno++)
309 void Gtid_state::broadcast_sidnos(
const Gtid_set *gs)
313 for (rpl_sidno sidno= 1; sidno <= max_sidno; sidno++)
322 DBUG_ENTER(
"Gtid_state::ensure_sidno");
330 PROPAGATE_REPORTED_ERROR(logged_gtids.
ensure_sidno(sidno));
331 PROPAGATE_REPORTED_ERROR(lost_gtids.
ensure_sidno(sidno));
332 PROPAGATE_REPORTED_ERROR(owned_gtids.
ensure_sidno(sidno));
333 PROPAGATE_REPORTED_ERROR(sid_locks.
ensure_index(sidno));
346 DBUG_ENTER(
"Gtid_state::add_lost_gtids()");
349 DBUG_PRINT(
"info", (
"add_lost_gtids '%s'", text));
353 BINLOG_ERROR((ER(ER_CANT_SET_GTID_PURGED_WHEN_GTID_EXECUTED_IS_NOT_EMPTY)),
354 (ER_CANT_SET_GTID_PURGED_WHEN_GTID_EXECUTED_IS_NOT_EMPTY,
356 RETURN_REPORTED_ERROR;
360 BINLOG_ERROR((ER(ER_CANT_SET_GTID_PURGED_WHEN_OWNED_GTIDS_IS_NOT_EMPTY)),
361 (ER_CANT_SET_GTID_PURGED_WHEN_OWNED_GTIDS_IS_NOT_EMPTY,
363 RETURN_REPORTED_ERROR;
370 DBUG_RETURN(RETURN_STATUS_OK);
376 DBUG_ENTER(
"Gtid_state::init()");
381 if (server_sid.
parse(server_uuid) != RETURN_STATUS_OK)
383 rpl_sidno sidno= sid_map->
add_sid(server_sid);