Commit 2e93d7e4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c1ba4a4c
...@@ -17,50 +17,54 @@ ...@@ -17,50 +17,54 @@
// //
// http://transaction.readthedocs.org // http://transaction.readthedocs.org
// https://github.com/zopefoundation/transaction // https://github.com/zopefoundation/transaction
//
// but is not exactly equal to it.
package transaction package transaction
import ( import (
"context" "context"
) )
// Manager manages seqeunce of transactions. // // Manager manages sequence of transactions.
type Manager interface { // type Manager interface {
//
// Begin begins new transaction. // // Begin begins new transaction.
// // //
// XXX // // XXX
// // //
// XXX There must be no existing in progress transaction. // // XXX There must be no existing in progress transaction.
// XXX kill ^^^ - we should support many simultaneous transactions. // // XXX kill ^^^ - we should support many simultaneous transactions.
// // //
// XXX + ctx, errror -> yes, i.e. it needs to sync fetch last tid from db // // XXX + ctx, error -> yes, i.e. it needs to sync fetch last tid from db
Begin() Transaction // Begin() Transaction
//
// RegisterSynch registers synchronizer. // // RegisterSynch registers synchronizer.
// // //
// Synchronizers are notified about major events in a transaction's life. // // Synchronizers are notified about major events in a transaction's life.
// See Synchronizer for details. // // See Synchronizer for details.
RegisterSynch(synch Synchronizer) // RegisterSynch(synch Synchronizer)
//
// UnregisterSynch unregisters synchronizer. // // UnregisterSynch unregisters synchronizer.
// // //
// XXX synchronizer must be already registered? // // XXX synchronizer must be already registered?
// XXX or make RegisterSynch return something that will allow to unregister via that? // // XXX or make RegisterSynch return something that will allow to unregister via that?
UnregisterSynch(synch Synchronizer) // UnregisterSynch(synch Synchronizer)
} // }
// Transaction represents running transaction. // Transaction represents running transaction.
// //
// XXX -> concrete type? // ... and should be completed by either Commit or Abort.
type Transaction interface { type Transaction interface {
User() string // user name associated with transaction User() string // user name associated with transaction
Description() string // description of transaction Description() string // description of transaction
Extension() string // XXX
// XXX map[string]interface{} (objects must be simple values serialized with pickle or json, not "instances")
Extension() string
// Commit finalizes the transaction. // Commit finalizes the transaction.
// //
// This executes the two-phase commit algorithm for all // This executes the two-phase commit algorithm for all DataManagers
// DataManager objects associated with the transaction. // associated with the transaction.
Commit(ctx context.Context) error Commit(ctx context.Context) error
// Abort aborts the transaction. // Abort aborts the transaction.
...@@ -71,59 +75,66 @@ type Transaction interface { ...@@ -71,59 +75,66 @@ type Transaction interface {
// XXX + Doom? // XXX + Doom?
// Join associates a data manager to the transaction. // Join associates a DataManager to the transaction.
// //
// Only associated data managers will participate in the transaction commit. // Only associated data managers will participate in the transaction commit.
// Join(DataManager)
// XXX -> JoinCommit?
Join(dm DataManager)
// XXX SetData(key interface{}, data interface{}) // XXX SetData(key interface{}, data interface{})
// XXX GetData(key interface{}) interface{}, ok // XXX GetData(key interface{}) interface{}, ok
} }
// // XXX
// type Participant interface {
// }
// DataManager represents transactional storage. // DataManager manages data and can transactionally persist it.
// //
// If DataManager is registered to transaction via Transaction.Join, it will // If DataManager is registered to transaction via Transaction.Join, it will
// participate in that transaction commit. // participate in that transaction commit or abort.
//
// XXX -> TPCCommitter?
type DataManager interface { type DataManager interface {
// Abort should abort all modifications to managed data.
//
// Abort is called by Transaction outside of two-phase commit, and only
// if abort was caused by user requesting transaction abort. If
// two-phase commit was started and transaction needs to be aborted due
// to two-phase commit logic, TPCAbort will be called.
Abort(txn Transaction) // XXX +ctx, error
// TPCBegin should begin commit of a transaction, starting the two-phase commit. // TPCBegin should begin commit of a transaction, starting the two-phase commit.
TPCBegin(txn Transaction) // XXX +ctx, error ? TPCBegin(txn Transaction) // XXX +ctx, error ?
// Commit should commit modifications to registered objects. // Commit should commit modifications to managed data.
// //
// Save changes to be made persistent if the transaction commits (if // It should save changes to be made persistent if the transaction
// tpc_finish is called later). If tpc_abort is called later, changes // commits (if TPCFinish is called later). If TPCAbort is called
// must not persist. // later, changes must not persist.
// //
// This includes conflict detection and handling. If no conflicts or // This includes conflict detection and handling. If no conflicts or
// errors occur, the data manager should be prepared to make the // errors occur, the committer should be prepared to make the
// changes persist when tpc_finish is called. // changes persist when TPCFinish is called.
Commit(ctx context.Context, txn Transaction) error Commit(ctx context.Context, txn Transaction) error
// TPCVote should verify that a data manager can commit the transaction. // TPCVote should verify that a committer can commit the transaction.
// //
// This is the last chance for a data manager to vote 'no'. A // This is the last chance for a committer to vote 'no'. A
// data manager votes 'no' by returning an error. // committer votes 'no' by returning an error.
TPCVote(ctx context.Context, txn Transaction) error TPCVote(ctx context.Context, txn Transaction) error
// Indicate confirmation that the transaction is done. // TPCFinish should indicate confirmation that the transaction is done.
// //
// Make all changes to objects modified by this transaction persist. // It should make all changes to data modified by this transaction persist.
// //
// This should never fail. If this raises an exception, the XXX // This should never fail. If this returns an error, the XXX
// database is not expected to maintain consistency; it's a // database is not expected to maintain consistency; it's a
// serious error. // serious error.
TPCFinish(ctx context.Context, txn Transaction) // XXX error? TPCFinish(ctx context.Context, txn Transaction) error
// TPCAbort should Abort a transaction. // TPCAbort should Abort a transaction.
// //
// This is called by a transaction manager to end a two-phase commit on // This is called by a transaction manager to end a two-phase commit on
// the data manager. Abandon all changes to objects modified by this // the data manager. It should abandon all changes to data modified
// transaction. // by this transaction.
// //
// This should never fail. // This should never fail.
TPCAbort(ctx context.Context, txn Transaction) // XXX error? TPCAbort(ctx context.Context, txn Transaction) // XXX error?
...@@ -135,6 +146,7 @@ type DataManager interface { ...@@ -135,6 +146,7 @@ type DataManager interface {
// Synchronizer is the interface to participate in transaction-boundary notifications. // Synchronizer is the interface to participate in transaction-boundary notifications.
type Synchronizer interface { type Synchronizer interface {
// BeforeCompletion is called by the transaction at the start of a commit. // BeforeCompletion is called by the transaction at the start of a commit.
// XXX -> PreCommit ?
BeforeCompletion(txn Transaction) BeforeCompletion(txn Transaction)
// AfterCompletion is called by the transaction after completing a commit. // AfterCompletion is called by the transaction after completing a commit.
...@@ -142,6 +154,6 @@ type Synchronizer interface { ...@@ -142,6 +154,6 @@ type Synchronizer interface {
// NewTransaction is called at the start of a transaction. // NewTransaction is called at the start of a transaction.
// XXX -> TxnStart ? // XXX -> TxnStart ?
// XXX + ctx, error (it neeeds to ask storage for last tid) // XXX + ctx, error (it needs to ask storage for last tid)
NewTransaction(txn Transaction) NewTransaction(txn Transaction)
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment