channeldb: accept cache sizes in ChannelGraph

This commit is contained in:
Conner Fromknecht 2019-04-01 16:33:36 -07:00
parent baa968b1ff
commit 6d3e081f7b
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
2 changed files with 12 additions and 5 deletions

@ -114,7 +114,7 @@ type DB struct {
// Open opens an existing channeldb. Any necessary schemas migrations due to
// updates will take place as necessary.
func Open(dbPath string) (*DB, error) {
func Open(dbPath string, modifiers ...OptionModifier) (*DB, error) {
path := filepath.Join(dbPath, dbName)
if !fileExists(path) {
@ -123,6 +123,11 @@ func Open(dbPath string) (*DB, error) {
}
}
opts := DefaultOptions()
for _, modifier := range modifiers {
modifier(&opts)
}
bdb, err := bbolt.Open(path, dbFilePermission, nil)
if err != nil {
return nil, err
@ -132,7 +137,9 @@ func Open(dbPath string) (*DB, error) {
DB: bdb,
dbPath: dbPath,
}
chanDB.graph = newChannelGraph(chanDB)
chanDB.graph = newChannelGraph(
chanDB, opts.RejectCacheSize, opts.ChannelCacheSize,
)
// Synchronize the version of database and apply migrations if needed.
if err := chanDB.syncVersions(dbVersions); err != nil {

@ -165,11 +165,11 @@ type ChannelGraph struct {
// newChannelGraph allocates a new ChannelGraph backed by a DB instance. The
// returned instance has its own unique reject cache and channel cache.
func newChannelGraph(db *DB) *ChannelGraph {
func newChannelGraph(db *DB, rejectCacheSize, chanCacheSize int) *ChannelGraph {
return &ChannelGraph{
db: db,
rejectCache: newRejectCache(50000),
chanCache: newChannelCache(20000),
rejectCache: newRejectCache(rejectCacheSize),
chanCache: newChannelCache(chanCacheSize),
}
}