Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
2e93d7e4
Commit
2e93d7e4
authored
Jul 24, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
c1ba4a4c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
54 deletions
+66
-54
go/transaction/transaction.go
go/transaction/transaction.go
+66
-54
No files found.
go/transaction/transaction.go
View file @
2e93d7e4
...
@@ -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 seqeu
nce of transactions.
//
// Manager manages seque
nce 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, er
rror -> yes, i.e. it needs to sync fetch last tid from db
// // XXX + ctx, e
rror -> 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 m
anager to the transaction.
// Join associates a
DataM
anager 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 manag
er should be prepared to make the
// errors occur, the
committ
er should be prepared to make the
// changes persist when
tpc_f
inish is called.
// changes persist when
TPCF
inish is called.
Commit
(
ctx
context
.
Context
,
txn
Transaction
)
error
Commit
(
ctx
context
.
Context
,
txn
Transaction
)
error
// TPCVote should verify that a
data manag
er can commit the transaction.
// TPCVote should verify that a
committ
er can commit the transaction.
//
//
// This is the last chance for a
data manag
er to vote 'no'. A
// This is the last chance for a
committ
er to vote 'no'. A
//
data manag
er votes 'no' by returning an error.
//
committ
er votes 'no' by returning an error.
TPCVote
(
ctx
context
.
Context
,
txn
Transaction
)
error
TPCVote
(
ctx
context
.
Context
,
txn
Transaction
)
error
//
I
ndicate confirmation that the transaction is done.
//
TPCFinish should i
ndicate 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 nee
e
ds to ask storage for last tid)
// XXX + ctx, error (it needs to ask storage for last tid)
NewTransaction
(
txn
Transaction
)
NewTransaction
(
txn
Transaction
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment