Skip to content

Commit 2006195

Browse files
author
Anibal Pinto
committed
BUG#25256910: NODE RECOVERY FAILS WITH ERROR_CODE: 1062; HANDLER ERROR HA_ERR_FOUND_DUPP_KEY
On Single Primary Mode Group Replication certification process is disabled, only one server accepts writes so there aren't conflicts. Exist one exception for when a new primary server is being elected. This causes a problem for when a new server is entering the group, it doesn't know if certification is enable or not in the group as a consequence of the primary election mechanism. Hence, queries being rejected in other member can be accepted and fail on the new joiner. This patch solves this problem sending on view change, when a member join or leaves, the state of conflict detection of the members. When the member enters it will receive the state of conflict detection of all members and activate it if one of the members has conflict detection active.
1 parent 978bf35 commit 2006195

18 files changed

+410
-39
lines changed

rapid/plugin/group_replication/include/certifier.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -762,7 +762,7 @@ class Gtid_Executed_Message: public Plugin_gcs_message
762762
Implementation of the template methods of Gcs_plugin_message
763763
*/
764764
void encode_payload(std::vector<unsigned char>* buffer) const;
765-
void decode_payload(const unsigned char* buffer, uint64 length);
765+
void decode_payload(const unsigned char* buffer, const unsigned char* end);
766766

767767
private:
768768
std::vector<uchar> data;

rapid/plugin/group_replication/include/gcs_plugin_messages.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -245,9 +245,10 @@ class Plugin_gcs_message
245245
values according to the values decoded.
246246
247247
@param[in] buffer the buffer to decode from.
248-
@param[in] length the length of the buffer.
248+
@param[in] end the end of the buffer.
249249
*/
250-
virtual void decode_payload(const unsigned char* buffer, uint64 length)= 0;
250+
virtual void decode_payload(const unsigned char* buffer,
251+
const unsigned char* end)= 0;
251252

252253
/**
253254
Encodes the given payload item type and length into the buffer.

rapid/plugin/group_replication/include/member_info.h

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -97,8 +97,11 @@ class Group_member_info: public Plugin_gcs_message
9797
// length of the configuration flags: 4 bytes
9898
PIT_CONFIGURATION_FLAGS= 12,
9999

100+
// length of the conflict detection enabled: 1 byte
101+
PIT_CONFLICT_DETECTION_ENABLE= 13,
102+
100103
// No valid type codes can appear after this one.
101-
PIT_MAX= 13
104+
PIT_MAX= 14
102105
};
103106

104107
/*
@@ -314,9 +317,24 @@ class Group_member_info: public Plugin_gcs_message
314317
*/
315318
bool is_unreachable();
316319

320+
/**
321+
Update this member conflict detection to true
322+
*/
323+
void enable_conflict_detection();
324+
325+
/**
326+
Update this member conflict detection to false
327+
*/
328+
void disable_conflict_detection();
329+
330+
/**
331+
Return true if conflict detection is enable on this member
332+
*/
333+
bool is_conflict_detection_enabled();
334+
317335
protected:
318336
void encode_payload(std::vector<unsigned char>* buffer) const;
319-
void decode_payload(const unsigned char* buffer, uint64 length);
337+
void decode_payload(const unsigned char* buffer, const unsigned char* end);
320338

321339
private:
322340
std::string hostname;
@@ -332,6 +350,7 @@ class Group_member_info: public Plugin_gcs_message
332350
bool unreachable;
333351
Group_member_role role;
334352
uint32 configuration_flags;
353+
bool conflict_detection_enable;
335354
};
336355

337356

@@ -446,6 +465,13 @@ class Group_member_info_manager_interface
446465
*/
447466
virtual std::vector<Group_member_info*>* decode(const uchar* to_decode,
448467
uint64 length)= 0;
468+
469+
/*
470+
Check if some member of the group has the conflict detection enable
471+
472+
@return true if at least one member has conflict detection enabled
473+
*/
474+
virtual bool is_conflict_detection_enabled()= 0;
449475
};
450476

451477

@@ -492,6 +518,8 @@ class Group_member_info_manager: public Group_member_info_manager_interface
492518
std::vector<Group_member_info*>* decode(const uchar* to_decode,
493519
uint64 length);
494520

521+
bool is_conflict_detection_enabled();
522+
495523
private:
496524
void clear_members();
497525

@@ -580,7 +608,7 @@ class Group_member_info_manager_message: public Plugin_gcs_message
580608

581609
protected:
582610
void encode_payload(std::vector<unsigned char>* buffer) const;
583-
void decode_payload(const unsigned char* buffer, uint64 length);
611+
void decode_payload(const unsigned char* buffer, const unsigned char* end);
584612

585613
private:
586614
/**

rapid/plugin/group_replication/include/observer_trans.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -89,7 +89,7 @@ class Transaction_Message: public Plugin_gcs_message
8989
Implementation of the template methods
9090
*/
9191
void encode_payload(std::vector<unsigned char>* buffer) const;
92-
void decode_payload(const unsigned char* buffer, uint64 length);
92+
void decode_payload(const unsigned char* buffer, const unsigned char* length);
9393

