Commit 413c07d3 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent a3d6a35d
...@@ -152,13 +152,13 @@ const ( ...@@ -152,13 +152,13 @@ const (
// state eviction until state discard is semantically required. // state eviction until state discard is semantically required.
PCachePinObject PCachePolicy = 1 << iota PCachePinObject PCachePolicy = 1 << iota
// don't keep object in the cache. // don't keep object in cache.
// //
// The object will be discarded from the cache completely as soon as it // The object will be discarded from the cache completely as soon as it
// is semantically valid to do so. // is semantically valid to do so.
PCacheDropObject PCacheDropObject
// keep object state in the cache. // keep object state in cache.
// //
// This prevents object state to go away when !dirty object is no // This prevents object state to go away when !dirty object is no
// longer used. However the object itself can go away unless it is // longer used. However the object itself can go away unless it is
...@@ -237,7 +237,7 @@ func (cache *LiveCache) Get(oid Oid) IPersistent { ...@@ -237,7 +237,7 @@ func (cache *LiveCache) Get(oid Oid) IPersistent {
// setNew sets objects corresponding to oid. // setNew sets objects corresponding to oid.
// //
// The cache must not have previous entry for oid before setNew is called. // The cache must not have entry for oid when setNew is called.
func (cache *LiveCache) setNew(oid Oid, obj IPersistent) { func (cache *LiveCache) setNew(oid Oid, obj IPersistent) {
var cp PCachePolicy var cp PCachePolicy
if cc := cache.control; cc != nil { if cc := cache.control; cc != nil {
......
...@@ -204,8 +204,10 @@ func (cc *zcacheControl) PCacheClassify(obj IPersistent) PCachePolicy { ...@@ -204,8 +204,10 @@ func (cc *zcacheControl) PCacheClassify(obj IPersistent) PCachePolicy {
return cc.pCachePolicy[obj.POid()] // default -> 0 return cc.pCachePolicy[obj.POid()] // default -> 0
} }
// tPersistentDB represents testing database. XXX -> tDB ? // tDB represents testing database.
type tPersistentDB struct { //
// The database can be worked on via zodb/go and committed into via zodb/py.
type tDB struct {
*testing.T *testing.T
work string // working directory work string // working directory
...@@ -222,8 +224,8 @@ type tPersistentDB struct { ...@@ -222,8 +224,8 @@ type tPersistentDB struct {
rawcache bool rawcache bool
} }
// tPersistentConn represents testing Connection. XXX -> tConn ? // tConnection represents testing Connection.
type tPersistentConn struct { type tConnection struct {
*testing.T *testing.T
// a transaction and DB connection opened under it // a transaction and DB connection opened under it
...@@ -233,9 +235,9 @@ type tPersistentConn struct { ...@@ -233,9 +235,9 @@ type tPersistentConn struct {
} }
// testdb creates and initializes new test database. // testdb creates and initializes new test database.
func testdb(t0 *testing.T, rawcache bool) *tPersistentDB { func testdb(t0 *testing.T, rawcache bool) *tDB {
t0.Helper() t0.Helper()
t := &tPersistentDB{ t := &tDB{
T: t0, T: t0,
rawcache: rawcache, rawcache: rawcache,
} }
...@@ -265,7 +267,7 @@ func testdb(t0 *testing.T, rawcache bool) *tPersistentDB { ...@@ -265,7 +267,7 @@ func testdb(t0 *testing.T, rawcache bool) *tPersistentDB {
} }
// Reopen repoens zodb/go .stor and .db . // Reopen repoens zodb/go .stor and .db .
func (t *tPersistentDB) Reopen() { func (t *tDB) Reopen() {
t.Helper() t.Helper()
X := t.fatalif X := t.fatalif
...@@ -279,7 +281,7 @@ func (t *tPersistentDB) Reopen() { ...@@ -279,7 +281,7 @@ func (t *tPersistentDB) Reopen() {
t.db = db t.db = db
} }
func (t *tPersistentDB) close() { func (t *tDB) close() {
t.Helper() t.Helper()
X := t.fatalif X := t.fatalif
...@@ -295,7 +297,7 @@ func (t *tPersistentDB) close() { ...@@ -295,7 +297,7 @@ func (t *tPersistentDB) close() {
} }
// Close release resources associated with test database. // Close release resources associated with test database.
func (t *tPersistentDB) Close() { func (t *tDB) Close() {
t.Helper() t.Helper()
X := t.fatalif X := t.fatalif
...@@ -307,7 +309,7 @@ func (t *tPersistentDB) Close() { ...@@ -307,7 +309,7 @@ func (t *tPersistentDB) Close() {
// MyObject(value). // MyObject(value).
// //
// The commit is performed by Commit. // The commit is performed by Commit.
func (t *tPersistentDB) Add(oid Oid, value string) { func (t *tDB) Add(oid Oid, value string) {
obj := NewMyObject(nil) // XXX hack - goes without jar obj := NewMyObject(nil) // XXX hack - goes without jar
obj.oid = oid obj.oid = oid
obj.value = value obj.value = value
...@@ -315,20 +317,19 @@ func (t *tPersistentDB) Add(oid Oid, value string) { ...@@ -315,20 +317,19 @@ func (t *tPersistentDB) Add(oid Oid, value string) {
} }
// Commit commits objects queued by Add. // Commit commits objects queued by Add.
func (t *tPersistentDB) Commit() { func (t *tDB) Commit() {
t.Helper() t.Helper()
head, err := ZPyCommit(t.zurl, t.head, t.commitq...) head, err := ZPyCommit(t.zurl, t.head, t.commitq...)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
//fmt.Printf("commit @%s -> @%s\n", t.head, head)
t.head = head t.head = head
t.commitq = nil t.commitq = nil
} }
// Open opens new test transaction/connection. // Open opens new test transaction/connection.
func (t *tPersistentDB) Open(opt *ConnOptions) *tPersistentConn { func (t *tDB) Open(opt *ConnOptions) *tConnection {
t.Helper() t.Helper()
X := t.fatalif X := t.fatalif
...@@ -338,7 +339,7 @@ func (t *tPersistentDB) Open(opt *ConnOptions) *tPersistentConn { ...@@ -338,7 +339,7 @@ func (t *tPersistentDB) Open(opt *ConnOptions) *tPersistentConn {
assert.Same(t, conn.db, t.db) assert.Same(t, conn.db, t.db)
assert.Same(t, conn.txn, txn) assert.Same(t, conn.txn, txn)
return &tPersistentConn{ return &tConnection{
T: t.T, T: t.T,
txn: txn, txn: txn,
ctx: ctx, ctx: ctx,
...@@ -347,7 +348,7 @@ func (t *tPersistentDB) Open(opt *ConnOptions) *tPersistentConn { ...@@ -347,7 +348,7 @@ func (t *tPersistentDB) Open(opt *ConnOptions) *tPersistentConn {
} }
// Get gets oid from t.conn and asserts its type. // Get gets oid from t.conn and asserts its type.
func (t *tPersistentConn) Get(oid Oid) *MyObject { func (t *tConnection) Get(oid Oid) *MyObject {
t.Helper() t.Helper()
xobj, err := t.conn.Get(t.ctx, oid) xobj, err := t.conn.Get(t.ctx, oid)
if err != nil { if err != nil {
...@@ -364,7 +365,7 @@ func (t *tPersistentConn) Get(oid Oid) *MyObject { ...@@ -364,7 +365,7 @@ func (t *tPersistentConn) Get(oid Oid) *MyObject {
} }
// PActivate activates obj in t environment. // PActivate activates obj in t environment.
func (t *tPersistentConn) PActivate(obj IPersistent) { func (t *tConnection) PActivate(obj IPersistent) {
t.Helper() t.Helper()
err := obj.PActivate(t.ctx) err := obj.PActivate(t.ctx)
if err != nil { if err != nil {
...@@ -375,7 +376,7 @@ func (t *tPersistentConn) PActivate(obj IPersistent) { ...@@ -375,7 +376,7 @@ func (t *tPersistentConn) PActivate(obj IPersistent) {
// checkObj checks state of obj and that obj ∈ t.conn. // checkObj checks state of obj and that obj ∈ t.conn.
// //
// if object is !GHOST - it also verifies its value. // if object is !GHOST - it also verifies its value.
func (t *tPersistentConn) checkObj(obj *MyObject, oid Oid, serial Tid, state ObjectState, refcnt int32, valueOk ...string) { func (t *tConnection) checkObj(obj *MyObject, oid Oid, serial Tid, state ObjectState, refcnt int32, valueOk ...string) {
t.Helper() t.Helper()
// any object with live pointer to it must be also in conn's cache. // any object with live pointer to it must be also in conn's cache.
...@@ -415,7 +416,7 @@ func (t *tPersistentConn) checkObj(obj *MyObject, oid Oid, serial Tid, state Obj ...@@ -415,7 +416,7 @@ func (t *tPersistentConn) checkObj(obj *MyObject, oid Oid, serial Tid, state Obj
} }
// Resync resyncs t to new transaction @at. // Resync resyncs t to new transaction @at.
func (t *tPersistentConn) Resync(at Tid) { func (t *tConnection) Resync(at Tid) {
t.Helper() t.Helper()
db := t.conn.db db := t.conn.db
...@@ -434,20 +435,20 @@ func (t *tPersistentConn) Resync(at Tid) { ...@@ -434,20 +435,20 @@ func (t *tPersistentConn) Resync(at Tid) {
} }
// Abort aborts t's connection and verifies it becomes !live. // Abort aborts t's connection and verifies it becomes !live.
func (t *tPersistentConn) Abort() { func (t *tConnection) Abort() {
t.Helper() t.Helper()
assert.Same(t, t.conn.txn, t.txn) assert.Same(t, t.conn.txn, t.txn)
t.txn.Abort() t.txn.Abort()
assert.Equal(t, t.conn.txn, nil) assert.Equal(t, t.conn.txn, nil)
} }
func (t *tPersistentDB) fatalif(err error) { func (t *tDB) fatalif(err error) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
func (t *tPersistentConn) fatalif(err error) { func (t *tConnection) fatalif(err error) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -488,7 +489,6 @@ func testPersistentDB(t0 *testing.T, rawcache bool) { ...@@ -488,7 +489,6 @@ func testPersistentDB(t0 *testing.T, rawcache bool) {
assert.Equal(db.pool, []*Connection(nil)) assert.Equal(db.pool, []*Connection(nil))
// δtail coverage is (at1, at1] (at0 not included) // δtail coverage is (at1, at1] (at0 not included)
//fmt.Println(db.δtail.Tail(), db.δtail.Head())
assert.Equal(db.δtail.Tail(), at1) assert.Equal(db.δtail.Tail(), at1)
assert.Equal(db.δtail.Head(), at1) assert.Equal(db.δtail.Head(), at1)
......
...@@ -42,7 +42,10 @@ var infov = []struct {name string; getParam paramFunc} { ...@@ -42,7 +42,10 @@ var infov = []struct {name string; getParam paramFunc} {
// TODO reenable size // TODO reenable size
// {"size", func(stor zodb.IStorage) (string, error) { return stor.StorageSize(), nil }}, // {"size", func(stor zodb.IStorage) (string, error) { return stor.StorageSize(), nil }},
{"head", zhead}, {"head", zhead},
{"last_tid", zhead}, // last_tid is deprecated alias for head {"last_tid", func(ctx context.Context, stor zodb.IStorage) (string, error) {
fmt.Fprintf(os.Stderr, "W: last_tid is deprecated alias for head\n")
return zhead(ctx, stor)
}},
} }
func zhead(ctx context.Context, stor zodb.IStorage) (string, error) { func zhead(ctx context.Context, stor zodb.IStorage) (string, error) {
......
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