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

lightningnetwork / lnd / 13035292482

29 Jan 2025 03:59PM UTC coverage: 49.3% (-9.5%) from 58.777%
13035292482

Pull #9456

github

mohamedawnallah
docs: update release-notes-0.19.0.md

In this commit, we warn users about the removal
of RPCs `SendToRoute`, `SendToRouteSync`, `SendPayment`,
and `SendPaymentSync` in the next release 0.20.
Pull Request #9456: lnrpc+docs: deprecate warning `SendToRoute`, `SendToRouteSync`, `SendPayment`, and `SendPaymentSync` in Release 0.19

100634 of 204126 relevant lines covered (49.3%)

1.54 hits per line

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

78.95
/batch/scheduler.go
1
package batch
2

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

7
        "github.com/lightningnetwork/lnd/kvdb"
8
)
9

10
// TimeScheduler is a batching engine that executes requests within a fixed
11
// horizon. When the first request is received, a TimeScheduler waits a
12
// configurable duration for other concurrent requests to join the batch. Once
13
// this time has elapsed, the batch is closed and executed. Subsequent requests
14
// are then added to a new batch which undergoes the same process.
15
type TimeScheduler struct {
16
        db       kvdb.Backend
17
        locker   sync.Locker
18
        duration time.Duration
19

20
        mu sync.Mutex
21
        b  *batch
22
}
23

24
// NewTimeScheduler initializes a new TimeScheduler with a fixed duration at
25
// which to schedule batches. If the operation needs to modify a higher-level
26
// cache, the cache's lock should be provided to so that external consistency
27
// can be maintained, as successful db operations will cause a request's
28
// OnCommit method to be executed while holding this lock.
29
func NewTimeScheduler(db kvdb.Backend, locker sync.Locker,
30
        duration time.Duration) *TimeScheduler {
3✔
31

3✔
32
        return &TimeScheduler{
3✔
33
                db:       db,
3✔
34
                locker:   locker,
3✔
35
                duration: duration,
3✔
36
        }
3✔
37
}
3✔
38

39
// Execute schedules the provided request for batch execution along with other
40
// concurrent requests. The request will be executed within a fixed horizon,
41
// parameterizeed by the duration of the scheduler. The error from the
42
// underlying operation is returned to the caller.
43
//
44
// NOTE: Part of the Scheduler interface.
45
func (s *TimeScheduler) Execute(r *Request) error {
3✔
46
        req := request{
3✔
47
                Request: r,
3✔
48
                errChan: make(chan error, 1),
3✔
49
        }
3✔
50

3✔
51
        // Add the request to the current batch. If the batch has been cleared
3✔
52
        // or no batch exists, create a new one.
3✔
53
        s.mu.Lock()
3✔
54
        if s.b == nil {
6✔
55
                s.b = &batch{
3✔
56
                        db:     s.db,
3✔
57
                        clear:  s.clear,
3✔
58
                        locker: s.locker,
3✔
59
                }
3✔
60
                time.AfterFunc(s.duration, s.b.trigger)
3✔
61
        }
3✔
62
        s.b.reqs = append(s.b.reqs, &req)
3✔
63

3✔
64
        // If this is a non-lazy request, we'll execute the batch immediately.
3✔
65
        if !r.lazy {
6✔
66
                go s.b.trigger()
3✔
67
        }
3✔
68

69
        s.mu.Unlock()
3✔
70

3✔
71
        // Wait for the batch to process the request. If the batch didn't
3✔
72
        // ask us to execute the request individually, simply return the error.
3✔
73
        err := <-req.errChan
3✔
74
        if err != errSolo {
6✔
75
                return err
3✔
76
        }
3✔
77

78
        // Obtain exclusive access to the cache if this scheduler needs to
79
        // modify the cache in OnCommit.
80
        if s.locker != nil {
×
81
                s.locker.Lock()
×
82
                defer s.locker.Unlock()
×
83
        }
×
84

85
        // Otherwise, run the request on its own.
86
        commitErr := kvdb.Update(s.db, req.Update, func() {
×
87
                if req.Reset != nil {
×
88
                        req.Reset()
×
89
                }
×
90
        })
91

92
        // Finally, return the commit error directly or execute the OnCommit
93
        // closure with the commit error if present.
94
        if req.OnCommit != nil {
×
95
                return req.OnCommit(commitErr)
×
96
        }
×
97

98
        return commitErr
×
99
}
100

101
// clear resets the scheduler's batch to nil so that no more requests can be
102
// added.
103
func (s *TimeScheduler) clear(b *batch) {
3✔
104
        s.mu.Lock()
3✔
105
        if s.b == b {
6✔
106
                s.b = nil
3✔
107
        }
3✔
108
        s.mu.Unlock()
3✔
109
}
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