octillery v1.1.0 Release Notes

Release Date: 2018-12-11 // over 5 years ago
  • ๐Ÿ‘Œ Supports Distributed Transaction

    How To Use

    Set before/after callback for commit

    octillery.BeforeCommitCallback(func(tx \*sql.Tx, writeQueries []\*sql.QueryLog) error { // write all writeQueries to log (WAL) in application sidereturn nil})) octillery.AfterCommitCallback(func(tx \*sql.Tx) error {}, func(tx \*sql.Tx, isCriticalError bool, failureWriteQueries []\*sql.QueryLog) error { if isCriticalError { // distributed transaction error// record failureWriteQueries and should execute after. } }))
    

    Also, callback function can set at *sql.Tx scope too.

    tx, \_ := db.Begin() tx.BeforeCommitCallback(func(writeQueries []\*sql.QueryLog) error { // write all writeQueries to log (WAL) in application sidereturn nil})) tx.AfterCommitCallback(func() error {}, func(isCriticalError bool, failureWriteQueries []\*sql.QueryLog) error { if isCriticalError { // distributed transaction error// record failureWriteQueries and should execute after. } }))
    

    Exec for multiple databases

    You can use *sql.Tx to multiple databases.

    (tableA and tableB are stored other databases)

    tx, \_ := db.Begin() tx.Exec("insert into tableA ...") // (1)tx.Exec("insert into tableB ...") // (2)// tx.Commit() commit (1) before it commit (2)// if (1) and (2) are success too, call AfterCommitSuccessCallback// if (1) and (2) are failure too, call AfterCommitFailureCallback with NOT CriticalError// if (1) is failure, instantly call AfterCommitFailureCallback with NOT CriticalError// if (1) is OK but (2) is failure, call AfterCommitFailureCallback with CriticalErrorif err := tx.Commit(); err != nil { ... }
    

    ๐Ÿš‘ Recover from CriticalError

    writeQueryLogs := queryLogsfromWAL()tx, \_ := db.Begin()for \_, writeQueryLog := range writeQueryLogs { isCommittedQuery, err := tx.IsAlreadyCommittedQueryLog(writeQueryLog) if err != nil { .... } if !isCommittedQuery { result, err := tx.ExecWithQueryLog(writeQueryLog) .... } }
    

    ๐Ÿ‘ If disable distributed transaction support

    set distributed_transaction: false in databases.yml