v6.5.0 的中心化分配自增 ID 的问题_1

窗口并发执行测试没有复现,最好提供一下脚本。

你这个代码放 MySQL 上跑什么表现,对比下

MySQL 中的自增 id 也不是根据插入的时间单调递增的,请问 tidb 中的自增id生成的插入顺序与什么有关?

没有复现,最好看看 mysql 上面表现是不是一样的

测试代码如下

#!/usr/bin/python2.7
#-*- coding=utf8 -*-

import threading
import pymysql
import datetime
from time import ctime,sleep,time

loops = [8,4]


dbconfig = {
      'host':'xxx', # vip 后面有 3 个 tidb 计算节点
      'port':4100,
      'user':'root',
      'password':'xxx',
      'db':'test',
      'charset':'utf8',
      'cursorclass':pymysql.cursors.DictCursor,
      }



def connTidb(sql, dbconf=dbconfig, fetchopt="all"):
    try:
        conn = pymysql.connect(**dbconf)
        cursor = conn.cursor(pymysql.cursors.DictCursor)
        conn.begin()

        cursor.execute(sql)
        if fetchopt == "all":
            res = cursor.fetchall()
        elif fetchopt == "one":
            res = cursor.fetchone()
        conn.commit()
        cursor.close()
        conn.close()
        return res
    except Exception, e:
        print e
        return e


def loop():

    sql = '''
    begin;insert into gyz.t1 (python_ts,tidb_ts,tso_ts) values ("{}",current_timestamp(6),@@tidb_current_ts);commit;'''.format(datetime.datetime.now())
    connTidb(sql)


def main():
    print 'strating at:',ctime()
    threads = []
    nloops = range(0,10)
    print nloops
    for i in nloops:
        t = threading.Thread(target=loop)
        threads.append(t)
    for i in nloops:
        threads[i].start()
    for i in nloops:
        threads[i].join()
    print 'all Done at:', ctime()

if __name__ == '__main__':
    main()

请问在 MySQL 上面测试过么 ?id 列数据是连续的么?

MySQL 和 TiDB 的表现是一样的,id 也会有不单调递增的情况

看下来应该是 python 的并发脚本有点儿问题,用 go 就没有这个问题

1 个赞

此话题已在最后回复的 60 天后被自动关闭。不再允许新回复。