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 // Open opens an existing channeldb. Any necessary schemas migrations due to
// updates will take place as necessary. // 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) path := filepath.Join(dbPath, dbName)
if !fileExists(path) { 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) bdb, err := bbolt.Open(path, dbFilePermission, nil)
if err != nil { if err != nil {
return nil, err return nil, err
@ -132,7 +137,9 @@ func Open(dbPath string) (*DB, error) {
DB: bdb, DB: bdb,
dbPath: dbPath, dbPath: dbPath,
} }
chanDB.graph = newChannelGraph(chanDB) chanDB.graph = newChannelGraph(
chanDB, opts.RejectCacheSize, opts.ChannelCacheSize,
)
// Synchronize the version of database and apply migrations if needed. // Synchronize the version of database and apply migrations if needed.
if err := chanDB.syncVersions(dbVersions); err != nil { 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 // newChannelGraph allocates a new ChannelGraph backed by a DB instance. The
// returned instance has its own unique reject cache and channel cache. // 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{ return &ChannelGraph{
db: db, db: db,
rejectCache: newRejectCache(50000), rejectCache: newRejectCache(rejectCacheSize),
chanCache: newChannelCache(20000), chanCache: newChannelCache(chanCacheSize),
} }
} }