Commit fb4ece21 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent fddbe660
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
package client package client
import ( import (
"fmt"
"reflect" "reflect"
"sort" "sort"
"testing" "testing"
...@@ -43,8 +44,10 @@ type tOidData struct { ...@@ -43,8 +44,10 @@ type tOidData struct {
} }
func (s *tStorage) Load(xid zodb.Xid) (data []byte, serial zodb.Tid, err error) { func (s *tStorage) Load(xid zodb.Xid) (data []byte, serial zodb.Tid, err error) {
fmt.Printf("> load(%v)\n", xid)
defer func() { fmt.Printf("< %v, %v, %v\n", data, serial, err) }()
tid := xid.Tid tid := xid.Tid
if xid.TidBefore { if !xid.TidBefore {
tid++ // XXX overflow tid++ // XXX overflow
} }
...@@ -56,47 +59,24 @@ func (s *tStorage) Load(xid zodb.Xid) (data []byte, serial zodb.Tid, err error) ...@@ -56,47 +59,24 @@ func (s *tStorage) Load(xid zodb.Xid) (data []byte, serial zodb.Tid, err error)
// find max entry with .serial < tid // find max entry with .serial < tid
n := len(datav) n := len(datav)
i := n - 1 - sort.Search(n, func(i int) bool { i := n - 1 - sort.Search(n, func(i int) bool {
return datav[n - 1 - i].serial < tid v := datav[n - 1 - i].serial < tid
fmt.Printf("@%d -> %v (@%d; %v)\n", i, v, n - 1 -i, tid)
return v
}) })
fmt.Printf("i: %d n: %d\n", i, n)
if i == -1 { if i == -1 {
// tid < all .serial - no such transaction // tid < all .serial - no such transaction
return nil, 0, &zodb.ErrXidMissing{xid} return nil, 0, &zodb.ErrXidMissing{xid}
} }
// check we have exact match if it was loadSerial // check we have exact match if it was loadSerial
if xid.TidBefore && datav[i].serial != xid.Tid { if !xid.TidBefore && datav[i].serial != xid.Tid {
return nil, 0, &zodb.ErrXidMissing{xid} return nil, 0, &zodb.ErrXidMissing{xid}
} }
return datav[i].data, datav[i].serial, nil return datav[i].data, datav[i].serial, nil
} }
/*
type tTxnRecord struct {
tid zodb.Tid
// data records for oid changed in transaction
// .oid↑
datav []tDataRecord
}
type tDataRecord struct {
oid zodb.Oid
data []byte
}
if xid.TidBefore {
// find max txn with .tid < xid.Tid
n := len(s.txnv)
i := n - 1 - sort.Search(n, func(i int) bool {
return s.txnv[n - 1 - i].tid < xid.Tid
})
if i == -1 {
// XXX xid.Tid < all .tid - no such transaction
}
}
*/
var tstor = &tStorage{ var tstor = &tStorage{
dataMap: map[zodb.Oid][]tOidData{ dataMap: map[zodb.Oid][]tOidData{
1: { 1: {
...@@ -106,24 +86,6 @@ var tstor = &tStorage{ ...@@ -106,24 +86,6 @@ var tstor = &tStorage{
}, },
} }
type Checker struct {
t *testing.T
}
func (c *Checker) ok1(v bool) {
c.t.Helper()
if !v {
c.t.Fatal("!ok")
}
}
func (c *Checker) assertEq(a, b interface{}) {
c.t.Helper()
if !reflect.DeepEqual(a, b) {
c.t.Fatal("!eq:\n", pretty.Compare(a, b))
}
}
func TestCache(t *testing.T) { func TestCache(t *testing.T) {
// XXX <100 <90 <80 // XXX <100 <90 <80
// q<110 -> a) 110 <= cache.before b) otherwise // q<110 -> a) 110 <= cache.before b) otherwise
...@@ -142,6 +104,9 @@ func TestCache(t *testing.T) { ...@@ -142,6 +104,9 @@ func TestCache(t *testing.T) {
c := NewCache(tstor) c := NewCache(tstor)
// XXX hack; place=ok?
pretty.CompareConfig.PrintStringers = true
xid1 := zodb.Xid{Oid: 1, XTid: zodb.XTid{Tid: 2, TidBefore: true}} xid1 := zodb.Xid{Oid: 1, XTid: zodb.XTid{Tid: 2, TidBefore: true}}
data, serial, err := c.Load(xid1) // -> nil, 0, &zodb.ErrXidMissing{1,<2} data, serial, err := c.Load(xid1) // -> nil, 0, &zodb.ErrXidMissing{1,<2}
ok1(data == nil) ok1(data == nil)
...@@ -164,3 +129,47 @@ func TestCache(t *testing.T) { ...@@ -164,3 +129,47 @@ func TestCache(t *testing.T) {
eq(len(oce1.revv), 1) eq(len(oce1.revv), 1)
eq(oce1.revv[0], rce1_b2) eq(oce1.revv[0], rce1_b2)
} }
type Checker struct {
t *testing.T
}
func (c *Checker) ok1(v bool) {
c.t.Helper()
if !v {
c.t.Fatal("!ok")
}
}
func (c *Checker) assertEq(a, b interface{}) {
c.t.Helper()
if !reflect.DeepEqual(a, b) {
c.t.Fatal("!eq:\n", pretty.Compare(a, b))
}
}
/*
type tTxnRecord struct {
tid zodb.Tid
// data records for oid changed in transaction
// .oid↑
datav []tDataRecord
}
type tDataRecord struct {
oid zodb.Oid
data []byte
}
if xid.TidBefore {
// find max txn with .tid < xid.Tid
n := len(s.txnv)
i := n - 1 - sort.Search(n, func(i int) bool {
return s.txnv[n - 1 - i].tid < xid.Tid
})
if i == -1 {
// XXX xid.Tid < all .tid - no such 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