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
79f54dcb
Commit
79f54dcb
authored
Aug 07, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
27120bd7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
45 deletions
+52
-45
go/transaction/api.go
go/transaction/api.go
+7
-9
go/transaction/transaction.go
go/transaction/transaction.go
+30
-27
go/transaction/transaction_test.go
go/transaction/transaction_test.go
+15
-9
No files found.
go/transaction/api.go
View file @
79f54dcb
...
...
@@ -140,12 +140,13 @@ const (
// Before completion, if there are changes to managed data, corresponding
// DataManager(s) must join the transaction to participate in the completion.
type
Transaction
interface
{
User
()
string
// user name associated with transaction
User
()
string
// user name associated with transaction
Description
()
string
// description of transaction
// XXX map[string]interface{} (objects must be simple values serialized with pickle or json, not "instances")
Extension
()
string
// XXX +Note, SetUser, ...
// Status returns current status of the transaction.
...
...
@@ -181,7 +182,7 @@ type Transaction interface {
// Join must be called before transaction completion begins.
Join
(
dm
DataManager
)
// RegisterSync registers sync to be notified
in
this transaction boundary events.
// RegisterSync registers sync to be notified
of
this transaction boundary events.
//
// See Synchronizer for details.
//
...
...
@@ -194,8 +195,8 @@ type Transaction interface {
// New creates new transaction.
//
//
XXX the transaction will be associated with ctx (txnCtx derives from ctx + associates txn)
//
XXX n
ested transactions are not supported.
//
The transaction will be associated with new context derived from ctx.
//
N
ested transactions are not supported.
func
New
(
ctx
context
.
Context
)
(
txn
Transaction
,
txnCtx
context
.
Context
)
{
return
newTxn
(
ctx
)
}
...
...
@@ -247,9 +248,8 @@ type DataManager interface {
//
// It should make all changes to data modified by this transaction persist.
//
// This should never fail. If this returns an error, the XXX
// database is not expected to maintain consistency; it's a
// serious error.
// This should never fail. If this returns an error, the database is
// not expected to maintain consistency; it's a serious error.
TPCFinish
(
ctx
context
.
Context
,
txn
Transaction
)
error
// TPCAbort should Abort a transaction.
...
...
@@ -291,8 +291,6 @@ type Synchronizer interface {
//
// On return ok indicates whether f succeeded, and the error, depending on ok,
// is either the error from f, or the error from transaction commit.
//
// XXX + note?
func
With
(
ctx
context
.
Context
,
f
func
(
context
.
Context
)
error
)
(
ok
bool
,
_
error
)
{
txn
,
ctx
:=
New
(
ctx
)
err
:=
f
(
ctx
)
...
...
go/transaction/transaction.go
View file @
79f54dcb
// Copyright (c) 2001, 2002 Zope Foundation and Contributors.
// All Rights Reserved.
//
// Copyright (C) 2018 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This software is subject to the provisions of the Zope Public License,
// Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
// THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
// WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
// FOR A PARTICULAR PURPOSE.
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
package
transaction
...
...
@@ -33,11 +39,11 @@ type transaction struct {
extension
string
// XXX
}
// ctxKey is type private to transaction package, used as key in contexts.
// ctxKey is t
he t
ype private to transaction package, used as key in contexts.
type
ctxKey
struct
{}
// getTxn returns transaction associated with provided context.
// nil is returned i
s
there is no association.
// nil is returned i
f
there is no association.
func
getTxn
(
ctx
context
.
Context
)
*
transaction
{
t
:=
ctx
.
Value
(
ctxKey
{})
if
t
==
nil
{
...
...
@@ -158,22 +164,6 @@ func (txn *transaction) Abort() {
// XXX return error?
}
// checkNotYetCompleting asserts that transaction completion has not yet began.
//
// and panics if the assert fails.
// must be called with .mu held.
//
// XXX place
func
(
txn
*
transaction
)
checkNotYetCompleting
(
who
string
)
{
switch
txn
.
status
{
case
Active
:
// XXX + Doomed ?
// ok
default
:
panic
(
"transaction: "
+
who
+
": transaction completion already began"
)
}
}
// Join implements Transaction.
func
(
txn
*
transaction
)
Join
(
dm
DataManager
)
{
txn
.
mu
.
Lock
()
...
...
@@ -196,6 +186,19 @@ func (txn *transaction) RegisterSync(sync Synchronizer) {
txn
.
syncv
=
append
(
txn
.
syncv
,
sync
)
}
// checkNotYetCompleting asserts that transaction completion has not yet began.
//
// and panics if the assert fails.
// must be called with .mu held.
func
(
txn
*
transaction
)
checkNotYetCompleting
(
who
string
)
{
switch
txn
.
status
{
case
Active
:
// XXX + Doomed ?
// ok
default
:
panic
(
"transaction: "
+
who
+
": transaction completion already began"
)
}
}
// ---- meta ----
...
...
go/transaction/transaction_test.go
View file @
79f54dcb
// Copyright (c) 2001, 2002 Zope Foundation and Contributors.
// All Rights Reserved.
//
// Copyright (C) 2018 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This software is subject to the provisions of the Zope Public License,
// Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
// THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
// WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
// FOR A PARTICULAR PURPOSE.
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
package
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