mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-12-12 05:42:25 +01:00
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:
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user