graph/db: let ChannelGraph init the graphCache
In this commit, we let the ChannelGraph be responsible for populating the graphCache and then passing it to the KVStore. This is a first step in moving the graphCache completely out of the KVStore layer.
This commit is contained in:
8 files changed
+129
-80
No files matched your search
+44
-28
@@ -20,6 +20,47 @@ const (
|
||||
DefaultPreAllocCacheNumNodes = 15000
|
||||
)
|
||||
|
||||
// chanGraphOptions holds parameters for tuning and customizing the
|
||||
// ChannelGraph.
|
||||
type chanGraphOptions struct {
|
||||
// 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
|
||||
|
||||
// preAllocCacheNumNodes is the number of nodes we expect to be in the
|
||||
// graph cache, so we can pre-allocate the map accordingly.
|
||||
preAllocCacheNumNodes int
|
||||
}
|
||||
|
||||
// defaultChanGraphOptions returns a new chanGraphOptions instance populated
|
||||
// with default values.
|
||||
func defaultChanGraphOptions() *chanGraphOptions {
|
||||
return &chanGraphOptions{
|
||||
useGraphCache: true,
|
||||
preAllocCacheNumNodes: DefaultPreAllocCacheNumNodes,
|
||||
}
|
||||
}
|
||||
|
||||
// ChanGraphOption describes the signature of a functional option that can be
|
||||
// used to customize a ChannelGraph instance.
|
||||
type ChanGraphOption func(*chanGraphOptions)
|
||||
|
||||
// WithUseGraphCache sets whether the in-memory graph cache should be used.
|
||||
func WithUseGraphCache(use bool) ChanGraphOption {
|
||||
return func(o *chanGraphOptions) {
|
||||
o.useGraphCache = use
|
||||
}
|
||||
}
|
||||
|
||||
// WithPreAllocCacheNumNodes sets the number of nodes we expect to be in the
|
||||
// graph cache, so we can pre-allocate the map accordingly.
|
||||
func WithPreAllocCacheNumNodes(n int) ChanGraphOption {
|
||||
return func(o *chanGraphOptions) {
|
||||
o.preAllocCacheNumNodes = n
|
||||
}
|
||||
}
|
||||
|
||||
// KVStoreOptions holds parameters for tuning and customizing a graph.DB.
|
||||
type KVStoreOptions struct {
|
||||
// RejectCacheSize is the maximum number of rejectCacheEntries to hold
|
||||
@@ -34,15 +75,6 @@ type KVStoreOptions struct {
|
||||
// wait before attempting to commit a pending set of updates.
|
||||
BatchCommitInterval time.Duration
|
||||
|
||||
// PreAllocCacheNumNodes is the number of nodes we expect to be in the
|
||||
// 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
|
||||
|
||||
// NoMigration specifies that underlying backend was opened in read-only
|
||||
// mode and migrations shouldn't be performed. This can be useful for
|
||||
// applications that use the channeldb package as a library.
|
||||
@@ -52,11 +84,9 @@ type KVStoreOptions struct {
|
||||
// DefaultOptions returns a KVStoreOptions populated with default values.
|
||||
func DefaultOptions() *KVStoreOptions {
|
||||
return &KVStoreOptions{
|
||||
RejectCacheSize: DefaultRejectCacheSize,
|
||||
ChannelCacheSize: DefaultChannelCacheSize,
|
||||
PreAllocCacheNumNodes: DefaultPreAllocCacheNumNodes,
|
||||
UseGraphCache: true,
|
||||
NoMigration: false,
|
||||
RejectCacheSize: DefaultRejectCacheSize,
|
||||
ChannelCacheSize: DefaultChannelCacheSize,
|
||||
NoMigration: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,13 +108,6 @@ func WithChannelCacheSize(n int) KVStoreOptionModifier {
|
||||
}
|
||||
}
|
||||
|
||||
// WithPreAllocCacheNumNodes sets the PreAllocCacheNumNodes to n.
|
||||
func WithPreAllocCacheNumNodes(n int) KVStoreOptionModifier {
|
||||
return func(o *KVStoreOptions) {
|
||||
o.PreAllocCacheNumNodes = n
|
||||
}
|
||||
}
|
||||
|
||||
// WithBatchCommitInterval sets the batch commit interval for the interval batch
|
||||
// schedulers.
|
||||
func WithBatchCommitInterval(interval time.Duration) KVStoreOptionModifier {
|
||||
@@ -92,10 +115,3 @@ func WithBatchCommitInterval(interval time.Duration) KVStoreOptionModifier {
|
||||
o.BatchCommitInterval = interval
|
||||
}
|
||||
}
|
||||
|
||||
// WithUseGraphCache sets the UseGraphCache option to the given value.
|
||||
func WithUseGraphCache(use bool) KVStoreOptionModifier {
|
||||
return func(o *KVStoreOptions) {
|
||||
o.UseGraphCache = use
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user