Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
7b9e2c5d
Commit
7b9e2c5d
authored
Jan 11, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X zodb: Generalize LoadError -> OpError to be returned by all ZODB operations
parent
5886aad3
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
53 additions
and
30 deletions
+53
-30
go/neo/client/client.go
go/neo/client/client.go
+6
-3
go/neo/server/cluster_test.go
go/neo/server/cluster_test.go
+5
-4
go/neo/server/storage.go
go/neo/server/storage.go
+1
-1
go/zodb/cache.go
go/zodb/cache.go
+6
-3
go/zodb/cache_test.go
go/zodb/cache_test.go
+2
-2
go/zodb/open.go
go/zodb/open.go
+1
-1
go/zodb/storage/fs1/filestorage.go
go/zodb/storage/fs1/filestorage.go
+12
-3
go/zodb/storage/fs1/filestorage_test.go
go/zodb/storage/fs1/filestorage_test.go
+5
-4
go/zodb/zodb.go
go/zodb/zodb.go
+15
-9
No files found.
go/neo/client/client.go
View file @
7b9e2c5d
...
...
@@ -33,7 +33,6 @@ import (
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
"lab.nexedi.com/kirr/go123/mem"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/go123/xnet"
"lab.nexedi.com/kirr/neo/go/neo"
...
...
@@ -362,7 +361,11 @@ func (c *Client) initFromMaster(ctx context.Context, mlink *neo.NodeLink) (err e
// --- user API calls ---
func
(
c
*
Client
)
LastTid
(
ctx
context
.
Context
)
(
_
zodb
.
Tid
,
err
error
)
{
defer
xerr
.
Context
(
&
err
,
"client: lastTid"
)
defer
func
()
{
if
err
!=
nil
{
err
=
&
zodb
.
OpError
{
URL
:
c
.
URL
(),
Op
:
"last_tid"
,
Args
:
nil
,
Err
:
err
}
}
}()
// XXX or require full withOperational ?
mlink
,
err
:=
c
.
masterLink
(
ctx
)
...
...
@@ -389,7 +392,7 @@ func (c *Client) Load(ctx context.Context, xid zodb.Xid) (buf *mem.Buf, serial z
// defer func() ...
buf
,
serial
,
err
=
c
.
_Load
(
ctx
,
xid
)
if
err
!=
nil
{
err
=
&
zodb
.
LoadError
{
URL
:
c
.
URL
(),
Xid
:
xid
,
Err
:
err
}
err
=
&
zodb
.
OpError
{
URL
:
c
.
URL
(),
Op
:
"load"
,
Args
:
xid
,
Err
:
err
}
}
return
buf
,
serial
,
err
}
...
...
go/neo/server/cluster_test.go
View file @
7b9e2c5d
...
...
@@ -515,10 +515,11 @@ func TestMasterStorage(t *testing.T) {
}
}
else
{
// deleted
errWant
:=
&
zodb
.
LoadError
{
URL
:
C
.
URL
(),
Xid
:
xid
,
Err
:
&
zodb
.
NoDataError
{
Oid
:
xid
.
Oid
,
DeletedAt
:
datai
.
Tid
},
errWant
:=
&
zodb
.
OpError
{
URL
:
C
.
URL
(),
Op
:
"load"
,
Args
:
xid
,
Err
:
&
zodb
.
NoDataError
{
Oid
:
xid
.
Oid
,
DeletedAt
:
datai
.
Tid
},
}
if
!
(
buf
==
nil
&&
serial
==
0
&&
reflect
.
DeepEqual
(
err
,
errWant
))
{
t
.
Fatalf
(
"load: %v ->
\n
buf:
\n
%s
\n
serial:
\n
%s
\n
err:
\n
%s
\n
"
,
xid
,
...
...
go/neo/server/storage.go
View file @
7b9e2c5d
...
...
@@ -551,7 +551,7 @@ func (stor *Storage) serveClient1(ctx context.Context, req neo.Msg) (resp neo.Ms
buf
,
serial
,
err
:=
stor
.
zstor
.
Load
(
ctx
,
xid
)
if
err
!=
nil
{
// translate err to NEO protocol error codes
e
:=
err
.
(
*
zodb
.
Load
Error
)
// XXX move this to ErrEncode?
e
:=
err
.
(
*
zodb
.
Op
Error
)
// XXX move this to ErrEncode?
return
neo
.
ErrEncode
(
e
.
Err
)
}
...
...
go/zodb/cache.go
View file @
7b9e2c5d
...
...
@@ -169,7 +169,7 @@ func (c *Cache) Load(ctx context.Context, xid Xid) (buf *mem.Buf, serial Tid, er
}
if
rce
.
err
!=
nil
{
return
nil
,
0
,
&
LoadError
{
URL
:
c
.
loader
.
URL
(),
Xid
:
xid
,
Err
:
rce
.
err
}
return
nil
,
0
,
&
OpError
{
URL
:
c
.
loader
.
URL
(),
Op
:
"load"
,
Args
:
xid
,
Err
:
rce
.
err
}
}
return
rce
.
buf
,
rce
.
serial
,
nil
...
...
@@ -180,6 +180,8 @@ func (c *Cache) Load(ctx context.Context, xid Xid) (buf *mem.Buf, serial Tid, er
// If data is not yet in cache loading for it is started in the background.
// Prefetch is not blocking operation and does not wait for loading, if any was
// started, to complete.
//
// Prefetch does not return any error.
func
(
c
*
Cache
)
Prefetch
(
ctx
context
.
Context
,
xid
Xid
)
{
rce
,
rceNew
:=
c
.
lookupRCE
(
xid
,
+
0
)
...
...
@@ -303,10 +305,11 @@ func (c *Cache) loadRCE(ctx context.Context, rce *revCacheEntry) {
// normalize buf/serial if it was error
if
err
!=
nil
{
e
:=
err
.
(
*
LoadError
)
// XXX better driver return *Load
Error explicitly
e
:=
err
.
(
*
OpError
)
// XXX better driver return *Op
Error explicitly
// only remember problem cause - full
Load
Error will be
// only remember problem cause - full
Op
Error will be
// reconstructed in Load with actual requested there xid.
// XXX check .Op == "load" ?
err
=
e
.
Err
// TODO err == canceled? -> don't remember
buf
.
XRelease
()
...
...
go/zodb/cache_test.go
View file @
7b9e2c5d
...
...
@@ -75,7 +75,7 @@ func (stor *tStorage) Load(_ context.Context, xid Xid) (buf *mem.Buf, serial Tid
//defer func() { fmt.Printf("< %v, %v, %v\n", buf.XData(), serial, err) }()
buf
,
serial
,
err
=
stor
.
load
(
xid
)
if
err
!=
nil
{
err
=
&
LoadError
{
URL
:
stor
.
URL
(),
Xid
:
xid
,
Err
:
err
}
err
=
&
OpError
{
URL
:
stor
.
URL
(),
Op
:
"load"
,
Args
:
xid
,
Err
:
err
}
}
return
buf
,
serial
,
err
}
...
...
@@ -163,7 +163,7 @@ func TestCache(t *testing.T) {
var
err
error
if
errCause
!=
nil
{
err
=
&
LoadError
{
URL
:
"test"
,
Xid
:
xid
,
Err
:
errCause
}
err
=
&
OpError
{
URL
:
"test"
,
Op
:
"load"
,
Args
:
xid
,
Err
:
errCause
}
}
if
!
reflect
.
DeepEqual
(
err
,
e
)
{
fmt
.
Fprintf
(
bad
,
"err:
\n
%s
\n
"
,
pretty
.
Compare
(
err
,
e
))
...
...
go/zodb/open.go
View file @
7b9e2c5d
...
...
@@ -105,7 +105,7 @@ type storage struct {
func
(
s
*
storage
)
Load
(
ctx
context
.
Context
,
xid
Xid
)
(
*
mem
.
Buf
,
Tid
,
error
)
{
// XXX here: offload xid validation from cache and driver ?
// XXX here: offload wrapping err ->
LoadError{
err} ?
// XXX here: offload wrapping err ->
OpError{"load",
err} ?
return
s
.
l1cache
.
Load
(
ctx
,
xid
)
}
...
...
go/zodb/storage/fs1/filestorage.go
View file @
7b9e2c5d
...
...
@@ -131,7 +131,7 @@ func (fs *FileStorage) Load(_ context.Context, xid zodb.Xid) (buf *mem.Buf, seri
// -> TODO reject tid out of range
buf
,
serial
,
err
=
fs
.
load
(
xid
)
if
err
!=
nil
{
err
=
&
zodb
.
LoadError
{
URL
:
fs
.
URL
(),
Xid
:
xid
,
Err
:
err
}
err
=
&
zodb
.
OpError
{
URL
:
fs
.
URL
(),
Op
:
"load"
,
Args
:
xid
,
Err
:
err
}
}
return
buf
,
serial
,
err
}
...
...
@@ -218,6 +218,7 @@ const (
// NextTxn iterates to next/previous transaction record according to iteration direction
func
(
zi
*
zIter
)
NextTxn
(
_
context
.
Context
)
(
*
zodb
.
TxnInfo
,
zodb
.
IDataIterator
,
error
)
{
// TODO err -> OpError("iter", tidmin..tidmax)
switch
{
case
zi
.
zFlags
&
zIterEOF
!=
0
:
return
nil
,
nil
,
io
.
EOF
...
...
@@ -245,6 +246,7 @@ func (zi *zIter) NextTxn(_ context.Context) (*zodb.TxnInfo, zodb.IDataIterator,
// NextData iterates to next data record and loads data content
func
(
zi
*
zIter
)
NextData
(
_
context
.
Context
)
(
*
zodb
.
DataInfo
,
error
)
{
// TODO err -> OpError("iter", tidmin..tidmax)
err
:=
zi
.
iter
.
NextData
()
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -381,7 +383,14 @@ func (fs *FileStorage) Iterate(tidMin, tidMax zodb.Tid) zodb.ITxnIterator {
return
ziter
case
err
!=
nil
:
return
&
iterStartError
{
err
}
return
&
iterStartError
{
&
zodb
.
OpError
{
URL
:
fs
.
URL
(),
Op
:
"iter"
,
// XXX (?) add TidRange type which prints as
// "tidmin..tidmax" with omiting ends if it is either 0 or ∞
Args
:
[]
zodb
.
Tid
{
tidMin
,
tidMax
},
Err
:
err
,
}}
}
// setup iter from what findTxnRecord found
...
...
@@ -498,7 +507,7 @@ func Open(ctx context.Context, path string) (_ *FileStorage, err error) {
func
(
fs
*
FileStorage
)
Close
()
error
{
err
:=
fs
.
file
.
Close
()
if
err
!=
nil
{
return
err
return
&
zodb
.
OpError
{
URL
:
fs
.
URL
(),
Op
:
"close"
,
Args
:
nil
,
Err
:
err
}
}
// TODO if opened !ro -> .saveIndex()
...
...
go/zodb/storage/fs1/filestorage_test.go
View file @
7b9e2c5d
...
...
@@ -70,10 +70,11 @@ func checkLoad(t *testing.T, fs *FileStorage, xid zodb.Xid, expect objState) {
// deleted obj - it should load with "no data"
if
expect
.
data
==
nil
{
errOk
:=
&
zodb
.
LoadError
{
URL
:
fs
.
URL
(),
Xid
:
xid
,
Err
:
&
zodb
.
NoDataError
{
Oid
:
xid
.
Oid
,
DeletedAt
:
expect
.
tid
},
errOk
:=
&
zodb
.
OpError
{
URL
:
fs
.
URL
(),
Op
:
"load"
,
Args
:
xid
,
Err
:
&
zodb
.
NoDataError
{
Oid
:
xid
.
Oid
,
DeletedAt
:
expect
.
tid
},
}
if
!
reflect
.
DeepEqual
(
err
,
errOk
)
{
t
.
Errorf
(
"load %v: returned err unexpected: %v ; want: %v"
,
xid
,
err
,
errOk
)
...
...
go/zodb/zodb.go
View file @
7b9e2c5d
...
...
@@ -147,18 +147,24 @@ func (e *NoDataError) Error() string {
}
}
// LoadError is the error returned by IStorageDriver.Load
type
LoadError
struct
{
URL
string
Xid
Xid
Err
error
// OpError is the error returned by IStorageDriver operations
type
OpError
struct
{
URL
string
// URL of the storage
Op
string
// operation that failed
Args
interface
{}
// operation arguments, if any
Err
error
// actual error that occured during the operation
}
func
(
e
*
LoadError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"%s: load %s: %v"
,
e
.
URL
,
e
.
Xid
,
e
.
Err
)
func
(
e
*
OpError
)
Error
()
string
{
s
:=
e
.
URL
+
": "
+
e
.
Op
if
e
.
Args
!=
nil
{
s
+=
fmt
.
Sprintf
(
" %s"
,
e
.
Args
)
}
s
+=
": "
+
e
.
Err
.
Error
()
return
s
}
func
(
e
*
Load
Error
)
Cause
()
error
{
func
(
e
*
Op
Error
)
Cause
()
error
{
return
e
.
Err
}
...
...
@@ -204,7 +210,7 @@ type IStorageDriver interface {
// - if there is data to load: buf is non-empty, serial indicates
// transaction which matched xid criteria and err=nil.
//
// otherwise buf=nil, serial=0 and err is *
Load
Error with err.Err
// otherwise buf=nil, serial=0 and err is *
Op
Error with err.Err
// describing the error cause:
//
// - *NoObjectError if there is no such object in database at all,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment