Commit 75a9a26b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent de0d5028
...@@ -283,7 +283,6 @@ func (fs *FileStorage) Load(_ context.Context, xid zodb.Xid) (data *zodb.Buf, ti ...@@ -283,7 +283,6 @@ func (fs *FileStorage) Load(_ context.Context, xid zodb.Xid) (data *zodb.Buf, ti
// be of first-found transaction // be of first-found transaction
tid = dh.Tid tid = dh.Tid
// TODO data -> slab
data, err = dh.LoadData(fs.file) data, err = dh.LoadData(fs.file)
if err != nil { if err != nil {
return nil, 0, &ErrXidLoad{xid, err} return nil, 0, &ErrXidLoad{xid, err}
...@@ -315,7 +314,7 @@ type zIter struct { ...@@ -315,7 +314,7 @@ type zIter struct {
dhLoading DataHeader dhLoading DataHeader
sri zodb.StorageRecordInformation // ptr to this will be returned by .NextData sri zodb.StorageRecordInformation // ptr to this will be returned by .NextData
dataBuf []byte dataBuf *zodb.Buf
} }
type zIterFlags int type zIterFlags int
...@@ -369,17 +368,22 @@ func (zi *zIter) NextData() (*zodb.StorageRecordInformation, error) { ...@@ -369,17 +368,22 @@ func (zi *zIter) NextData() (*zodb.StorageRecordInformation, error) {
// 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
zi.dhLoading = zi.iter.Datah zi.dhLoading = zi.iter.Datah
zi.sri.Data = zi.dataBuf if zi.dataBuf != nil {
err = zi.dhLoading.LoadData(zi.iter.R, &zi.sri.Data) zi.dataBuf.Free()
zi.dataBuf = nil
}
// zi.sri.Data = zi.dataBuf
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 // // if memory was reallocated - use it next time
if cap(zi.sri.Data) > cap(zi.dataBuf) { // if cap(zi.sri.Data) > cap(zi.dataBuf) {
zi.dataBuf = zi.sri.Data // zi.dataBuf = zi.sri.Data
} // }
zi.sri.Data = zi.dataBuf.Data
zi.sri.DataTid = zi.dhLoading.Tid zi.sri.DataTid = zi.dhLoading.Tid
return &zi.sri, nil return &zi.sri, nil
} }
......
...@@ -75,15 +75,15 @@ type oidLoadedOk struct { ...@@ -75,15 +75,15 @@ type oidLoadedOk struct {
// checkLoad verifies that fs.Load(xid) returns expected result // checkLoad verifies that fs.Load(xid) returns expected result
func checkLoad(t *testing.T, fs *FileStorage, xid zodb.Xid, expect oidLoadedOk) { func checkLoad(t *testing.T, fs *FileStorage, xid zodb.Xid, expect oidLoadedOk) {
data, tid, err := fs.Load(context.Background(), xid) buf, tid, err := fs.Load(context.Background(), xid)
if err != nil { if err != nil {
t.Errorf("load %v: %v", xid, err) t.Errorf("load %v: %v", xid, err)
} }
if tid != expect.tid { if tid != expect.tid {
t.Errorf("load %v: returned tid unexpected: %v ; want: %v", xid, tid, expect.tid) t.Errorf("load %v: returned tid unexpected: %v ; want: %v", xid, tid, expect.tid)
} }
if !reflect.DeepEqual(data, expect.data) { // NOTE reflect to catch nil != "" if !reflect.DeepEqual(buf.Data, expect.data) { // NOTE reflect to catch nil != ""
t.Errorf("load %v: different data:\nhave: %q\nwant: %q", xid, data, expect.data) t.Errorf("load %v: different data:\nhave: %q\nwant: %q", xid, buf.Data, expect.data)
} }
} }
......
...@@ -132,7 +132,7 @@ type DumperFsDump struct { ...@@ -132,7 +132,7 @@ type DumperFsDump struct {
// for loading data // for loading data
dhLoading fs1.DataHeader dhLoading fs1.DataHeader
data []byte // data []byte
} }
func (d *DumperFsDump) DumperName() string { func (d *DumperFsDump) DumperName() string {
...@@ -174,30 +174,30 @@ func (d *DumperFsDump) DumpTxn(buf *xfmt.Buffer, it *fs1.Iter) error { ...@@ -174,30 +174,30 @@ func (d *DumperFsDump) DumpTxn(buf *xfmt.Buffer, it *fs1.Iter) error {
// load actual data // load actual data
d.dhLoading = *dh d.dhLoading = *dh
data := d.data dataBuf, err := d.dhLoading.LoadData(it.R)
err = d.dhLoading.LoadData(it.R, &data)
if err != nil { if err != nil {
return err return err
} }
// if memory was reallocated - use it next time
if cap(data) > cap(d.data) {
d.data = data
}
if data == nil { if dataBuf == nil {
buf .S(" class=undo or abort of object creation") buf .S(" class=undo or abort of object creation")
} else { } else {
fullclass := zodb.PyData(data).ClassName() fullclass := zodb.PyData(dataBuf.Data).ClassName()
buf .S(" size=") .D64(d.dhLoading.DataLen) buf .S(" size=") .D64(d.dhLoading.DataLen)
buf .S(" class=") .S(fullclass) buf .S(" class=") .S(fullclass)
} }
if dh.DataLen == 0 && data != nil { if dh.DataLen == 0 && dataBuf != nil {
// it was backpointer - print tid of transaction it points to // it was backpointer - print tid of transaction it points to
buf .S(" bp=") .V(d.dhLoading.Tid) buf .S(" bp=") .V(d.dhLoading.Tid)
} }
// XXX avoid `if != nil`
if dataBuf != nil {
dataBuf.Free()
}
buf .S("\n") buf .S("\n")
} }
......
...@@ -156,7 +156,7 @@ type IStorage interface { ...@@ -156,7 +156,7 @@ type IStorage interface {
// //
// XXX zodb.loadBefore() returns (data, serial, serial_next) -> add serial_next? // XXX zodb.loadBefore() returns (data, serial, serial_next) -> add serial_next?
// //
// XXX currently deleted data is returned as data=nil -- is it ok? // XXX currently deleted data is returned as data.Data=nil -- is it ok?
// TODO specify error when data not found -> ErrOidMissing | ErrXidMissing // TODO specify error when data not found -> ErrOidMissing | ErrXidMissing
Load(ctx context.Context, xid Xid) (data *Buf, serial Tid, err error) // XXX -> StorageRecordInformation ? Load(ctx context.Context, xid Xid) (data *Buf, serial Tid, err error) // XXX -> StorageRecordInformation ?
......
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