Skip to content

Commit 3b44982

Browse files
committed
graph/db: init SQLStore caches and batch schedulers
Here, we use the new options to initialise the reject and channel caches for the SQLStore (as is done for the KVStore) and also the channel and node batch schedulers.
1 parent 149e1c7 commit 3b44982

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

graph/db/sql_store.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package graphdb
22

33
import (
44
"fmt"
5+
"sync"
56

7+
"github.com/lightningnetwork/lnd/batch"
68
"github.com/lightningnetwork/lnd/sqldb"
79
)
810

@@ -28,6 +30,16 @@ type BatchedSQLQueries interface {
2830
type SQLStore struct {
2931
db BatchedSQLQueries
3032

33+
// cacheMu guards all caches (rejectCache and chanCache). If
34+
// this mutex will be acquired at the same time as the DB mutex then
35+
// the cacheMu MUST be acquired first to prevent deadlock.
36+
cacheMu sync.RWMutex
37+
rejectCache *rejectCache
38+
chanCache *channelCache
39+
40+
chanScheduler batch.Scheduler[SQLQueries]
41+
nodeScheduler batch.Scheduler[SQLQueries]
42+
3143
// Temporary fall-back to the KVStore so that we can implement the
3244
// interface incrementally.
3345
*KVStore
@@ -52,8 +64,19 @@ func NewSQLStore(db BatchedSQLQueries, kvStore *KVStore,
5264
"supported for SQL stores")
5365
}
5466

55-
return &SQLStore{
56-
db: db,
57-
KVStore: kvStore,
58-
}, nil
67+
s := &SQLStore{
68+
db: db,
69+
KVStore: kvStore,
70+
rejectCache: newRejectCache(opts.RejectCacheSize),
71+
chanCache: newChannelCache(opts.ChannelCacheSize),
72+
}
73+
74+
s.chanScheduler = batch.NewTimeScheduler(
75+
db, &s.cacheMu, opts.BatchCommitInterval,
76+
)
77+
s.nodeScheduler = batch.NewTimeScheduler(
78+
db, nil, opts.BatchCommitInterval,
79+
)
80+
81+
return s, nil
5982
}

0 commit comments

Comments
 (0)