mysql gtid寻找位置_【MySQL】UUID与GTID以及如何根据GTID找寻filename和position

Open Group于1997年10月发布,UUID遵从此协议。

UUID被设计成一个在空间和时间上的唯一值。两次调用的UUID将产生两个不同的值,即使这些调用是在两个不连接的,彼此独立的计算机。

由一串数字表示

aaaaaaaa-bbbb-cccc

-

dddd

-

eeeeeeeeeeee

format:

mysql> SELECT UUID(); -> '6ccd780c-baba-1026-9564-0040f4311e29'

虽然UUID()值是唯一的,但它们不一定是不可猜测的或不可预测的。如果需要不可预测性,UUID值应该以其他方式生成。

UUID

不基于statement replication.

The

first three numbers

are generated from a timestamp.

The

fourth number

preserves temporal uniqueness in case the timestamp value loses monotonicity (for example, due to daylight saving time).

由于夏令时导致的

The

fifth number

is an IEEE 802 node number that provides spatial uniqueness. A random number is substituted if the latter is not available (for example, because the host computer has no Ethernet card, or we do not know how to find the hardware address of an interface on your operating system). In this case, spatial uniqueness cannot be guaranteed. Nevertheless, a collision should have

very

low probability.

第五个数字是,它提供空间唯一一个IEEE802节点号。

The MAC address of an interface is taken into account only on FreeBSD and Linux. On other operating systems, MySQL uses a randomly generated 48-bit number.

uuid我在百度百科上也看到了... ...

ff2c541d521845cae3735cb16f4f3d79.png

1 2 3

段是与时间有关的。

time_low

time_mid

time_high_and_version

转成

16

进制后分别对应第

1 2 3

段。这个时间是从

1582-10-15 00:00:00.00

到当前时间的

100ns

值。(实际上系统只能取到精确

us

,再乘以

10

)。所以你短时间连续执行的话,比较可能只有第一个值在改,实际上

1 2 3

都可能会改变。

4

段是你启动这个

MySQL

后第一次执行

select uuid()

时的随机数,每次重启会改变。

5

段是

mac

值转过来的,同一个机器多实例的一般相同。如果

mac

值获取不到,则是一个随机值。

所以这个值可以认为是每次执行都不相同。并且不同实例之间也只有极微小概率重复。

Returns a

short

universal identifier as a 64-bit unsigned integer (rather than a string-form 128-bit identifier as returned by the

UUID()

function).

The value of

UUID_SHORT()

is guaranteed to be unique if the following conditions hold:

The

UUID_SHORT()

return value is constructed this way:

(server_id & 255) <

+ (server_startup_time_in_seconds <

+ incremented_variable++;

mysql> SELECT UUID_SHORT(); -> 92395783831158784

Note that

UUID_SHORT()

does not work with statement-based replication.

The

server_id

of the current host is unique among your set of master and slave servers

server_id

is between 0 and 255

You do not set back your system time for your server between

mysqld

restarts

uuid

返回固定长度字符串不同,

uuid_short

的返回值是一个

unsigned long long

类型。

MySQL

启动后第一次执行的值是通过

server_id << 56 + server_start_time << 24

来初始化。

server_start_time

单位是秒。

之后每次执行都加

1

由于每次加

1

都会加全局

mutex

锁,因此多线程安全,可以当作

sequence

来用,只是初始值有点大。

You do not invoke

UUID_SHORT()

on average more than 16 million times per second between

mysqld

restarts

In an

INSERT ... ON DUPLICATE KEY UPDATE

statement, you can use the VALUES(

col_name

) function in the

UPDATE

clause to refer to column values from the

INSERT

portion of the statement. In other words, VALUES(

col_name

) in the

UPDATE

clause refers to the value of

col_name

that would be inserted, had no duplicate-key conflict occurred. This function is especially useful in multiple-row inserts. The

VALUES()

function is meaningful only in the ON DUPLICATE KEY UPDATE clause of

INSERT

statements and returns NULL otherwise. See

Section 13.2.5.3, “INSERT ... ON DUPLICATE KEY UPDATE Syntax”

.

mysql> INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6) -> ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);

c6e846b20b836ac84aa5eeac0b944996.png

当开启gitd时,binlog中会多出gtid event,扫描binlog就会知道GTID对应的filename和position,主从日志落后很多,就会扫描很多binlog日志。

f495f1a4d8ce314b614b8ba1c3727b15.png

Previous_gtids表示这之前的binlog运行到的GTID的位置。GTID比当前值到就去扫这个binlog,比这个小就去扫描之前的binlog日志。

c6a3e8a2ef472936ee5772738f6a9c71.png

说到切换,有的时候主库恢复后,可能从库还没有应用完,虽然我们事先准备好了切换脚本,但是到这时候我们还是很犹豫的,经历过后会深有感触。金融行业不允许切半同步,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值