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
0419e890
Commit
0419e890
authored
Mar 04, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
1160f6b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
22 deletions
+44
-22
go/zodb/db.go
go/zodb/db.go
+44
-22
No files found.
go/zodb/db.go
View file @
0419e890
...
...
@@ -22,13 +22,13 @@ package zodb
import
(
"context"
"fmt"
"sort"
"sync"
"time"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/neo/go/transaction"
"fmt"
)
// DB represents a handle to database at application level and contains pool
...
...
@@ -48,6 +48,10 @@ type DB struct {
stor
IStorage
watchq
chan
Event
// we are watching .stor via here
down
chan
struct
{}
// ready when DB is no longer operational
downOnce
sync
.
Once
// shutdown may be due to both Close and IO error in watcher
downErr
error
// reason for shutdown
mu
sync
.
Mutex
// pool of unused connections.
...
...
@@ -122,6 +126,7 @@ func NewDB(stor IStorage) *DB {
db
:=
&
DB
{
stor
:
stor
,
watchq
:
make
(
chan
Event
),
down
:
make
(
chan
struct
{}),
δwait
:
make
(
map
[
δwaiter
]
struct
{}),
tδkeep
:
10
*
time
.
Minute
,
// see δtail discussion
...
...
@@ -134,19 +139,25 @@ func NewDB(stor IStorage) *DB {
return
db
}
// XXX DB.shutdown(reason error) ?
// shutdown mark db no longer operational due to reason.
//
// It serves both explicit Close, or shutdown triggered due to error received
// by watcher.
func
(
db
*
DB
)
shutdown
(
reason
error
)
{
db
.
downOnce
.
Do
(
func
()
{
db
.
downErr
=
reason
// XXX err ctx
close
(
db
.
down
)
db
.
stor
.
DelWatch
(
db
.
watchq
)
})
}
// Close closes database handle.
//
// After Close DB.Open calls will return error. However it is ok to continue
// working with connections opened prior Close.
func
(
db
*
DB
)
Close
()
error
{
db
.
mu
.
Lock
()
defer
db
.
mu
.
Unlock
()
stor
.
DelWatch
(
db
.
watchq
)
// XXX stub
db
.
shutdown
(
fmt
.
Errorf
(
"db is closed"
))
return
nil
}
...
...
@@ -195,14 +206,23 @@ type δwaiter struct {
// watcher receives events about new committed transactions and updates δtail.
//
// it also notifies δtail waiters.
func
(
db
*
DB
)
watcher
()
{
// XXX err ?
func
(
db
*
DB
)
watcher
()
(
err
error
)
{
defer
db
.
shutdown
(
err
)
defer
xerr
.
Contextf
(
&
err
,
"db: watcher"
)
var
event
Event
var
ok
bool
for
{
// XXX check for db.down
event
,
ok
:=
<-
db
.
watchq
if
!
ok
{
fmt
.
Printf
(
"db: watcher: close
\n
"
)
// XXX wake up all waiters?
return
// closed
select
{
case
<-
db
.
down
:
// should be already shut down with concrete reason
return
fmt
.
Errorf
(
"db is down"
)
case
event
,
ok
=
<-
db
.
watchq
:
if
!
ok
{
return
fmt
.
Errorf
(
"storage closed"
)
}
}
//fmt.Printf("db: watcher <- %v\n", event)
...
...
@@ -213,8 +233,7 @@ func (db *DB) watcher() { // XXX err ?
panic
(
fmt
.
Sprintf
(
"unexepected event: %T"
,
event
))
case
*
EventError
:
fmt
.
Printf
(
"db: watcher: error: %s
\n
"
,
event
.
Err
)
continue
// XXX shutdown instead
return
fmt
.
Errorf
(
"error: %s"
,
event
.
Err
)
case
*
EventCommit
:
δ
=
event
...
...
@@ -360,14 +379,17 @@ retry:
db
.
mu
.
Unlock
()
select
{
case
<-
ctx
.
Done
()
:
// leave db.mu unlocked
return
nil
,
ctx
.
Err
()
case
<-
δready
:
// ok - δtail.head went over at; relock db and retry
db
.
mu
.
Lock
()
continue
retry
// on error leave db.mu unlocked
case
<-
ctx
.
Done
()
:
return
nil
,
ctx
.
Err
()
case
<-
db
.
down
:
return
nil
,
db
.
downErr
}
}
...
...
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