Assuming a MariaDB compatible database (AWS Aurora RDS) with default settings, which includes autocommit enabled, if a Lambda function was terminated after three seconds doing a transaction that takes more than five seconds, e.g.
tx, err := h.db.Begin()
if err != nil {
log.WithError(err).Error("failed to start transaction")
}
res, execErr := tx.Exec(fmt.Sprintf("UPDATE testtable SET val = %d WHERE id = 1; SELECT SLEEP(5.5);", time.Now().Unix()))
if execErr != nil {
log.WithError(err).Error("rolling back")
err = tx.Rollback()
if err != nil {
log.WithError(err).Error("failed to roll back")
}
}
if err := tx.Commit(); err != nil {
log.WithError(err).Error("failed to commit")
}
What would one assume the result to be? The transaction would have not been committed?
I am using Go MySQL Driver v1.3.0-84-g6be42e0 btw. I also made a video showing my results, but I am wondering if it is right since I don't understand how the driver could have executed rollback.