Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: v6.5.0 的中心化分配自增 ID 的问题_1

The concurrent execution test for the window did not reproduce the issue. It would be best to provide the script.
Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: v6.5.0 的中心化分配自增 ID 的问题_1
The concurrent execution test for the window did not reproduce the issue. It would be best to provide the script.
How does this code perform when run on MySQL? Compare the results.
The auto-increment ID in MySQL is also not monotonically increasing based on the insertion time. What is the insertion order of the auto-increment ID generated in TiDB related to?
Unable to reproduce, it’s best to check if the behavior is the same on MySQL.
The test code is as follows:
#!/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 followed by 3 TiDB compute nodes
'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 as 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('starting 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()
Have you tested it on MySQL? Is the data in the id column continuous?
The performance of MySQL and TiDB is the same, and the id may also have non-monotonic increments.
It seems that there might be an issue with the concurrency script in Python. This problem does not occur when using Go.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.