mgr参数之-group_replication_gtid_assignment_block_size小结

一、官方文档解释:
This system variable is a group-wide configuration setting,and a full reboot of the replication group is required for a  change to take effect
group_replication_gtid_assignment_block_size specifies the number of consecutive GTIDs that are reserved for each group member. Each member consumes its own blocks and reserves more when needed.
This system variable is a group-wide configuration setting. It must have the same value on all group members, cannot be changed while Group Replication is running, and requires a full reboot of the group (a bootstrap by a server with group_replication_bootstrap_group=ON) in order for the value change to take effect. For instructions to safely bootstrap a group where transactions have been executed and certified, see Section 18.5.2, “Restarting a Group”.
If the group has a value set for this system variable, and a joining member has a different value set for the system variable, the joining member cannot join the group until the value is changed to match. If the group members have a value set for this system variable, and the joining member does not support the system variable, it cannot join the group.
此系统变量是组范围的配置设置,需要完全重新启动复制组才能使更改生效
group_replication_gtid_assignment_block_size指定为每个组成员保留的连续gtid的数量。每个成员消耗自己的区块,并在需要时保留更多。
此系统变量是组范围内的配置设置。它在所有组成员上都必须具有相同的值,在组复制运行时不能更改,并且需要完全重新启动组(由group_Replication_bootstrap_group=on的服务器引导)才能使值更改生效。有关安全引导已执行和认证事务的组的说明,请参阅第18.5.2节“重新启动组”。
如果组为此系统变量设置了值,而加入成员为系统变量设置的值不同,则在值更改为匹配之前,加入成员无法加入组。如果组成员为此系统变量设置了值,而加入成员不支持该系统变量,则无法加入组。
全局变量,动态变量,整型类型,默认值为1000000,取值范围:32位平台为1~4294967295,64位平台为1~9223372036854775807,MySQL 5.7.17版本引入
二、个人理解:
1、关于GTID分配机制:
普通主从复制,GTID分配是 server_uuid:id(number)
MGR GTID分配与普通主从复制不同,每个mgr组统一分配  group_replication_group_name(uuid):id(number),但是gtid后面的id号是取自执行节点预留的值,也就是group_replication_gtid_assignment_block_size参数设置的保留的个数!有点类似于tidb自增生成器,每个tidb server预留一部分!
2、group_replication_gtid_assignment_block_size参数:
group_replication_gtid_assignment_block_size为每个成员保留的连续GTID数。每个成员从中进行消耗,并在其需要的时候获取更多的GTID数(类似于分布式事务中的全局序列,该系统变量设置的值表示每个成员每一次从全局序列中获取多大范围的连续数字范围来作为自身写事务的GTID号)
MGR会为每个实例节点分配一段连续的GTID值,所以当mgr发生主从切换的时候,可能导致集群gtid_executed事务ID不连续;
举个例子,集群中有2个节点,group_replication_gtid_assignment_block_size为1000,那么为节点A分配的Gtid_set为group_name:1-1000,节点B分配的Gtid_set为group_name:1001-2000。
则group_name:1-1000和group_name:1001-2000分别作为Gtid_set保存在member_gtids上。A节点的事务T1认证通过后,分配gtid为group_name:1,接着A节点事务T2分配group_name:2,然后B节点事务进入认证模块,认证通过后,为其分配group_name:1001,每分配一次gtid则gtids_assigned_in_blocks_counter增一。当发生主从切换时候,节点B会从1001开始记录gtid,所以会造成MGR的gtid_executed有时是不连续的多段,如aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1-2:1001-1005
若分配次数gtids_assigned_in_blocks_counter已达到gtid_assignment_block_size,则需要compute_group_available_gtid_intervals()重新计算。基于member_uuid找到该成员可用的gtid区间,若还没为该成员分配gtid,则调用reserve_gtid_block()进行分配。需要注意的是,reserve_gtid_block()是最多分配而不是一定分配block_size大小的gtid序列,是否等于block_size依赖于group_available_gtid_intervals的第一个可用的连续gtid序列大小是否等于或大于block_size
三、该参数设置建议:保持默认即可
对于多主架构减少校验的复杂度:
为每个成员保留的连续的gtid的数量。每个成员消耗其块,并在需要时储备更多。
事务在节点执行完成,commit前发送到GR做校验。校验成功后,GR会给此事务分配一个GTID(如果该事务没有GTID)。GR会给每个节点预留一个范围的GTID,(GTID是由server_uuid+数字组成,gr中GTID中的UUID部分都是一样的,数字部分则为各节点分配一个范围段,用完了再分配一个新的范围段)。这个范围段的大小就是有group_replication_gtid_assignment_block_size变量控制,默认是1000000。这个数字范围如果很大的话,gtid_executed就不能及时合并,许多GTID interval 会使校验算法变得复杂


请使用浏览器的分享功能分享到微信等