Skip to content

Commit a3793b2

Browse files
authored
Merge pull request #10129 from ellemouton/graphPerf9
[8] graph/db: use batch loading for various graph SQL methods
2 parents e00a072 + 522e200 commit a3793b2

File tree

5 files changed

+500
-222
lines changed

5 files changed

+500
-222
lines changed

graph/db/benchmark_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,15 @@ func BenchmarkGraphReadMethods(b *testing.B) {
736736
require.NoError(b, err)
737737
},
738738
},
739+
{
740+
name: "ChanUpdatesInHorizon",
741+
fn: func(b testing.TB, store V1Store) {
742+
_, err := store.ChanUpdatesInHorizon(
743+
time.Unix(0, 0), time.Now(),
744+
)
745+
require.NoError(b, err)
746+
},
747+
},
739748
}
740749

741750
for _, test := range tests {

graph/db/kv_store.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,7 +2789,8 @@ func (c *KVStore) delChannelEdgeUnsafe(edges, edgeIndex, chanIndex,
27892789
}
27902790

27912791
nodeKey1, nodeKey2 = makeZombiePubkeys(
2792-
&edgeInfo, e1UpdateTime, e2UpdateTime,
2792+
edgeInfo.NodeKey1Bytes, edgeInfo.NodeKey2Bytes,
2793+
e1UpdateTime, e2UpdateTime,
27932794
)
27942795
}
27952796

@@ -2814,27 +2815,27 @@ func (c *KVStore) delChannelEdgeUnsafe(edges, edgeIndex, chanIndex,
28142815
// the channel. If the channel were to be marked zombie again, it would be
28152816
// marked with the correct lagging channel since we received an update from only
28162817
// one side.
2817-
func makeZombiePubkeys(info *models.ChannelEdgeInfo,
2818-
e1, e2 *time.Time) ([33]byte, [33]byte) {
2818+
func makeZombiePubkeys(node1, node2 [33]byte, e1, e2 *time.Time) ([33]byte,
2819+
[33]byte) {
28192820

28202821
switch {
28212822
// If we don't have either edge policy, we'll return both pubkeys so
28222823
// that the channel can be resurrected by either party.
28232824
case e1 == nil && e2 == nil:
2824-
return info.NodeKey1Bytes, info.NodeKey2Bytes
2825+
return node1, node2
28252826

28262827
// If we're missing edge1, or if both edges are present but edge1 is
28272828
// older, we'll return edge1's pubkey and a blank pubkey for edge2. This
28282829
// means that only an update from edge1 will be able to resurrect the
28292830
// channel.
28302831
case e1 == nil || (e2 != nil && e1.Before(*e2)):
2831-
return info.NodeKey1Bytes, [33]byte{}
2832+
return node1, [33]byte{}
28322833

28332834
// Otherwise, we're missing edge2 or edge2 is the older side, so we
28342835
// return a blank pubkey for edge1. In this case, only an update from
28352836
// edge2 can resurect the channel.
28362837
default:
2837-
return [33]byte{}, info.NodeKey2Bytes
2838+
return [33]byte{}, node1
28382839
}
28392840
}
28402841

graph/db/sql_migration.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func migrateNodes(ctx context.Context, kvBackend kvdb.Backend,
192192
pub, id, dbNode.ID)
193193
}
194194

195-
migratedNode, err := buildNode(ctx, sqlDB, &dbNode)
195+
migratedNode, err := buildNode(ctx, sqlDB, dbNode)
196196
if err != nil {
197197
return fmt.Errorf("could not build migrated node "+
198198
"from dbNode(db id: %d, node pub: %x): %w",
@@ -410,6 +410,8 @@ func migrateChannelsAndPolicies(ctx context.Context, kvBackend kvdb.Backend,
410410
}
411411

412412
channelCount++
413+
chunk++
414+
413415
err = migrateSingleChannel(
414416
ctx, sqlDB, channel, policy1, policy2, migChanPolicy,
415417
)

0 commit comments

Comments
 (0)