Commit 6ae2604b authored by Kirill Smelkov's avatar Kirill Smelkov

X zodb: Clarify load semantic: for deleted data err="no data" and buf, serial = nil, 0

parent 75dc3060
...@@ -89,10 +89,11 @@ func (stor *tStorage) Load(_ context.Context, xid zodb.Xid) (buf *zodb.Buf, seri ...@@ -89,10 +89,11 @@ func (stor *tStorage) Load(_ context.Context, xid zodb.Xid) (buf *zodb.Buf, seri
} }
s, e := datav[i].serial, datav[i].err s, e := datav[i].serial, datav[i].err
b := mkbuf(datav[i].data)
if e != nil { if e != nil {
s = 0 // obey protocol of returning 0 with error b, s = nil, 0 // obey protocol of returning nil, 0 with error
} }
return mkbuf(datav[i].data), s, e return b, s, e
} }
var ioerr = errors.New("input/output error") var ioerr = errors.New("input/output error")
......
...@@ -146,7 +146,7 @@ func (dh *DataHeader) Free() { ...@@ -146,7 +146,7 @@ func (dh *DataHeader) Free() {
dhPool.Put(dh) dhPool.Put(dh)
} }
func (fs *FileStorage) Load(_ context.Context, xid zodb.Xid) (buf *zodb.Buf, tid zodb.Tid, err error) { func (fs *FileStorage) Load(_ context.Context, xid zodb.Xid) (buf *zodb.Buf, serial zodb.Tid, err error) {
// lookup in index position of oid data record within latest transaction which changed this oid // lookup in index position of oid data record within latest transaction which changed this oid
dataPos, ok := fs.index.Get(xid.Oid) dataPos, ok := fs.index.Get(xid.Oid)
if !ok { if !ok {
...@@ -162,9 +162,9 @@ func (fs *FileStorage) Load(_ context.Context, xid zodb.Xid) (buf *zodb.Buf, tid ...@@ -162,9 +162,9 @@ func (fs *FileStorage) Load(_ context.Context, xid zodb.Xid) (buf *zodb.Buf, tid
dh.Tid = zodb.TidMax dh.Tid = zodb.TidMax
dh.PrevRevPos = dataPos dh.PrevRevPos = dataPos
//defer dh.Free() //defer dh.Free()
buf, tid, err = fs._Load(dh, xid) buf, serial, err = fs._Load(dh, xid)
dh.Free() dh.Free()
return buf, tid, err return buf, serial, err
} }
func (fs *FileStorage) _Load(dh *DataHeader, xid zodb.Xid) (*zodb.Buf, zodb.Tid, error) { func (fs *FileStorage) _Load(dh *DataHeader, xid zodb.Xid) (*zodb.Buf, zodb.Tid, error) {
...@@ -187,9 +187,9 @@ func (fs *FileStorage) _Load(dh *DataHeader, xid zodb.Xid) (*zodb.Buf, zodb.Tid, ...@@ -187,9 +187,9 @@ func (fs *FileStorage) _Load(dh *DataHeader, xid zodb.Xid) (*zodb.Buf, zodb.Tid,
} }
} }
// even if we will scan back via backpointers, the tid returned should // even if we will scan back via backpointers, the serial returned should
// be of first-found transaction // be of first-found transaction
tid := dh.Tid serial := dh.Tid
buf, err := dh.LoadData(fs.file) buf, err := dh.LoadData(fs.file)
if err != nil { if err != nil {
...@@ -200,7 +200,7 @@ func (fs *FileStorage) _Load(dh *DataHeader, xid zodb.Xid) (*zodb.Buf, zodb.Tid, ...@@ -200,7 +200,7 @@ func (fs *FileStorage) _Load(dh *DataHeader, xid zodb.Xid) (*zodb.Buf, zodb.Tid,
return nil, 0, &zodb.ErrXidMissing{Xid: xid} return nil, 0, &zodb.ErrXidMissing{Xid: xid}
} }
return buf, tid, nil return buf, serial, nil
} }
// --- ZODB-level iteration --- // --- ZODB-level iteration ---
......
...@@ -657,7 +657,7 @@ func (dh *DataHeader) loadNext(r io.ReaderAt, txnh *TxnHeader) error { ...@@ -657,7 +657,7 @@ func (dh *DataHeader) loadNext(r io.ReaderAt, txnh *TxnHeader) error {
// LoadData loads data for the data record taking backpointers into account. // LoadData loads data for the data record taking backpointers into account.
// //
// NOTE on success dh state is changed to data header of original data transaction. // NOTE on success dh state is changed to data header of original data transaction.
// NOTE "deleted" records are indicated via returning buf with .Data=nil. // NOTE "deleted" records are indicated via returning buf with .Data=nil without error.
func (dh *DataHeader) LoadData(r io.ReaderAt) (*zodb.Buf, error) { func (dh *DataHeader) LoadData(r io.ReaderAt) (*zodb.Buf, error) {
// scan via backpointers // scan via backpointers
for dh.DataLen == 0 { for dh.DataLen == 0 {
......
...@@ -160,7 +160,6 @@ type IStorage interface { ...@@ -160,7 +160,6 @@ type IStorage interface {
// Load loads object data addressed by xid from database. // Load loads object data addressed by xid from database.
// //
// XXX currently deleted data is returned as buf.Data=nil -- is it ok?
// TODO specify error when data not found -> ErrOidMissing | ErrXidMissing // TODO specify error when data not found -> ErrOidMissing | ErrXidMissing
// //
// NOTE ZODB/py provides 2 entrypoints in IStorage for loading: // NOTE ZODB/py provides 2 entrypoints in IStorage for loading:
......
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