graph/db: rename Options to KVStoreOptions

Namespace these options so that we can introduce separate options for
the new ChannelGraph.
This commit is contained in:
Elle Mouton
2025-02-18 13:39:43 -03:00
parent ae3961b47f
commit 81e0608c10
4 changed files with 24 additions and 23 deletions

View File

@@ -1026,7 +1026,7 @@ func (d *DefaultDatabaseBuilder) BuildDatabase(
"instances") "instances")
} }
graphDBOptions := []graphdb.OptionModifier{ graphDBOptions := []graphdb.KVStoreOptionModifier{
graphdb.WithRejectCacheSize(cfg.Caches.RejectCacheSize), graphdb.WithRejectCacheSize(cfg.Caches.RejectCacheSize),
graphdb.WithChannelCacheSize(cfg.Caches.ChannelCacheSize), graphdb.WithChannelCacheSize(cfg.Caches.ChannelCacheSize),
graphdb.WithBatchCommitInterval(cfg.DB.BatchCommitInterval), graphdb.WithBatchCommitInterval(cfg.DB.BatchCommitInterval),

View File

@@ -12,8 +12,8 @@ type ChannelGraph struct {
} }
// NewChannelGraph creates a new ChannelGraph instance with the given backend. // NewChannelGraph creates a new ChannelGraph instance with the given backend.
func NewChannelGraph(db kvdb.Backend, options ...OptionModifier) (*ChannelGraph, func NewChannelGraph(db kvdb.Backend, options ...KVStoreOptionModifier) (
error) { *ChannelGraph, error) {
store, err := NewKVStore(db, options...) store, err := NewKVStore(db, options...)
if err != nil { if err != nil {

View File

@@ -198,7 +198,7 @@ type KVStore struct {
// NewKVStore allocates a new KVStore backed by a DB instance. The // NewKVStore allocates a new KVStore 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 NewKVStore(db kvdb.Backend, options ...OptionModifier) (*KVStore, func NewKVStore(db kvdb.Backend, options ...KVStoreOptionModifier) (*KVStore,
error) { error) {
opts := DefaultOptions() opts := DefaultOptions()
@@ -4827,8 +4827,8 @@ func (c *chanGraphNodeTx) ForEachChannel(f func(*models.ChannelEdgeInfo,
// MakeTestGraph creates a new instance of the KVStore for testing // MakeTestGraph creates a new instance of the KVStore for testing
// purposes. // purposes.
func MakeTestGraph(t testing.TB, modifiers ...OptionModifier) (*ChannelGraph, func MakeTestGraph(t testing.TB, modifiers ...KVStoreOptionModifier) (
error) { *ChannelGraph, error) {
opts := DefaultOptions() opts := DefaultOptions()
for _, modifier := range modifiers { for _, modifier := range modifiers {

View File

@@ -20,8 +20,8 @@ const (
DefaultPreAllocCacheNumNodes = 15000 DefaultPreAllocCacheNumNodes = 15000
) )
// Options holds parameters for tuning and customizing a graph.DB. // KVStoreOptions holds parameters for tuning and customizing a graph.DB.
type Options struct { type KVStoreOptions struct {
// RejectCacheSize is the maximum number of rejectCacheEntries to hold // RejectCacheSize is the maximum number of rejectCacheEntries to hold
// in the rejection cache. // in the rejection cache.
RejectCacheSize int RejectCacheSize int
@@ -49,9 +49,9 @@ type Options struct {
NoMigration bool NoMigration bool
} }
// DefaultOptions returns an Options populated with default values. // DefaultOptions returns a KVStoreOptions populated with default values.
func DefaultOptions() *Options { func DefaultOptions() *KVStoreOptions {
return &Options{ return &KVStoreOptions{
RejectCacheSize: DefaultRejectCacheSize, RejectCacheSize: DefaultRejectCacheSize,
ChannelCacheSize: DefaultChannelCacheSize, ChannelCacheSize: DefaultChannelCacheSize,
PreAllocCacheNumNodes: DefaultPreAllocCacheNumNodes, PreAllocCacheNumNodes: DefaultPreAllocCacheNumNodes,
@@ -60,41 +60,42 @@ func DefaultOptions() *Options {
} }
} }
// OptionModifier is a function signature for modifying the default Options. // KVStoreOptionModifier is a function signature for modifying the default
type OptionModifier func(*Options) // KVStoreOptions.
type KVStoreOptionModifier func(*KVStoreOptions)
// WithRejectCacheSize sets the RejectCacheSize to n. // WithRejectCacheSize sets the RejectCacheSize to n.
func WithRejectCacheSize(n int) OptionModifier { func WithRejectCacheSize(n int) KVStoreOptionModifier {
return func(o *Options) { return func(o *KVStoreOptions) {
o.RejectCacheSize = n o.RejectCacheSize = n
} }
} }
// WithChannelCacheSize sets the ChannelCacheSize to n. // WithChannelCacheSize sets the ChannelCacheSize to n.
func WithChannelCacheSize(n int) OptionModifier { func WithChannelCacheSize(n int) KVStoreOptionModifier {
return func(o *Options) { return func(o *KVStoreOptions) {
o.ChannelCacheSize = n o.ChannelCacheSize = n
} }
} }
// WithPreAllocCacheNumNodes sets the PreAllocCacheNumNodes to n. // WithPreAllocCacheNumNodes sets the PreAllocCacheNumNodes to n.
func WithPreAllocCacheNumNodes(n int) OptionModifier { func WithPreAllocCacheNumNodes(n int) KVStoreOptionModifier {
return func(o *Options) { return func(o *KVStoreOptions) {
o.PreAllocCacheNumNodes = n o.PreAllocCacheNumNodes = n
} }
} }
// WithBatchCommitInterval sets the batch commit interval for the interval batch // WithBatchCommitInterval sets the batch commit interval for the interval batch
// schedulers. // schedulers.
func WithBatchCommitInterval(interval time.Duration) OptionModifier { func WithBatchCommitInterval(interval time.Duration) KVStoreOptionModifier {
return func(o *Options) { return func(o *KVStoreOptions) {
o.BatchCommitInterval = interval o.BatchCommitInterval = interval
} }
} }
// WithUseGraphCache sets the UseGraphCache option to the given value. // WithUseGraphCache sets the UseGraphCache option to the given value.
func WithUseGraphCache(use bool) OptionModifier { func WithUseGraphCache(use bool) KVStoreOptionModifier {
return func(o *Options) { return func(o *KVStoreOptions) {
o.UseGraphCache = use o.UseGraphCache = use
} }
} }