• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 15249422085

26 May 2025 08:11AM UTC coverage: 57.977% (-11.0%) from 69.015%
15249422085

push

github

web-flow
Merge pull request #9853 from lightningnetwork/elle-graphSQL8-prep

graph/db: init SQLStore caches and batch schedulers

9 of 34 new or added lines in 4 files covered. (26.47%)

29283 existing lines in 458 files now uncovered.

96475 of 166402 relevant lines covered (57.98%)

1.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/graph/db/sql_store.go
1
package graphdb
2

3
import (
4
        "fmt"
5
        "sync"
6

7
        "github.com/lightningnetwork/lnd/batch"
8
        "github.com/lightningnetwork/lnd/sqldb"
9
)
10

11
// SQLQueries is a subset of the sqlc.Querier interface that can be used to
12
// execute queries against the SQL graph tables.
13
type SQLQueries interface {
14
}
15

16
// BatchedSQLQueries is a version of SQLQueries that's capable of batched
17
// database operations.
18
type BatchedSQLQueries interface {
19
        SQLQueries
20
        sqldb.BatchedTx[SQLQueries]
21
}
22

23
// SQLStore is an implementation of the V1Store interface that uses a SQL
24
// database as the backend.
25
//
26
// NOTE: currently, this temporarily embeds the KVStore struct so that we can
27
// implement the V1Store interface incrementally. For any method not
28
// implemented,  things will fall back to the KVStore. This is ONLY the case
29
// for the time being while this struct is purely used in unit tests only.
30
type SQLStore struct {
31
        db BatchedSQLQueries
32

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

43
        // Temporary fall-back to the KVStore so that we can implement the
44
        // interface incrementally.
45
        *KVStore
46
}
47

48
// A compile-time assertion to ensure that SQLStore implements the V1Store
49
// interface.
50
var _ V1Store = (*SQLStore)(nil)
51

52
// NewSQLStore creates a new SQLStore instance given an open BatchedSQLQueries
53
// storage backend.
54
func NewSQLStore(db BatchedSQLQueries, kvStore *KVStore,
NEW
55
        options ...StoreOptionModifier) (*SQLStore, error) {
×
NEW
56

×
NEW
57
        opts := DefaultOptions()
×
NEW
58
        for _, o := range options {
×
NEW
59
                o(opts)
×
NEW
60
        }
×
61

NEW
62
        if opts.NoMigration {
×
NEW
63
                return nil, fmt.Errorf("the NoMigration option is not yet " +
×
NEW
64
                        "supported for SQL stores")
×
NEW
65
        }
×
66

NEW
67
        s := &SQLStore{
×
NEW
68
                db:          db,
×
NEW
69
                KVStore:     kvStore,
×
NEW
70
                rejectCache: newRejectCache(opts.RejectCacheSize),
×
NEW
71
                chanCache:   newChannelCache(opts.ChannelCacheSize),
×
72
        }
×
NEW
73

×
NEW
74
        s.chanScheduler = batch.NewTimeScheduler(
×
NEW
75
                db, &s.cacheMu, opts.BatchCommitInterval,
×
NEW
76
        )
×
NEW
77
        s.nodeScheduler = batch.NewTimeScheduler(
×
NEW
78
                db, nil, opts.BatchCommitInterval,
×
NEW
79
        )
×
NEW
80

×
NEW
81
        return s, nil
×
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc