go-gorm / sharding

High performance table sharding plugin for Gorm.
MIT License
276 stars 60 forks source link

[WIP] fix: fixed ConnPool incorrect handling of transaction #42

Closed jiekun closed 2 years ago

jiekun commented 2 years ago

What did this pull request do?

Currently, sharding lib cannot start transaction correctly.

  1. When entering (pool *ConnPool) BeginTx() method, pool.ConnPool is actually *sql.DB and not match the gorm.ConnPoolBeginner interface. So pool, nil is returned and transaction is not started.
  2. BeginTx / Commit / Rollback return nil when interface not match. When executing write operation, transaction is automatically called: BeginTransaction. If no error returned, it will consider the transaction started by GORM and try to commit it in CommitOrRollbackTransaction.

In this PR, problems above are fixed by:

  1. Adding correct interface assertion for BeginTx so the BeginTx could be called.
  2. return gorm. ErrInvalidTransaction instead of nil, which could be handled in transaction.go

User Case Description

N/A

jiekun commented 2 years ago

@jinzhu @huacnlee PTAL.

In case I am not fixing this bug in the correct way, I would like to hear more from ya before finishing the PR. Tagged as [WIP] for now.

jiekun commented 2 years ago

43 #41 Should be fixed in this PR. We may need different struct to impl TxCommitter

jiekun commented 2 years ago

Hi. I'm closing this PR due to the lack of time to review and push it further. The issue is still present as described above.