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 (
...
@@ -140,12 +140,13 @@ const (
// Before completion, if there are changes to managed data, corresponding
// Before completion, if there are changes to managed data, corresponding
// DataManager(s) must join the transaction to participate in the completion.
// DataManager(s) must join the transaction to participate in the completion.
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
// XXX map[string]interface{} (objects must be simple values serialized with pickle or json, not "instances")
// XXX map[string]interface{} (objects must be simple values serialized with pickle or json, not "instances")
Extension
()
string
Extension
()
string
// XXX +Note, SetUser, ...
// Status returns current status of the transaction.
// Status returns current status of the transaction.
...
@@ -181,7 +182,7 @@ type Transaction interface {
...
@@ -181,7 +182,7 @@ type Transaction interface {
// Join must be called before transaction completion begins.
// Join must be called before transaction completion begins.
Join
(
dm
DataManager
)
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.
// See Synchronizer for details.
//
//
...
@@ -194,8 +195,8 @@ type Transaction interface {
...
@@ -194,8 +195,8 @@ type Transaction interface {
// New creates new transaction.
// New creates new transaction.
//
//
//
XXX the transaction will be associated with ctx (txnCtx derives from ctx + associates txn)
//
The transaction will be associated with new context derived from ctx.
//
XXX n
ested transactions are not supported.
//
N
ested transactions are not supported.
func
New
(
ctx
context
.
Context
)
(
txn
Transaction
,
txnCtx
context
.
Context
)
{
func
New
(
ctx
context
.
Context
)
(
txn
Transaction
,
txnCtx
context
.
Context
)
{
return
newTxn
(
ctx
)
return
newTxn
(
ctx
)
}
}
...
@@ -247,9 +248,8 @@ type DataManager interface {
...
@@ -247,9 +248,8 @@ type DataManager interface {
//
//
// It should make all changes to data modified by this transaction persist.
// It should make all changes to data modified by this transaction persist.
//
//
// This should never fail. If this returns an error, the XXX
// This should never fail. If this returns an error, the database is
// database is not expected to maintain consistency; it's a
// not expected to maintain consistency; it's a serious error.
// serious error.
TPCFinish
(
ctx
context
.
Context
,
txn
Transaction
)
error
TPCFinish
(
ctx
context
.
Context
,
txn
Transaction
)
error
// TPCAbort should Abort a transaction.
// TPCAbort should Abort a transaction.
...
@@ -291,8 +291,6 @@ type Synchronizer interface {
...
@@ -291,8 +291,6 @@ type Synchronizer interface {
//
//
// On return ok indicates whether f succeeded, and the error, depending on ok,
// 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.
// 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
)
{
func
With
(
ctx
context
.
Context
,
f
func
(
context
.
Context
)
error
)
(
ok
bool
,
_
error
)
{
txn
,
ctx
:=
New
(
ctx
)
txn
,
ctx
:=
New
(
ctx
)
err
:=
f
(
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.
// Copyright (C) 2018 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
// Kirill Smelkov <kirr@nexedi.com>
//
//
// This software is subject to the provisions of the Zope Public License,
// This program is free software: you can Use, Study, Modify and Redistribute
// Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
// it under the terms of the GNU General Public License version 3, or (at your
// THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
// option) any later version, as published by the Free Software Foundation.
// WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
//
// WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
// You can also Link and Combine this program with other software covered by
// FOR A PARTICULAR PURPOSE.
// 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
package
transaction
...
@@ -33,11 +39,11 @@ type transaction struct {
...
@@ -33,11 +39,11 @@ type transaction struct {
extension
string
// XXX
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
{}
type
ctxKey
struct
{}
// getTxn returns transaction associated with provided context.
// 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
{
func
getTxn
(
ctx
context
.
Context
)
*
transaction
{
t
:=
ctx
.
Value
(
ctxKey
{})
t
:=
ctx
.
Value
(
ctxKey
{})
if
t
==
nil
{
if
t
==
nil
{
...
@@ -158,22 +164,6 @@ func (txn *transaction) Abort() {
...
@@ -158,22 +164,6 @@ func (txn *transaction) Abort() {
// XXX return error?
// 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.
// Join implements Transaction.
func
(
txn
*
transaction
)
Join
(
dm
DataManager
)
{
func
(
txn
*
transaction
)
Join
(
dm
DataManager
)
{
txn
.
mu
.
Lock
()
txn
.
mu
.
Lock
()
...
@@ -196,6 +186,19 @@ func (txn *transaction) RegisterSync(sync Synchronizer) {
...
@@ -196,6 +186,19 @@ func (txn *transaction) RegisterSync(sync Synchronizer) {
txn
.
syncv
=
append
(
txn
.
syncv
,
sync
)
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 ----
// ---- 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.
// Copyright (C) 2018 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
// Kirill Smelkov <kirr@nexedi.com>
//
//
// This software is subject to the provisions of the Zope Public License,
// This program is free software: you can Use, Study, Modify and Redistribute
// Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
// it under the terms of the GNU General Public License version 3, or (at your
// THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
// option) any later version, as published by the Free Software Foundation.
// WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
//
// WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
// You can also Link and Combine this program with other software covered by
// FOR A PARTICULAR PURPOSE.
// 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
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