Commit ea5f2687 authored by Kirill Smelkov's avatar Kirill Smelkov

zodb: NewDB += option to set live cache control on created connections

WCFS needs this to run tests faster.

In general it is also a good idea to pass options to DB constructor, in
particular options that affect live cache size, or other properties, for
further created connections.
parent 890290e6
// Copyright (C) 2018-2019 Nexedi SA and Contributors.
// Copyright (C) 2018-2021 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -105,7 +105,7 @@ func TestBTree(t *testing.T) {
if err != nil {
t.Fatal(err)
}
db := zodb.NewDB(stor)
db := zodb.NewDB(stor, &zodb.DBOptions{})
defer func() {
err := db.Close(); X(err)
}()
......
// Copyright (C) 2018-2020 Nexedi SA and Contributors.
// Copyright (C) 2018-2021 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -180,7 +180,7 @@ const (
// newConnection creates new Connection associated with db.
func newConnection(db *DB, at Tid) *Connection {
return &Connection{
conn := &Connection{
db: db,
at: at,
cache: LiveCache{
......@@ -188,6 +188,10 @@ func newConnection(db *DB, at Tid) *Connection {
objtab: make(map[Oid]*weak.Ref),
},
}
if cc := db.opt.CacheControl; cc != nil {
conn.cache.SetControl(cc)
}
return conn
}
// DB returns database handle under which the connection was opened.
......
// Copyright (C) 2018-2020 Nexedi SA and Contributors.
// Copyright (C) 2018-2021 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -48,6 +48,8 @@ type DB struct {
stor IStorage
watchq chan Event // we are watching .stor via here
opt *DBOptions
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
......@@ -121,15 +123,23 @@ type DB struct {
// (so it is not duplicated many times for many DB case)
}
// DBOptions describes options to NewDB.
type DBOptions struct {
// CacheControl, if !nil, is set as default live cache control for
// newly created connections.
CacheControl LiveCacheControl
}
// NewDB creates new database handle.
//
// Created database handle must be closed when no longer needed.
func NewDB(stor IStorage) *DB {
// XXX db options?
func NewDB(stor IStorage, opt *DBOptions) *DB {
// copy opts in case caller will change them later
opt_ := *opt
db := &DB{
stor: stor,
watchq: make(chan Event),
opt: &opt_,
down: make(chan struct{}),
hwait: make(map[hwaiter]struct{}),
......
// Copyright (C) 2018-2020 Nexedi SA and Contributors.
// Copyright (C) 2018-2021 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -276,7 +276,7 @@ func (t *tDB) Reopen() {
ReadOnly: true,
NoCache: !t.rawcache,
}); X(err)
db := NewDB(stor)
db := NewDB(stor, &DBOptions{})
t.stor = stor
t.db = db
}
......
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