9494
private:
9595
std::vector<uchar> data;

rapid/plugin/group_replication/include/pipeline_stats.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -151,9 +151,9 @@ class Pipeline_stats_member_message : public Plugin_gcs_message
151151
Message decoding method
152152
153153
@param[in] buffer the received data
154-
@param[in] length the received data size
154+
@param[in] end the end of the buffer
155155
*/
156-
void decode_payload(const unsigned char *buffer, uint64 length);
156+
void decode_payload(const unsigned char *buffer, const unsigned char* end);
157157

158158
private:
159159
int32 m_transactions_waiting_certification;

rapid/plugin/group_replication/include/recovery_message.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -99,9 +99,9 @@ class Recovery_message : public Plugin_gcs_message
9999
Message decoding method
100100
101101
@param[in] buffer the received data
102-
@param[in] length the received data size
102+
@param[in] end the end of the buffer
103103
*/
104-
void decode_payload(const unsigned char* buffer, uint64 length);
104+
void decode_payload(const unsigned char* buffer, const unsigned char* end);
105105

106106
private:
107107
/**The message type*/

rapid/plugin/group_replication/include/single_primary_message.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -89,9 +89,10 @@ class Single_primary_message : public Plugin_gcs_message
8989
Message decoding method
9090
9191
@param[in] buffer the received data
92-
@param[in] length the received data size
92+
@param[in] end the end of buffer
9393
*/
94-
void decode_payload(const unsigned char* buffer, uint64 length);
94+
void decode_payload(const unsigned char* buffer,
95+
const unsigned char* end);
9596

9697
private:
9798
/**The message type*/

rapid/plugin/group_replication/src/certifier.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -1666,6 +1666,7 @@ void Certifier::enable_conflict_detection()
16661666

16671667
mysql_mutex_lock(&LOCK_certification_info);
16681668
conflict_detection_enable= true;
1669+
local_member_info->enable_conflict_detection();
16691670
mysql_mutex_unlock(&LOCK_certification_info);
16701671

16711672
log_message(MY_INFORMATION_LEVEL,
@@ -1682,6 +1683,7 @@ void Certifier::disable_conflict_detection()
16821683

16831684
mysql_mutex_lock(&LOCK_certification_info);
16841685
conflict_detection_enable= false;
1686+
local_member_info->disable_conflict_detection();
16851687
mysql_mutex_unlock(&LOCK_certification_info);
16861688

16871689
log_message(MY_INFORMATION_LEVEL,
@@ -1733,7 +1735,8 @@ Gtid_Executed_Message::encode_payload(std::vector<unsigned char>* buffer) const
17331735
}
17341736

17351737
void
1736-
Gtid_Executed_Message::decode_payload(const unsigned char* buffer, uint64 length)
1738+
Gtid_Executed_Message::decode_payload(const unsigned char* buffer,
1739+
const unsigned char* length)
17371740
{
17381741
DBUG_ENTER("Gtid_Executed_Message::decode_payload");
17391742
const unsigned char *slider= buffer;

rapid/plugin/group_replication/src/gcs_event_handlers.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -84,7 +84,7 @@ Plugin_gcs_events_handler::on_message_received(const Gcs_message& message) const
8484
break;
8585

8686
default:
87-
DBUG_ASSERT(0); /* purecov: inspected */
87+
break; /* purecov: inspected */
8888
}
8989
}
9090

@@ -332,6 +332,15 @@ Plugin_gcs_events_handler::on_view_changed(const Gcs_view& new_view,
332332
//update the Group Manager with all the received states
333333
this->update_group_info_manager(new_view, exchanged_data, is_leaving);
334334

335+
//enable conflict detection if someone on group have it enabled
336+
if (local_member_info->in_primary_mode() &&
337+
group_member_mgr->is_conflict_detection_enabled())
338+
{
339+
Certifier_interface *certifier=
340+
this->applier_module->get_certification_handler()->get_certifier();
341+
certifier->enable_conflict_detection();
342+
}
343+
335344
//Inform any interested handler that the view changed
336345
View_change_pipeline_action *vc_action=
337346
new View_change_pipeline_action(is_leaving);

rapid/plugin/group_replication/src/gcs_plugin_messages.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -75,6 +75,7 @@ void Plugin_gcs_message::decode(const unsigned char* buffer,
7575
{
7676
DBUG_ENTER("Plugin_gcs_message::decode");
7777
const unsigned char *slider= buffer;
78+
const unsigned char *end= buffer + length;
7879

7980
m_version= uint4korr(slider);
8081
slider += WIRE_VERSION_SIZE;
@@ -92,7 +93,7 @@ void Plugin_gcs_message::decode(const unsigned char* buffer,
9293
s_cargo_type;
9394
slider += WIRE_CARGO_TYPE_SIZE;
9495

95-
decode_payload(slider, length);
96+
decode_payload(slider, end);
9697

9798
DBUG_VOID_RETURN;
9899
}

0 commit comments

Comments
 (0)