Commit f2eb6a5b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e6d7a736
......@@ -472,7 +472,7 @@ func (c *Client) Load(ctx context.Context, xid zodb.Xid) (data *zodb.Buf, serial
return data, resp.Serial, nil
}
func (c *Client) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator {
func (c *Client) Iterate(tidMin, tidMax zodb.Tid) zodb.ITxnIterator {
// see notes in ../NOTES:"On iteration"
panic("TODO")
}
......
......@@ -40,7 +40,7 @@ type Buf struct {
const order0 = 4 // buf sizes start from 2^4 (=16)
var bufPoolv = [14]sync.Pool{} // buf size stop at 2^(4+14-1) (=128K)
var bufPoolv = [19]sync.Pool{} // buf size stop at 2^(4+19-1) (=4M)
func init() {
......
......@@ -30,8 +30,7 @@ func sliceDataPtr(b []byte) unsafe.Pointer {
}
func TestBufAllocFree(t *testing.T) {
for i := uint(0); i < 20; i++ {
//if i < 7 { continue }
for i := uint(0); i < 25; i++ {
size := 1<<i - 1
xcap := 1<<i
buf := BufAlloc(size)
......@@ -49,18 +48,22 @@ func TestBufAllocFree(t *testing.T) {
t.Errorf("%v: cap=%v ; want %v", i, cap(buf.Data), xcap)
}
// this allocations are not from pool - memory won't be reused
if int(i) >= order0 + len(bufPoolv) {
continue
}
// free and allocate another buf -> it must be it
data := buf.Data
buf.Free()
buf2 := BufAlloc(size)
// from pool -> it must be the same
if int(i) < order0 + len(bufPoolv) {
if !(buf2 == buf && sliceDataPtr(buf2.Data) == sliceDataPtr(data)) {
t.Errorf("%v: buffer not reused on free/realloc", i)
}
// not from pool - memory won't be reused
} else {
if buf2 == buf || sliceDataPtr(buf2.Data) == sliceDataPtr(data) {
t.Errorf("%v: buffer reused but should not", i)
}
}
}
}
......@@ -313,7 +313,7 @@ type zIter struct {
// here to avoid allocations )
dhLoading DataHeader
sri zodb.StorageRecordInformation // ptr to this will be returned by .NextData
datai zodb.DataInfo // ptr to this will be returned by .NextData
dataBuf *zodb.Buf
}
......@@ -324,7 +324,7 @@ const (
)
// NextTxn iterates to next/previous transaction record according to iteration direction
func (zi *zIter) NextTxn() (*zodb.TxnInfo, zodb.IStorageRecordIterator, error) {
func (zi *zIter) NextTxn() (*zodb.TxnInfo, zodb.IDataIterator, error) {
switch {
case zi.zFlags & zIterEOF != 0:
//println("already eof")
......@@ -356,14 +356,14 @@ func (zi *zIter) NextTxn() (*zodb.TxnInfo, zodb.IStorageRecordIterator, error) {
}
// NextData iterates to next data record and loads data content
func (zi *zIter) NextData() (*zodb.StorageRecordInformation, error) {
func (zi *zIter) NextData() (*zodb.DataInfo, error) {
err := zi.iter.NextData()
if err != nil {
return nil, err // XXX recheck
}
zi.sri.Oid = zi.iter.Datah.Oid
zi.sri.Tid = zi.iter.Datah.Tid
zi.datai.Oid = zi.iter.Datah.Oid
zi.datai.Tid = zi.iter.Datah.Tid
// NOTE dh.LoadData() changes dh state while going through backpointers -
// - need to use separate dh because of this
......@@ -372,20 +372,14 @@ func (zi *zIter) NextData() (*zodb.StorageRecordInformation, error) {
zi.dataBuf.Free()
zi.dataBuf = nil
}
// zi.sri.Data = zi.dataBuf
zi.dataBuf, err = zi.dhLoading.LoadData(zi.iter.R) //, &zi.sri.Data)
zi.dataBuf, err = zi.dhLoading.LoadData(zi.iter.R)
if err != nil {
return nil, err // XXX recheck
}
// // if memory was reallocated - use it next time
// if cap(zi.sri.Data) > cap(zi.dataBuf) {
// zi.dataBuf = zi.sri.Data
// }
zi.sri.Data = zi.dataBuf.Data
zi.sri.DataTid = zi.dhLoading.Tid
return &zi.sri, nil
zi.datai.Data = zi.dataBuf.Data
zi.datai.DataTid = zi.dhLoading.Tid
return &zi.datai, nil
}
......@@ -400,7 +394,7 @@ type iterStartError struct {
err error
}
func (e *iterStartError) NextTxn() (*zodb.TxnInfo, zodb.IStorageRecordIterator, error) {
func (e *iterStartError) NextTxn() (*zodb.TxnInfo, zodb.IDataIterator, error) {
return nil, nil, e.err
}
......@@ -483,7 +477,7 @@ func (fs *FileStorage) findTxnRecord(r io.ReaderAt, tid zodb.Tid) (TxnHeader, er
}
// Iterate creates zodb-level iterator for tidMin..tidMax range
func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.IStorageIterator {
func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.ITxnIterator {
//fmt.Printf("iterate %v..%v\n", tidMin, tidMax)
// when iterating use IO optimized for sequential access
......
......@@ -218,7 +218,7 @@ func testIterate(t *testing.T, fs *FileStorage, tidMin, tidMax zodb.Tid, expectv
// assert datai pointes to where we expect - this will allow us
// not only to check oid/tid/data but also to check whole data header.
if datai != &fsi.sri {
if datai != &fsi.datai {
t.Fatal("unexpected datai pointer")
}
......
......@@ -53,8 +53,11 @@ const TidMax Tid = 1<<63 - 1 // 0x7fffffffffffffff
// See also: Xid.
type Oid uint64
// TxnMeta is metadata information about one transaction.
type TxnMeta struct {
// TxnInfo is metadata information about one transaction.
//
// XXX naming -> TxnMeta?
// XXX +TxnInfo = TxnMeta + []DataInfo ?
type TxnInfo struct {
Tid Tid
Status TxnStatus
User []byte
......@@ -62,7 +65,6 @@ type TxnMeta struct {
Extension []byte
}
// XXX +TxnInfo = TxnMeta + []DataInfo ?
// DataInfo represents information about one data record.
type DataInfo struct {
......@@ -185,7 +187,7 @@ type ITxnIterator interface {
// 2. iterator over transaction's data records.
// transaction metadata stays valid until next call to NextTxn().
// end of iteration is indicated with io.EOF
NextTxn() (*TxnMeta, IDataIterator, error) // XXX ctx
NextTxn() (*TxnInfo, IDataIterator, error) // XXX ctx
}
// IDataIterator is the interface to iterate data records.
......
......@@ -46,7 +46,7 @@ func Catobj(ctx context.Context, w io.Writer, stor zodb.IStorage, xid zodb.Xid)
// Dumpobj dumps content of one ZODB object with zodbdump-like header
func Dumpobj(ctx context.Context, w io.Writer, stor zodb.IStorage, xid zodb.Xid, hashOnly bool) error {
var objInfo zodb.StorageRecordInformation
var objInfo zodb.DataInfo
buf, tid, err := stor.Load(ctx, xid)
if err != nil {
......
......@@ -67,7 +67,7 @@ var _LF = []byte{'\n'}
// DumpData dumps one data record
// XXX naming -> DumpObj ?
func (d *dumper) DumpData(datai *zodb.StorageRecordInformation) error {
func (d *dumper) DumpData(datai *zodb.DataInfo) error {
buf := &d.buf
buf.Reset()
......@@ -121,8 +121,8 @@ out:
}
// DumpTxn dumps one transaction record
func (d *dumper) DumpTxn(txni *zodb.TxnInfo, dataIter zodb.IStorageRecordIterator) error {
var datai *zodb.StorageRecordInformation
func (d *dumper) DumpTxn(txni *zodb.TxnInfo, dataIter zodb.IDataIterator) error {
var datai *zodb.DataInfo
// LF in-between txn records
vskip := "\n"
......@@ -168,7 +168,7 @@ out:
// Dump dumps transaction records in between tidMin..tidMax
func (d *dumper) Dump(stor zodb.IStorage, tidMin, tidMax zodb.Tid) error {
var txni *zodb.TxnInfo
var dataIter zodb.IStorageRecordIterator
var dataIter zodb.IDataIterator
var err error
iter := stor.Iterate(tidMin, tidMax)
......
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