Commit 9cbf4ac2 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 78391c92
...@@ -13,8 +13,6 @@ const ( ...@@ -13,8 +13,6 @@ const (
INVALID_TID zodb.Tid = 1<<64 - 1 // 0xffffffffffffffff INVALID_TID zodb.Tid = 1<<64 - 1 // 0xffffffffffffffff
INVALID_OID zodb.Oid = 1<<64 - 1 INVALID_OID zodb.Oid = 1<<64 - 1
// // XXX vvv move to ZODB ?
ZERO_OID zodb.Oid = 0 // XXX or simply OID{} ? // XXX -> OID0
// OID_LEN = 8 // OID_LEN = 8
// TID_LEN = 8 // TID_LEN = 8
) )
...@@ -45,22 +45,19 @@ func fsIndexNew() *fsIndex { ...@@ -45,22 +45,19 @@ func fsIndexNew() *fsIndex {
} }
// TODO Encode (__getstate__) ?
// TODO Decode (__setstate__) ?
// NOTE Get/Set/... are taken as-is from fsb.Tree // NOTE Get/Set/... are taken as-is from fsb.Tree
// on-disk index format // on-disk index format
// (changed in 2010 in https://github.com/zopefoundation/ZODB/commit/1bb14faf) // (changed in 2010 in https://github.com/zopefoundation/ZODB/commit/1bb14faf)
// //
// topPos position pointing just past the last committed transaction // topPos position pointing just past the last committed transaction
// (oid[:6], v.toString) # ._data[oid]-> v (fsBucket().toString()) // (oid[:6], fsBucket)
// (oid[:6], v.toString) // (oid[:6], fsBucket)
// ... // ...
// None // None
// //
// //
// fsBucket.toString(): // fsBucket:
// oid[6:8]oid[6:8]oid[6:8]...pos[0:6]pos[0:6]pos[0:6]... // oid[6:8]oid[6:8]oid[6:8]...pos[0:6]pos[0:6]pos[0:6]...
...@@ -103,7 +100,7 @@ func (fsi *fsIndex) Save(topPos int64, w io.Writer) error { ...@@ -103,7 +100,7 @@ func (fsi *fsIndex) Save(topPos int64, w io.Writer) error {
oid, pos, errStop := e.Next() oid, pos, errStop := e.Next()
oidPrefix := oid & oidPrefixMask oidPrefix := oid & oidPrefixMask
if oidPrefix != oidPrefixCur { if oidPrefix != oidPrefixCur || errStop != nil {
// emit (oid[:6], oid[6:8]oid[6:8]...pos[0:6]pos[0:6]...) // emit (oid[:6], oid[6:8]oid[6:8]...pos[0:6]pos[0:6]...)
binary.BigEndian.PutUint64(oidb[:], uint64(oid)) binary.BigEndian.PutUint64(oidb[:], uint64(oid))
t[0] = oidb[0:6] t[0] = oidb[0:6]
......
...@@ -3,12 +3,92 @@ ...@@ -3,12 +3,92 @@
package fs1 package fs1
import ( import (
"sort"
"testing" "testing"
"../../zodb"
) )
type indexEntry struct {
oid zodb.Oid
pos int64
}
type byOid []indexEntry
func (p byOid) Len() int { return len(p) }
func (p byOid) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p byOid) Less(i, j int) bool { return p[i].oid < p[j].oid }
func TestIndexLookup(t *testing.T) { func TestIndexLookup(t *testing.T) {
// the lookup is tested in cznic.b itself // the lookup is tested in cznic.b itself
// here we only lightly excersize it // here we only lightly exercise it
fsi := fsIndexNew()
if fsi.Len() != 0 {
t.Errorf("index created non empty")
}
tt := [...]indexEntry {
{0x0000000000000000, 111},
{0x0000000000000001, 222},
{0x000000000000ffff, 333},
{0x0000000000001234, 444},
{0x0000000000010002, 555},
{0x0000000000010001, 665},
{0xffffffffffffffff, 777},
{0xfffffffffffffff0, 888},
{0x8000000000000000, 999},
{0xa000000000000000, 0x7fffffffffffffff},
}
// set
for _, entry := range tt {
fsi.Set(entry.oid, entry.pos)
}
// get
for _, entry := range tt {
pos, ok := fsi.Get(entry.oid)
if !(pos == entry.pos && ok == true) {
t.Errorf("fsi[%x] -> got (%x, %v) ; want (%x, true)", entry.oid, pos, ok, entry.pos)
}
// try non-existing entries too
oid := entry.oid ^ (1<<32)
pos, ok = fsi.Get(oid)
if !(pos == 0 && ok == false) {
t.Errorf("fsi[%x] -> got (%x, %v) ; want (0, false)", oid, pos, ok)
}
}
// iter
e, err := fsi.SeekFirst()
if err != nil {
t.Fatal(err)
}
sort.Sort(byOid(tt[:]))
i := 0
for ;; i++ {
oid, pos, errStop := e.Next()
if errStop != nil {
break
}
entry := indexEntry{oid, pos}
entryOk := tt[i]
if entry != entryOk {
t.Errorf("iter step %d: got %v ; want %v", i, entry, entryOk)
}
}
if i != len(tt) {
t.Errorf("iter ended at step %v ; want %v", i, len(tt))
}
} }
......
...@@ -17,10 +17,12 @@ type Xid struct { ...@@ -17,10 +17,12 @@ type Xid struct {
*/ */
const ( const (
Tid0 Tid = 0 Tid0 Tid = 0 // XXX or simply Tid(0) ?
TidMax Tid = 1<<63 - 1 // 0x7fffffffffffffff TidMax Tid = 1<<63 - 1 // 0x7fffffffffffffff
// ZODB defines maxtid to be max signed int64 since baee84a6 (Jun 7 2016) // ZODB defines maxtid to be max signed int64 since baee84a6 (Jun 7 2016)
// (XXX in neo: SQLite does not accept numbers above 2^63-1) // (XXX in neo: SQLite does not accept numbers above 2^63-1)
Oid0 Oid = 0
) )
// ---------------------------------------- // ----------------------------------------
......
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