MySQL源码学习-GTID

GTID的组成

gtid一般又server_uuid+gno组成

1.server_uuid重要的函数

/*
函数位置:mysqld.cc
*/
init_server_auto_options() //mysql启动的时候会调用该函数读取auto.cnf文件获取server_uuid
generate_server_uuid() //如果auto.cnf文件不存在,则会调用该函数生成一个新的server_uuid

1.1generate_server_uuid()函数部分代码理解

/*
这部分代码是server_uuid的主要初始化过程,该函数首先会分配一个临时的变量thd,来进行过程中的计算
为了保证在新启动mysqld时uuid的不重复,我们可以看到uuid和以下三个方面有关
1.数据库的启动时间
2.轻量级现成的id
3.随机内存地址
*/
sql_print_information("Salting uuid generator variables, current_pid: %lu, "
                        "server_start_time: %lu, bytes_sent: %llu, ",
                        current_pid,
                        (ulong)server_start_time, thd->status_var.bytes_sent);

  const time_t save_server_start_time= server_start_time;
  server_start_time+= ((ulonglong)current_pid << 48) + current_pid;
  thd->status_var.bytes_sent= (ulonglong)thd;

  lex_start(thd);
  func_uuid= new (thd->mem_root) Item_func_uuid();
  func_uuid->fixed= 1;
  func_uuid->val_str(&uuid);

  sql_print_information("Generated uuid: '%s', "
                        "server_start_time: %lu, bytes_sent: %llu",
                        uuid.c_ptr(),
                        (ulong)server_start_time, thd->status_var.bytes_sent);
  // Restore global variables used for salting
  server_start_time = save_server_start_time;

2.gno相关的函数

/*
函数位置:rpl_gtid_state.cc
*/
rpl_gno Gtid_state::get_automatic_gno()//gno生成以及gtid的生成
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

渔不是鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值