Commit a35bc53b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3f3c556c
...@@ -176,7 +176,7 @@ func (conn *Connection) get(class string, oid Oid) (IPersistent, error) { ...@@ -176,7 +176,7 @@ func (conn *Connection) get(class string, oid Oid) (IPersistent, error) {
// The object's data is not necessarily loaded after Get returns. Use // The object's data is not necessarily loaded after Get returns. Use
// PActivate to make sure the object is fully loaded. // PActivate to make sure the object is fully loaded.
func (conn *Connection) Get(ctx context.Context, oid Oid) (IPersistent, error) { func (conn *Connection) Get(ctx context.Context, oid Oid) (IPersistent, error) {
conn.checkTxn(ctx, "Get") conn.checkTxnCtx(ctx, "Get")
conn.objmu.Lock() // XXX -> rlock conn.objmu.Lock() // XXX -> rlock
wobj := conn.objtab[oid] wobj := conn.objtab[oid]
...@@ -215,7 +215,7 @@ func (conn *Connection) Get(ctx context.Context, oid Oid) (IPersistent, error) { ...@@ -215,7 +215,7 @@ func (conn *Connection) Get(ctx context.Context, oid Oid) (IPersistent, error) {
// load loads object specified by oid. // load loads object specified by oid.
func (conn *Connection) load(ctx context.Context, oid Oid) (_ *mem.Buf, serial Tid, _ error) { func (conn *Connection) load(ctx context.Context, oid Oid) (_ *mem.Buf, serial Tid, _ error) {
conn.checkTxn(ctx, "load") conn.checkTxnCtx(ctx, "load")
return conn.stor.Load(ctx, Xid{Oid: oid, At: conn.at}) return conn.stor.Load(ctx, Xid{Oid: oid, At: conn.at})
} }
...@@ -223,10 +223,14 @@ func (conn *Connection) load(ctx context.Context, oid Oid) (_ *mem.Buf, serial T ...@@ -223,10 +223,14 @@ func (conn *Connection) load(ctx context.Context, oid Oid) (_ *mem.Buf, serial T
// ---------------------------------------- // ----------------------------------------
// checkTxn asserts that current transaction is the same as conn.txn . // checkTxnCtx asserts that current transaction is the same as conn.txn .
func (conn *Connection) checkTxn(ctx context.Context, who string) { func (conn *Connection) checkTxnCtx(ctx context.Context, who string) {
if txn := transaction.Current(ctx); txn != conn.txn { conn.checkTxn(transaction.Current(ctx), who)
}
// checkTxn asserts that specified "current" transaction is the same as conn.txn .
func (conn *Connection) checkTxn(txn transaction.Transaction, who string) {
if txn != conn.txn {
panic("connection: " + who + "current transaction is different from connection transaction") panic("connection: " + who + "current transaction is different from connection transaction")
} }
} }
...@@ -109,13 +109,16 @@ func (db *DB) put(conn *Connection) { ...@@ -109,13 +109,16 @@ func (db *DB) put(conn *Connection) {
type connTxnSync Connection // hide from public API type connTxnSync Connection // hide from public API
func (conn *connTxnSync) BeforeCompletion(txn transaction.Transaction) { func (csync *connTxnSync) BeforeCompletion(txn transaction.Transaction) {
// XXX check txn conn := (*Connection)(csync)
conn.checkTxn(txn, "BeforeCompletion")
// nothing // nothing
} }
func (conn *connTxnSync) AfterCompletion(txn transaction.Transaction) { func (csync *connTxnSync) AfterCompletion(txn transaction.Transaction) {
// XXX check txn conn := (*Connection)(csync)
conn.checkTxn(txn, "AfterCompletion")
conn.db.put((*Connection)(conn)) // put conn back into db pool.
conn.db.put(conn)
} }
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