diff --git a/README.md b/README.md index 183e5f3..bdd9769 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,11 @@ In this project we try to implement `Serializable Snapshot Isolation` from Badge - [MatrixOrigin](https://github.com/arjunsk/matrixone/blob/c80e5add3048e656aac805ae6849d724cb0309dd/pkg/txn/client/types.go#L173) - [Serializable Snapshot Isolation Paper](https://github.com/db-modules/awesome-dbdev/blob/master/papers/serializable-snapshot-isolation.pdf) - [Write Snapshot Isolation Paper](https://github.com/dbminions/awesome-dbdev/blob/master/papers/write-snapshot-isolation.pdf) -- [SurrealKV](https://github.com/surrealdb/surrealkv/pull/5/files) \ No newline at end of file +- [SurrealKV](https://github.com/surrealdb/surrealkv/pull/5/files) + + +### Flow + +Reference: [Sarthak Makhija's Blog](https://tech-lessons.in/en/blog/serializable_snapshot_isolation/) + +![img.png](img.png) \ No newline at end of file diff --git a/img.png b/img.png new file mode 100644 index 0000000..a50b5f2 Binary files /dev/null and b/img.png differ diff --git a/pkg/txn/b_txn.go b/pkg/txn/b_txn.go index 79885da..b3d82b7 100644 --- a/pkg/txn/b_txn.go +++ b/pkg/txn/b_txn.go @@ -62,15 +62,15 @@ func (txn *Txn) Commit() error { } commitTs, err := txn.scheduler.NewCommitTs(txn) + if err != nil { + return err + } { // WAL start entry | START // WAL write entry | DATA } - if err != nil { - return err - } doneCh := txn.executor.sendToWriteCh(txn.writeSet.ToExecutorReq(commitTs)) { diff --git a/pkg/txn/c_scheduler.go b/pkg/txn/c_scheduler.go index 1e432d9..77cdc6a 100644 --- a/pkg/txn/c_scheduler.go +++ b/pkg/txn/c_scheduler.go @@ -85,9 +85,10 @@ func (o *Scheduler) DoneCommit(commitTs uint64) { } func (o *Scheduler) hasConflictFor(txn *Txn) bool { + currTxnBeginTs := txn.snapshot.ts + for _, readyToCommitTxn := range o.readyToCommitTxns { - txnBeginTs := txn.snapshot.ts - if readyToCommitTxn.commitTs <= txnBeginTs { + if readyToCommitTxn.commitTs <= currTxnBeginTs { continue } @@ -102,10 +103,10 @@ func (o *Scheduler) hasConflictFor(txn *Txn) bool { func (o *Scheduler) gcOldReadyToCommitTxns() { updatedReadyToCommitTxns := o.readyToCommitTxns[:0] - lastCommittedTxnTs := o.readTsMarker.DoneTill() + lastActiveReadTs := o.readTsMarker.DoneTill() for _, readyToCommitTxn := range o.readyToCommitTxns { - if readyToCommitTxn.commitTs <= lastCommittedTxnTs { + if readyToCommitTxn.commitTs <= lastActiveReadTs { continue } updatedReadyToCommitTxns = append(updatedReadyToCommitTxns, readyToCommitTxn) diff --git a/pkg/txn/d_ts_waiter.go b/pkg/txn/d_ts_waiter.go index ebc6b2d..8835255 100644 --- a/pkg/txn/d_ts_waiter.go +++ b/pkg/txn/d_ts_waiter.go @@ -91,6 +91,7 @@ func (w *TsWaiter) Run() { } } } + func (w *TsWaiter) processWaitEvent(event Event) { doneTill := w.DoneTill() if doneTill >= event.ts {