Giter VIP home page Giter VIP logo

Comments (9)

lunny avatar lunny commented on August 23, 2024

Hi, I have copied the code and run in my macbook.

-------begin query------
0 <nil>
0 <nil>
-------adding data------

I think there is no error occupied this time.

from tidb.

elvizlai avatar elvizlai commented on August 23, 2024

@lunny every time the code runs, it inserted "a" and "b" to database. But it only succeed for the first run. From TiDB log, it show's the second time run missing autocommit
So I tried using session commit instead. It works.

from tidb.

lunny avatar lunny commented on August 23, 2024

I open the tidb's log. It seems it's ok.

2015/11/20 09:17:49 kv.go:80: [info] New store test/tidb
2015/11/20 09:17:49 kv.go:115: [debug] Begin txn:1
2015/11/20 09:17:49 txn.go:138: [debug] seek mDB: txn:1
2015/11/20 09:17:49 txn.go:213: [info] commit txn 1
2015/11/20 09:17:49 tidb.go:88: [debug] compiling use tidb
2015/11/20 09:17:49 tidb.go:101: [debug] compiling prepared SELECT `TABLE_NAME`, `ENGINE`, `TABLE_ROWS`, `AUTO_INCREMENT` from `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? AND (`ENGINE`='MyISAM' OR `ENGINE` = 'InnoDB')
2015/11/20 09:17:49 select.go:209: [info] SelectStmt trx:
[xorm] [info]  2015/11/20 09:17:49.881813 [sql] SELECT `TABLE_NAME`, `ENGINE`, `TABLE_ROWS`, `AUTO_INCREMENT` from `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? AND (`ENGINE`='MyISAM' OR `ENGINE` = 'InnoDB') [tidb]
2015/11/20 09:17:49 tidb.go:101: [debug] compiling prepared SELECT `COLUMN_NAME`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `COLUMN_TYPE`, `COLUMN_KEY`, `EXTRA` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?
2015/11/20 09:17:49 select.go:209: [info] SelectStmt trx:
[xorm] [info]  2015/11/20 09:17:49.883490 [sql] SELECT `COLUMN_NAME`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `COLUMN_TYPE`, `COLUMN_KEY`, `EXTRA` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ? [tidb a]
2015/11/20 09:17:49 tidb.go:101: [debug] compiling prepared SELECT `INDEX_NAME`, `NON_UNIQUE`, `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`STATISTICS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?
2015/11/20 09:17:49 select.go:209: [info] SelectStmt trx:
[xorm] [info]  2015/11/20 09:17:49.883976 [sql] SELECT `INDEX_NAME`, `NON_UNIQUE`, `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`STATISTICS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ? [tidb a]
2015/11/20 09:17:49 select.go:209: [info] SelectStmt trx:
[xorm] [info]  2015/11/20 09:17:49.884139 [sql] SELECT `COLUMN_NAME`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `COLUMN_TYPE`, `COLUMN_KEY`, `EXTRA` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ? [tidb b]
2015/11/20 09:17:49 select.go:209: [info] SelectStmt trx:
[xorm] [info]  2015/11/20 09:17:49.884405 [sql] SELECT `INDEX_NAME`, `NON_UNIQUE`, `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`STATISTICS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ? [tidb b]
2015/11/20 09:17:49 select.go:209: [info] SelectStmt trx:
[xorm] [info]  2015/11/20 09:17:49.884669 [sql] SELECT `TABLE_NAME`, `ENGINE`, `TABLE_ROWS`, `AUTO_INCREMENT` from `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? AND (`ENGINE`='MyISAM' OR `ENGINE` = 'InnoDB') [tidb]
2015/11/20 09:17:49 select.go:209: [info] SelectStmt trx:
[xorm] [info]  2015/11/20 09:17:49.884912 [sql] SELECT `COLUMN_NAME`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `COLUMN_TYPE`, `COLUMN_KEY`, `EXTRA` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ? [tidb a]
2015/11/20 09:17:49 select.go:209: [info] SelectStmt trx:
[xorm] [info]  2015/11/20 09:17:49.885152 [sql] SELECT `INDEX_NAME`, `NON_UNIQUE`, `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`STATISTICS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ? [tidb a]
2015/11/20 09:17:49 select.go:209: [info] SelectStmt trx:
[xorm] [info]  2015/11/20 09:17:49.885315 [sql] SELECT `COLUMN_NAME`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `COLUMN_TYPE`, `COLUMN_KEY`, `EXTRA` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ? [tidb b]
2015/11/20 09:17:49 select.go:209: [info] SelectStmt trx:
[xorm] [info]  2015/11/20 09:17:49.885625 [sql] SELECT `INDEX_NAME`, `NON_UNIQUE`, `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`STATISTICS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ? [tidb b]
-------begin query------
2015/11/20 09:17:49 tidb.go:101: [debug] compiling prepared SELECT count(*) FROM `a`
2015/11/20 09:17:49 select.go:209: [info] SelectStmt trx:
2015/11/20 09:17:49 kv.go:115: [debug] Begin txn:2
2015/11/20 09:17:49 session.go:319: [warning] New txn:2 in session:1
2015/11/20 09:17:49 txn.go:138: [debug] seek 5_rsd txn:2
2015/11/20 09:17:49 txn.go:108: [debug] get key:5_rsdd, txn:2
2015/11/20 09:17:49 txn.go:108: [debug] get key:5_rsdd, txn:2
2015/11/20 09:17:49 txn.go:108: [debug] get key:5_rsdd, txn:2
2015/11/20 09:17:49 txn.go:213: [info] commit txn 2
1 <nil>
2015/11/20 09:17:49 tidb.go:101: [debug] compiling prepared SELECT count(*) FROM `b`
2015/11/20 09:17:49 select.go:209: [info] SelectStmt trx:
2015/11/20 09:17:49 kv.go:115: [debug] Begin txn:3
2015/11/20 09:17:49 session.go:319: [warning] New txn:3 in session:1
2015/11/20 09:17:49 txn.go:138: [debug] seek 9_rsd txn:3
2015/11/20 09:17:49 txn.go:108: [debug] get key:9_rsdd, txn:3
2015/11/20 09:17:49 txn.go:108: [debug] get key:9_rsdd, txn:3
2015/11/20 09:17:49 txn.go:108: [debug] get key:9_sdd, txn:3
2015/11/20 09:17:49 txn.go:213: [info] commit txn 3
1 <nil>
-------adding data------
2015/11/20 09:17:49 tidb.go:101: [debug] compiling prepared INSERT INTO `a` (`id`, `name`, `pv`) VALUES (?, ?, ?)
2015/11/20 09:17:49 kv.go:115: [debug] Begin txn:4
2015/11/20 09:17:49 txn.go:69: [debug] Inc mTable::5_autoID, step 1000 txn:4
2015/11/20 09:17:49 txn.go:213: [info] commit txn 4
2015/11/20 09:17:49 autoid.go:70: [info] Alloc id 1001, table ID:5, from 0xc820666cc0, store ID:98d9a00b-2120-46b2-a037-41045c4efd7d
2015/11/20 09:17:49 kv.go:115: [debug] Begin txn:5
2015/11/20 09:17:49 session.go:319: [warning] New txn:5 in session:1
2015/11/20 09:17:49 txn.go:132: [debug] set key:5_r�sd, txn:5
2015/11/20 09:17:49 txn.go:132: [debug] set key:5_r�sdd, txn:5
2015/11/20 09:17:49 txn.go:132: [debug] set key:5_r�sdd, txn:5
2015/11/20 09:17:49 txn.go:132: [debug] set key:5_r�sdd, txn:5
2015/11/20 09:17:49 txn.go:213: [info] commit txn 5
2015/11/20 09:17:49 tidb.go:101: [debug] compiling prepared INSERT INTO `b` (`id`, `name`, `pv`) VALUES (?, ?, ?)
2015/11/20 09:17:49 kv.go:115: [debug] Begin txn:6
2015/11/20 09:17:49 txn.go:69: [debug] Inc mTable::9_autoID, step 1000 txn:6
2015/11/20 09:17:49 txn.go:213: [info] commit txn 6
2015/11/20 09:17:49 autoid.go:70: [info] Alloc id 1001, table ID:9, from 0xc820666cf0, store ID:98d9a00b-2120-46b2-a037-41045c4efd7d
2015/11/20 09:17:49 kv.go:115: [debug] Begin txn:7
2015/11/20 09:17:49 session.go:319: [warning] New txn:7 in session:1
2015/11/20 09:17:49 txn.go:132: [debug] set key:9_r�sd, txn:7
2015/11/20 09:17:49 txn.go:132: [debug] set key:9_r�sdd, txn:7
2015/11/20 09:17:49 txn.go:132: [debug] set key:9_r�sdd, txn:7
2015/11/20 09:17:49 txn.go:132: [debug] set key:9_rsdd, txn:7
2015/11/20 09:17:49 txn.go:213: [info] commit txn 7

And @ngaut, What's the Engine column's value on INFORMATION_SCHEMA.TABLES, 'MyISAM' OR 'InnoDB' or others?

from tidb.

elvizlai avatar elvizlai commented on August 23, 2024

@lunny
check your log, they are not autocommit, it just insert to memory,but not commit to storage.

here is my log file when the first time run that code.

2015/11/20 10:15:14 tidb.go:148: [debug] compiling prepared INSERT INTO `b` (`id`, `name`, `pv`) VALUES (?, ?, ?) 
2015/11/20 10:15:14 kv.go:162: [debug] Begin txn:379580767087624194
2015/11/20 10:15:14 txn.go:109: [debug] get key:"\x00mDBs\x00\x01\x11hmDB:60\x00\x01", txn:379580767087624194
2015/11/20 10:15:14 txn.go:109: [debug] get key:"\x00mDB:60\x00\x01\x11hmTable:68\x00\x01", txn:379580767087624194
2015/11/20 10:15:14 txn.go:109: [debug] get key:"\x00mDB:60\x00\x01\x11hmTID:68\x00\x01", txn:379580767087624194
2015/11/20 10:15:14 txn.go:146: [debug] set key:"\x00mDB:60\x00\x01\x11hmTID:68\x00\x01", txn:379580767087624194
2015/11/20 10:15:14 txn.go:109: [debug] get key:"\x00mDB:60\x00\x01\x11H", txn:379580767087624194
2015/11/20 10:15:14 txn.go:146: [debug] set key:"\x00mDB:60\x00\x01\x11H", txn:379580767087624194
2015/11/20 10:15:14 txn.go:244: [info] commit txn 379580767087624194
2015/11/20 10:15:14 autoid.go:71: [info] Alloc id 1, table ID:68, from 0xc820209a40, database ID:60
2015/11/20 10:15:14 kv.go:162: [debug] Begin txn:379580767087886336
2015/11/20 10:15:14 tidb.go:125: [debug] compiling SELECT VARIABLE_VALUE FROM mysql.GLOBAL_VARIABLES WHERE VARIABLE_NAME="autocommit"; 
2015/11/20 10:15:14 session.go:267: [debug] Executing SELECT VARIABLE_VALUE FROM mysql.GLOBAL_VARIABLES WHERE VARIABLE_NAME="autocommit"; [SELECT VARIABLE_VALUE FROM mysql.GLOBAL_VARIABLES WHERE VARIABLE_NAME="autocommit";]

here is my log file for the second time run.

2015/11/20 10:19:17 tidb.go:148: [debug] compiling prepared INSERT INTO `b` (`id`, `name`, `pv`) VALUES (?, ?, ?) 
2015/11/20 10:19:17 kv.go:162: [debug] Begin txn:379580830857822209
2015/11/20 10:19:17 txn.go:109: [debug] get key:"\x00mDBs\x00\x01\x11hmDB:60\x00\x01", txn:379580830857822209
2015/11/20 10:19:17 txn.go:109: [debug] get key:"\x00mDB:60\x00\x01\x11hmTable:68\x00\x01", txn:379580830857822209
2015/11/20 10:19:17 txn.go:109: [debug] get key:"\x00mDB:60\x00\x01\x11hmTID:68\x00\x01", txn:379580830857822209
2015/11/20 10:19:17 txn.go:146: [debug] set key:"\x00mDB:60\x00\x01\x11hmTID:68\x00\x01", txn:379580830857822209
2015/11/20 10:19:17 txn.go:109: [debug] get key:"\x00mDB:60\x00\x01\x11H", txn:379580830857822209
2015/11/20 10:19:17 txn.go:244: [info] commit txn 379580830857822209
2015/11/20 10:19:17 autoid.go:71: [info] Alloc id 1001, table ID:68, from 0xc8206b4450, database ID:60
2015/11/20 10:19:17 txn.go:146: [debug] set key:"68_r\x00\x01\x12\x03\xe9\x00\x00sd", txn:379580830855725056
2015/11/20 10:19:17 txn.go:146: [debug] set key:"68_r\x00\x01\x12\x03\xe9\x11A\x00\x00sdd", txn:379580830855725056
2015/11/20 10:19:17 txn.go:146: [debug] set key:"68_r\x00\x01\x12\x03\xe9\x11B\x00\x00sdd", txn:379580830855725056
2015/11/20 10:19:17 txn.go:146: [debug] set key:"68_r\x00\x01\x12\x03\xe9\x11C\x00\x00sdd", txn:379580830855725056

It looks like that the autocommit are missing. I thought maybe adding time.Sleep() at the end of the code to wait for autocommit, but that does not work.

So I tried using session to commit(this works):

    sess := engine.NewSession()
    sess.Begin()
    sess.InsertOne(a)
    sess.InsertOne(b)
    fmt.Println(sess.Commit())

and the log:

2015/11/20 10:22:32 tidb.go:125: [debug] compiling BEGIN; 
2015/11/20 10:22:32 txn.go:244: [info] commit txn 379580881881006081
2015/11/20 10:22:32 kv.go:162: [debug] Begin txn:379580881882841092
2015/11/20 10:22:32 tidb.go:125: [debug] compiling SELECT VARIABLE_VALUE FROM mysql.GLOBAL_VARIABLES WHERE VARIABLE_NAME="autocommit"; 
2015/11/20 10:22:32 session.go:267: [debug] Executing SELECT VARIABLE_VALUE FROM mysql.GLOBAL_VARIABLES WHERE VARIABLE_NAME="autocommit"; [SELECT VARIABLE_VALUE FROM mysql.GLOBAL_VARIABLES WHERE VARIABLE_NAME="autocommit";]
2015/11/20 10:22:32 select.go:254: [info] Exec : SELECT VARIABLE_VALUE FROM mysql.GLOBAL_VARIABLES WHERE VARIABLE_NAME="autocommit"; 
2015/11/20 10:22:32 txn.go:109: [debug] get key:"52_i_primary\x00\x01autocommit\x00\x01\x00\x00s", txn:379580881882841092
2015/11/20 10:22:32 txn.go:109: [debug] get key:"52_r\x00\x01\x11\x94\x112\x00\x00sdd", txn:379580881882841092
2015/11/20 10:22:32 txn.go:109: [debug] get key:"52_r\x00\x01\x11\x94\x113\x00\x00sdd", txn:379580881882841092
2015/11/20 10:22:32 session.go:516: [warning] Force new txn:379580881882841092 in session:1
2015/11/20 10:22:32 tidb.go:148: [debug] compiling prepared INSERT INTO `a` (`id`, `name`, `pv`) VALUES (?, ?, ?) 
2015/11/20 10:22:32 autoid.go:71: [info] Alloc id 3002, table ID:64, from 0xc82024d560, database ID:60
2015/11/20 10:22:32 txn.go:146: [debug] set key:"64_r\x00\x01\x12\v\xba\x00\x00sd", txn:379580881882841092
2015/11/20 10:22:32 txn.go:146: [debug] set key:"64_r\x00\x01\x12\v\xba\x11=\x00\x00sdd", txn:379580881882841092
2015/11/20 10:22:32 txn.go:146: [debug] set key:"64_r\x00\x01\x12\v\xba\x11>\x00\x00sdd", txn:379580881882841092
2015/11/20 10:22:32 txn.go:146: [debug] set key:"64_r\x00\x01\x12\v\xba\x11?\x00\x00sdd", txn:379580881882841092
2015/11/20 10:22:32 tidb.go:148: [debug] compiling prepared INSERT INTO `b` (`id`, `name`, `pv`) VALUES (?, ?, ?) 
2015/11/20 10:22:32 autoid.go:71: [info] Alloc id 3002, table ID:68, from 0xc82024d590, database ID:60
2015/11/20 10:22:32 txn.go:146: [debug] set key:"68_r\x00\x01\x12\v\xba\x00\x00sd", txn:379580881882841092
2015/11/20 10:22:32 txn.go:146: [debug] set key:"68_r\x00\x01\x12\v\xba\x11A\x00\x00sdd", txn:379580881882841092
2015/11/20 10:22:32 txn.go:146: [debug] set key:"68_r\x00\x01\x12\v\xba\x11B\x00\x00sdd", txn:379580881882841092
2015/11/20 10:22:32 txn.go:146: [debug] set key:"68_r\x00\x01\x12\v\xba\x11C\x00\x00sdd", txn:379580881882841092
2015/11/20 10:22:32 tidb.go:125: [debug] compiling COMMIT; 
2015/11/20 10:22:32 txn.go:244: [info] commit txn 379580881882841092
2015/11/20 10:22:32 tidb.go:125: [debug] compiling SELECT VARIABLE_VALUE FROM mysql.GLOBAL_VARIABLES WHERE VARIABLE_NAME="autocommit"; 
2015/11/20 10:22:32 session.go:267: [debug] Executing SELECT VARIABLE_VALUE FROM mysql.GLOBAL_VARIABLES WHERE VARIABLE_NAME="autocommit"; [SELECT VARIABLE_VALUE FROM mysql.GLOBAL_VARIABLES WHERE VARIABLE_NAME="autocommit";]

from tidb.

lunny avatar lunny commented on August 23, 2024

So that maybe it's a driver's problem? @ngaut

from tidb.

ngaut avatar ngaut commented on August 23, 2024

Thanks @lunny
I will take a look.

from tidb.

ngaut avatar ngaut commented on August 23, 2024

Fixed! Thanks @lunny @elvizlai
Please update tidb and try again

from tidb.

lunny avatar lunny commented on August 23, 2024

I think maybe we can close this issue. @elvizlai

from tidb.

elvizlai avatar elvizlai commented on August 23, 2024

Done

from tidb.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.