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