Commit 79f54dcb authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 27120bd7
...@@ -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 nested transactions are not supported. // Nested 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)
......
// 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 the type 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 is there is no association. // nil is returned if 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 ----
......
// 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
......
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