Commit a2dea432 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 4467ebea
...@@ -20,8 +20,11 @@ ...@@ -20,8 +20,11 @@
package zodb package zodb
// application-level database handle. // application-level database handle.
// TODO: handle invalidations
import ( import (
"context" "context"
"fmt"
"sort" "sort"
"sync" "sync"
"time" "time"
...@@ -81,8 +84,27 @@ type ConnOptions struct { ...@@ -81,8 +84,27 @@ type ConnOptions struct {
// Open must be called under transaction. // Open must be called under transaction.
// Opened connection must be used only under the same transaction and only // Opened connection must be used only under the same transaction and only
// until that transaction is complete. // until that transaction is complete.
func (db *DB) Open(ctx context.Context, opt *ConnOptions) (*Connection, error) { func (db *DB) Open(ctx context.Context, opt *ConnOptions) (_ *Connection, err error) {
// XXX err ctx defer func() {
if err == nil {
return
}
var argv []interface{}
if opt.At != 0 {
argv = append(argv, fmt.Sprintf("at=%s", opt.At))
}
if opt.NoSync {
argv = append(argv, "nosync")
}
err = &OpError{
URL: db.stor.URL(),
Op: "open db",
Args: argv,
Err: err,
}
}()
txn := transaction.Current(ctx) txn := transaction.Current(ctx)
...@@ -140,6 +162,7 @@ func (db *DB) get(at Tid) *Connection { ...@@ -140,6 +162,7 @@ func (db *DB) get(at Tid) *Connection {
// search through window of X previous connections and find out the one // search through window of X previous connections and find out the one
// with minimal distance to get to state @at. If all connections are to // with minimal distance to get to state @at. If all connections are to
// distant - create connection anew. // distant - create connection anew.
//
// XXX search not only previous, but future too? (we can get back to // XXX search not only previous, but future too? (we can get back to
// past by invalidating what was later changed) // past by invalidating what was later changed)
const X = 10 // XXX hardcoded const X = 10 // XXX hardcoded
...@@ -168,7 +191,7 @@ func (db *DB) get(at Tid) *Connection { ...@@ -168,7 +191,7 @@ func (db *DB) get(at Tid) *Connection {
if conn.db != db { if conn.db != db {
panic("DB.get: foreign connection in the pool") panic("DB.get: foreign connection in the pool")
} }
if conn.txn != nil) { if conn.txn != nil {
panic("DB.get: live connection in the pool") panic("DB.get: live connection in the pool")
} }
......
...@@ -311,6 +311,7 @@ func (e *OpError) Error() string { ...@@ -311,6 +311,7 @@ func (e *OpError) Error() string {
if e.Args != nil { if e.Args != nil {
s += fmt.Sprintf(" %s", e.Args) s += fmt.Sprintf(" %s", e.Args)
} }
// XXX if e.Err = OpError with the same URL - don't print URL twice.
s += ": " + e.Err.Error() s += ": " + e.Err.Error()
return s return s
} }
......
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