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
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( chanDB.graph, err = NewChannelGraph(
backend, opts.RejectCacheSize, opts.ChannelCacheSize, backend, opts.RejectCacheSize, opts.ChannelCacheSize,
opts.BatchCommitInterval, opts.PreAllocCacheNumNodes, opts.BatchCommitInterval, opts.PreAllocCacheNumNodes,
opts.UseGraphCache,
) )
if err != nil { if err != nil {
return nil, err return nil, err

View File

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

View File

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

View File

@@ -45,6 +45,11 @@ type Options struct {
// graph cache, so we can pre-allocate the map accordingly. // graph cache, so we can pre-allocate the map accordingly.
PreAllocCacheNumNodes int 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 is the time source used by the database.
clock clock.Clock clock clock.Clock
@@ -65,6 +70,7 @@ func DefaultOptions() Options {
RejectCacheSize: DefaultRejectCacheSize, RejectCacheSize: DefaultRejectCacheSize,
ChannelCacheSize: DefaultChannelCacheSize, ChannelCacheSize: DefaultChannelCacheSize,
PreAllocCacheNumNodes: DefaultPreAllocCacheNumNodes, PreAllocCacheNumNodes: DefaultPreAllocCacheNumNodes,
UseGraphCache: true,
clock: clock.NewDefaultClock(), 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. // OptionSetSyncFreelist allows the database to sync its freelist.
func OptionSetSyncFreelist(b bool) OptionModifier { func OptionSetSyncFreelist(b bool) OptionModifier {
return func(o *Options) { return func(o *Options) {

View File

@@ -847,6 +847,7 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
channeldb.OptionSetChannelCacheSize(cfg.Caches.ChannelCacheSize), channeldb.OptionSetChannelCacheSize(cfg.Caches.ChannelCacheSize),
channeldb.OptionSetBatchCommitInterval(cfg.DB.BatchCommitInterval), channeldb.OptionSetBatchCommitInterval(cfg.DB.BatchCommitInterval),
channeldb.OptionDryRunMigration(cfg.DryRunMigration), channeldb.OptionDryRunMigration(cfg.DryRunMigration),
channeldb.OptionSetUseGraphCache(!cfg.DB.NoGraphCache),
} }
// We want to pre-allocate the channel graph cache according to what we // 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( graph, err := channeldb.NewChannelGraph(
backend, opts.RejectCacheSize, opts.ChannelCacheSize, backend, opts.RejectCacheSize, opts.ChannelCacheSize,
opts.BatchCommitInterval, opts.PreAllocCacheNumNodes, opts.BatchCommitInterval, opts.PreAllocCacheNumNodes,
true,
) )
if err != nil { if err != nil {
cleanUp() cleanUp()