lnd+channeldb: add graph cache option to channeldb

With this commit we forward the config option for disabling the channel
graph cache as a boolean to the channeldb. But we invert its meaning to
make the flag easier to understand.
This commit is contained in:
Oliver Gugger 2021-10-21 13:55:20 +02:00
parent a2ad533136
commit f216da32f3
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
6 changed files with 19 additions and 2 deletions

View File

@ -291,6 +291,7 @@ func CreateWithBackend(backend kvdb.Backend, modifiers ...OptionModifier) (*DB,
chanDB.graph, err = NewChannelGraph(
backend, opts.RejectCacheSize, opts.ChannelCacheSize,
opts.BatchCommitInterval, opts.PreAllocCacheNumNodes,
opts.UseGraphCache,
)
if err != nil {
return nil, err

View File

@ -188,8 +188,8 @@ 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 kvdb.Backend, rejectCacheSize, chanCacheSize int,
batchCommitInterval time.Duration,
preAllocCacheNumNodes int) (*ChannelGraph, error) {
batchCommitInterval time.Duration, preAllocCacheNumNodes int,
useGraphCache bool) (*ChannelGraph, error) {
if err := initChannelGraph(db); err != nil {
return nil, err

View File

@ -77,6 +77,7 @@ func MakeTestGraph(modifiers ...OptionModifier) (*ChannelGraph, func(), error) {
graph, err := NewChannelGraph(
backend, opts.RejectCacheSize, opts.ChannelCacheSize,
opts.BatchCommitInterval, opts.PreAllocCacheNumNodes,
true,
)
if err != nil {
backendCleanup()

View File

@ -45,6 +45,11 @@ type Options struct {
// graph cache, so we can pre-allocate the map accordingly.
PreAllocCacheNumNodes int
// UseGraphCache denotes whether the in-memory graph cache should be
// used or a fallback version that uses the underlying database for
// path finding.
UseGraphCache bool
// clock is the time source used by the database.
clock clock.Clock
@ -65,6 +70,7 @@ func DefaultOptions() Options {
RejectCacheSize: DefaultRejectCacheSize,
ChannelCacheSize: DefaultChannelCacheSize,
PreAllocCacheNumNodes: DefaultPreAllocCacheNumNodes,
UseGraphCache: true,
clock: clock.NewDefaultClock(),
}
}
@ -93,6 +99,13 @@ func OptionSetPreAllocCacheNumNodes(n int) OptionModifier {
}
}
// OptionSetUseGraphCache sets the UseGraphCache option to the given value.
func OptionSetUseGraphCache(use bool) OptionModifier {
return func(o *Options) {
o.UseGraphCache = use
}
}
// OptionSetSyncFreelist allows the database to sync its freelist.
func OptionSetSyncFreelist(b bool) OptionModifier {
return func(o *Options) {

View File

@ -847,6 +847,7 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
channeldb.OptionSetChannelCacheSize(cfg.Caches.ChannelCacheSize),
channeldb.OptionSetBatchCommitInterval(cfg.DB.BatchCommitInterval),
channeldb.OptionDryRunMigration(cfg.DryRunMigration),
channeldb.OptionSetUseGraphCache(!cfg.DB.NoGraphCache),
}
// We want to pre-allocate the channel graph cache according to what we

View File

@ -173,6 +173,7 @@ func makeTestGraph() (*channeldb.ChannelGraph, kvdb.Backend, func(), error) {
graph, err := channeldb.NewChannelGraph(
backend, opts.RejectCacheSize, opts.ChannelCacheSize,
opts.BatchCommitInterval, opts.PreAllocCacheNumNodes,
true,
)
if err != nil {
cleanUp()