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
1160f6b3
Commit
1160f6b3
authored
Mar 04, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
4ebf39a5
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
10 deletions
+39
-10
go/zodb/btree/btree_test.go
go/zodb/btree/btree_test.go
+3
-0
go/zodb/db.go
go/zodb/db.go
+31
-10
go/zodb/persistent_test.go
go/zodb/persistent_test.go
+3
-0
go/zodb/zodb.go
go/zodb/zodb.go
+2
-0
No files found.
go/zodb/btree/btree_test.go
View file @
1160f6b3
...
...
@@ -106,6 +106,9 @@ func TestBTree(t *testing.T) {
t
.
Fatal
(
err
)
}
db
:=
zodb
.
NewDB
(
stor
)
defer
func
()
{
err
:=
db
.
Close
();
X
(
err
)
}()
txn
,
ctx
:=
transaction
.
New
(
ctx
)
defer
txn
.
Abort
()
...
...
go/zodb/db.go
View file @
1160f6b3
...
...
@@ -46,6 +46,7 @@ import (
// DB is safe to access from multiple goroutines simultaneously.
type
DB
struct
{
stor
IStorage
watchq
chan
Event
// we are watching .stor via here
mu
sync
.
Mutex
...
...
@@ -114,25 +115,42 @@ type DB struct {
// NewDB creates new database handle.
//
// Created database handle must be closed when no longer needed.
func
NewDB
(
stor
IStorage
)
*
DB
{
// XXX db options?
db
:=
&
DB
{
stor
:
stor
,
watchq
:
make
(
chan
Event
),
δwait
:
make
(
map
[
δwaiter
]
struct
{}),
tδkeep
:
10
*
time
.
Minute
,
// see δtail discussion
}
watchq
:=
make
(
chan
Event
)
at0
:=
stor
.
AddWatch
(
watchq
)
at0
:=
stor
.
AddWatch
(
db
.
watchq
)
db
.
δtail
=
NewΔTail
(
at0
)
// init to (at0, at0]
go
db
.
watcher
(
watchq
)
// XXX DelWatch? in db.Close() ?
go
db
.
watcher
()
return
db
}
// XXX DB.shutdown(reason error) ?
// 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
return
nil
}
// ConnOptions describes options to DB.Open .
type
ConnOptions
struct
{
At
Tid
// if !0, open Connection bound to `at` view of database; not latest.
...
...
@@ -177,9 +195,10 @@ type δwaiter struct {
// watcher receives events about new committed transactions and updates δtail.
//
// it also notifies δtail waiters.
func
(
db
*
DB
)
watcher
(
watchq
<-
chan
Event
)
{
// XXX err ?
func
(
db
*
DB
)
watcher
()
{
// XXX err ?
for
{
event
,
ok
:=
<-
watchq
// XXX check for db.down
event
,
ok
:=
<-
db
.
watchq
if
!
ok
{
fmt
.
Printf
(
"db: watcher: close
\n
"
)
// XXX wake up all waiters?
...
...
@@ -255,6 +274,8 @@ func (db *DB) Open(ctx context.Context, opt *ConnOptions) (_ *Connection, err er
}
}()
// XXX check db is aready down/closed
txn
:=
transaction
.
Current
(
ctx
)
// find out db state we should open at
...
...
go/zodb/persistent_test.go
View file @
1160f6b3
...
...
@@ -347,6 +347,9 @@ func testPersistentDB(t0 *testing.T, rawcache bool) {
ctx
:=
context
.
Background
()
stor
,
err
:=
OpenStorage
(
ctx
,
zurl
,
&
OpenOptions
{
ReadOnly
:
true
,
NoCache
:
!
rawcache
});
X
(
err
)
db
:=
NewDB
(
stor
)
defer
func
()
{
err
:=
db
.
Close
();
X
(
err
)
}()
// testopen opens new db transaction/connection and wraps it with tPersistentDB.
testopen
:=
func
(
opt
*
ConnOptions
)
*
tPersistentDB
{
...
...
go/zodb/zodb.go
View file @
1160f6b3
...
...
@@ -359,6 +359,8 @@ type IStorageDriver interface {
// LastTid returns the id of the last committed transaction.
//
// If no transactions have been committed yet, LastTid returns 0.
//
// XXX clarify semantic XXX -> Sync + Head ?
LastTid
(
ctx
context
.
Context
)
(
Tid
,
error
)
Loader
...
...
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