feat(txn): add public method for getting the value of discarded field (#1788)

This commit is contained in:
Mateusz Czubak
2022-06-10 14:55:50 -07:00
committed by GitHub
parent c513059d9e
commit aedbca4ee8
2 changed files with 17 additions and 0 deletions
+5
View File
@@ -760,6 +760,11 @@ func (txn *Txn) ReadTs() uint64 {
return txn.readTs
}
// Discarded returns the discarded value of the transaction.
func (txn *Txn) Discarded() bool {
return txn.discarded
}
// NewTransaction creates a new transaction. Badger supports concurrent execution of transactions,
// providing serializable snapshot isolation, avoiding write skews. Badger achieves this by tracking
// the keys read and at Commit time, ensuring that these read keys weren't concurrently modified by
+12
View File
@@ -952,3 +952,15 @@ func TestConflict(t *testing.T) {
runTest(t, testAndSetItr)
})
}
func TestTxnGetters(t *testing.T) {
t.Run("TxnDiscarded", func(t *testing.T) {
runBadgerTest(t, nil, func(t *testing.T, db *DB) {
txn := db.NewTransaction(true)
require.Equal(t, false, txn.Discarded())
txn.Discard()
require.Equal(t, true, txn.Discarded())
})
})
}