multi: add reset to ForEachNode
This commit is contained in:
9 files changed
+17
-13
No files matched your search
+2
-2
@@ -121,7 +121,7 @@ func (d *dbNode) ForEachChannel(ctx context.Context,
|
|||||||
//
|
//
|
||||||
// NOTE: Part of the autopilot.ChannelGraph interface.
|
// NOTE: Part of the autopilot.ChannelGraph interface.
|
||||||
func (d *databaseChannelGraph) ForEachNode(ctx context.Context,
|
func (d *databaseChannelGraph) ForEachNode(ctx context.Context,
|
||||||
cb func(context.Context, Node) error, _ func()) error {
|
cb func(context.Context, Node) error, reset func()) error {
|
||||||
|
|
||||||
return d.db.ForEachNode(ctx, func(nodeTx graphdb.NodeRTx) error {
|
return d.db.ForEachNode(ctx, func(nodeTx graphdb.NodeRTx) error {
|
||||||
// We'll skip over any node that doesn't have any advertised
|
// We'll skip over any node that doesn't have any advertised
|
||||||
@@ -136,7 +136,7 @@ func (d *databaseChannelGraph) ForEachNode(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return cb(ctx, node)
|
return cb(ctx, node)
|
||||||
})
|
}, reset)
|
||||||
}
|
}
|
||||||
|
|
||||||
// databaseChannelGraphCached wraps a channeldb.ChannelGraph instance with the
|
// databaseChannelGraphCached wraps a channeldb.ChannelGraph instance with the
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ type GraphSource interface {
|
|||||||
// the callback returns an error, then the transaction is aborted and
|
// the callback returns an error, then the transaction is aborted and
|
||||||
// the iteration stops early. Any operations performed on the NodeTx
|
// the iteration stops early. Any operations performed on the NodeTx
|
||||||
// passed to the call-back are executed under the same read transaction.
|
// passed to the call-back are executed under the same read transaction.
|
||||||
ForEachNode(context.Context, func(graphdb.NodeRTx) error) error
|
ForEachNode(context.Context, func(graphdb.NodeRTx) error, func()) error
|
||||||
|
|
||||||
// ForEachNodeCached is similar to ForEachNode, but it utilizes the
|
// ForEachNodeCached is similar to ForEachNode, but it utilizes the
|
||||||
// channel graph cache if one is available. It is less consistent than
|
// channel graph cache if one is available. It is less consistent than
|
||||||
|
|||||||
@@ -1454,7 +1454,7 @@ func TestGraphTraversalCacheable(t *testing.T) {
|
|||||||
nodeMap[tx.Node().PubKeyBytes] = struct{}{}
|
nodeMap[tx.Node().PubKeyBytes] = struct{}{}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
}, func() {})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, nodeMap, numNodes)
|
require.Len(t, nodeMap, numNodes)
|
||||||
|
|
||||||
@@ -1583,7 +1583,7 @@ func fillTestGraph(t testing.TB, graph *ChannelGraph, numNodes,
|
|||||||
err := graph.ForEachNode(ctx, func(tx NodeRTx) error {
|
err := graph.ForEachNode(ctx, func(tx NodeRTx) error {
|
||||||
delete(nodeIndex, tx.Node().Alias)
|
delete(nodeIndex, tx.Node().Alias)
|
||||||
return nil
|
return nil
|
||||||
})
|
}, func() {})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, nodeIndex, 0)
|
require.Len(t, nodeIndex, 0)
|
||||||
|
|
||||||
@@ -1693,7 +1693,7 @@ func assertNumNodes(t *testing.T, graph *ChannelGraph, n int) {
|
|||||||
numNodes++
|
numNodes++
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
}, func() {})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_, _, line, _ := runtime.Caller(1)
|
_, _, line, _ := runtime.Caller(1)
|
||||||
t.Fatalf("line %v: unable to scan nodes: %v", line, err)
|
t.Fatalf("line %v: unable to scan nodes: %v", line, err)
|
||||||
|
|||||||
@@ -102,7 +102,8 @@ type V1Store interface { //nolint:interfacebloat
|
|||||||
// passed to the call-back are executed under the same read transaction
|
// passed to the call-back are executed under the same read transaction
|
||||||
// and so, methods on the NodeTx object _MUST_ only be called from
|
// and so, methods on the NodeTx object _MUST_ only be called from
|
||||||
// within the call-back.
|
// within the call-back.
|
||||||
ForEachNode(ctx context.Context, cb func(tx NodeRTx) error) error
|
ForEachNode(ctx context.Context, cb func(tx NodeRTx) error,
|
||||||
|
reset func()) error
|
||||||
|
|
||||||
// ForEachNodeCacheable iterates through all the stored vertices/nodes
|
// ForEachNodeCacheable iterates through all the stored vertices/nodes
|
||||||
// in the graph, executing the passed callback with each node
|
// in the graph, executing the passed callback with each node
|
||||||
|
|||||||
@@ -802,9 +802,7 @@ func (c *KVStore) DisabledChannelIDs() ([]uint64, error) {
|
|||||||
// executed under the same read transaction and so, methods on the NodeTx object
|
// executed under the same read transaction and so, methods on the NodeTx object
|
||||||
// _MUST_ only be called from within the call-back.
|
// _MUST_ only be called from within the call-back.
|
||||||
func (c *KVStore) ForEachNode(_ context.Context,
|
func (c *KVStore) ForEachNode(_ context.Context,
|
||||||
cb func(tx NodeRTx) error) error {
|
cb func(tx NodeRTx) error, reset func()) error {
|
||||||
|
|
||||||
reset := func() {}
|
|
||||||
|
|
||||||
return forEachNode(c.db, func(tx kvdb.RTx,
|
return forEachNode(c.db, func(tx kvdb.RTx,
|
||||||
node *models.LightningNode) error {
|
node *models.LightningNode) error {
|
||||||
|
|||||||
@@ -401,6 +401,8 @@ func fetchAllNodes(t *testing.T, store V1Store) []*models.LightningNode {
|
|||||||
nodes = append(nodes, node)
|
nodes = append(nodes, node)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
}, func() {
|
||||||
|
nodes = nil
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|||||||
@@ -785,9 +785,7 @@ func (s *SQLStore) ForEachSourceNodeChannel(ctx context.Context,
|
|||||||
//
|
//
|
||||||
// NOTE: part of the V1Store interface.
|
// NOTE: part of the V1Store interface.
|
||||||
func (s *SQLStore) ForEachNode(ctx context.Context,
|
func (s *SQLStore) ForEachNode(ctx context.Context,
|
||||||
cb func(tx NodeRTx) error) error {
|
cb func(tx NodeRTx) error, reset func()) error {
|
||||||
|
|
||||||
reset := func() {}
|
|
||||||
|
|
||||||
var lastID int64 = 0
|
var lastID int64 = 0
|
||||||
handleNode := func(db SQLQueries, dbNode sqlc.Node) error {
|
handleNode := func(db SQLQueries, dbNode sqlc.Node) error {
|
||||||
|
|||||||
@@ -82,6 +82,9 @@ func testGraphMigration(ht *lntest.HarnessTest) {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
}, func() {
|
||||||
|
clear(edges)
|
||||||
|
numNodes = 0
|
||||||
})
|
})
|
||||||
require.NoError(ht, err)
|
require.NoError(ht, err)
|
||||||
require.Equal(ht, expNumNodes, numNodes)
|
require.Equal(ht, expNumNodes, numNodes)
|
||||||
|
|||||||
@@ -6745,6 +6745,8 @@ func (r *rpcServer) DescribeGraph(ctx context.Context,
|
|||||||
resp.Nodes = append(resp.Nodes, lnNode)
|
resp.Nodes = append(resp.Nodes, lnNode)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
}, func() {
|
||||||
|
resp.Nodes = nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in new issue
Block a user