engine.Insert can not autocommit #2

Closed
opened 2015-11-19 08:11:53 +00:00 by lunny · 9 comments
Owner

Author: @elvizlai

engine.Insert can not autocommit
//test case:

package main
import (
    _ "github.com/pingcap/tidb"
    _ "github.com/go-xorm/tidb"
    "github.com/go-xorm/xorm"
    "fmt"
)

type A struct {
    Id   int
    Name string
    Pv   int64 `xorm:"default 1"`
}

type B struct {
    Id   int
    Name string
    Pv   int `xorm:"default 1"`
}

func main() {
    engine, err := xorm.NewEngine("tidb", "goleveldb://test/tidb")
    if err != nil {
        panic(err)
    }
    //create table
    engine.Sync2(new(A))
    engine.Sync2(new(B))

    //query data
    fmt.Println("-------begin query------")
    //should be 0 if the first run---but every time you run the code, it still 1(it only autocommit when db created)
    fmt.Println(engine.Count(new(A)))
    fmt.Println(engine.Count(new(B)))
    //adding data

    fmt.Println("-------adding data------")
    a := &A{Name:"ElvizLai"}
    b := &B{Name:"ElvizLai"}

    engine.Insert(a)
    engine.Insert(b)

    return
    sess := engine.NewSession()
    sess.Begin()
    sess.InsertOne(a)
    sess.InsertOne(b)
    fmt.Println(sess.Commit())
}
Author: @elvizlai engine.Insert can not autocommit //test case: ``` package main import ( _ "github.com/pingcap/tidb" _ "github.com/go-xorm/tidb" "github.com/go-xorm/xorm" "fmt" ) type A struct { Id int Name string Pv int64 `xorm:"default 1"` } type B struct { Id int Name string Pv int `xorm:"default 1"` } func main() { engine, err := xorm.NewEngine("tidb", "goleveldb://test/tidb") if err != nil { panic(err) } //create table engine.Sync2(new(A)) engine.Sync2(new(B)) //query data fmt.Println("-------begin query------") //should be 0 if the first run---but every time you run the code, it still 1(it only autocommit when db created) fmt.Println(engine.Count(new(A))) fmt.Println(engine.Count(new(B))) //adding data fmt.Println("-------adding data------") a := &A{Name:"ElvizLai"} b := &B{Name:"ElvizLai"} engine.Insert(a) engine.Insert(b) return sess := engine.NewSession() sess.Begin() sess.InsertOne(a) sess.InsertOne(b) fmt.Println(sess.Commit()) } ```
Author
Owner

Author: @lunny

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.

Author: @lunny 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.
Author
Owner

Author: @elvizlai

@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.

Author: @elvizlai @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.
Author
Owner

Author: @lunny

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?

Author: @lunny 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?
Author
Owner

Author: @elvizlai

@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";]
Author: @elvizlai @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";] ```
Author
Owner

Author: @lunny

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

Author: @lunny So that maybe it's a driver's problem? @ngaut
Author
Owner

Author: @ngaut

Thanks @lunny
I will take a look.

Author: @ngaut Thanks @lunny I will take a look.
Author
Owner

Author: @ngaut

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

Author: @ngaut Fixed! Thanks @lunny @ElvizLai Please update tidb and try again
Author
Owner

Author: @lunny

I think maybe we can close this issue. @ElvizLai

Author: @lunny I think maybe we can close this issue. @ElvizLai
Author
Owner

Author: @elvizlai

Done

Author: @elvizlai Done
This repo is archived. You cannot comment on issues.
No Milestone
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/tidb#2
No description provided.