channeldb: use a read-txn rather than a write-txn in FetchChannelEdgesByID

This commit modifies the FetchChannelEdgesByID slightly to use a
read-only transaction rather than a write-only transaction. As a result
we’ll no longer extraneously consume a writer’s slot when we’re only
reading data from the database.
This commit is contained in:
Olaoluwa Osuntokun 2016-12-26 22:02:40 -06:00
parent e0d94b545c
commit afd2323d10
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -1075,24 +1075,24 @@ func (c *ChannelGraph) FetchChannelEdgesByID(chanID uint64) (*ChannelEdge, *Chan
channelID [8]byte channelID [8]byte
) )
err := c.db.Update(func(tx *bolt.Tx) error { err := c.db.View(func(tx *bolt.Tx) error {
// First, grab the node bucket. This will be used to populate // First, grab the node bucket. This will be used to populate
// the Node pointers in each edge read from disk. // the Node pointers in each edge read from disk.
nodes, err := tx.CreateBucketIfNotExists(nodeBucket) nodes := tx.Bucket(nodeBucket)
if err != nil { if nodes == nil {
return err return ErrGraphNotFound
} }
// Next, grab the edge bucket which stores the edges, and also // Next, grab the edge bucket which stores the edges, and also
// the index itself so we can group the directed edges together // the index itself so we can group the directed edges together
// logically. // logically.
edges, err := tx.CreateBucketIfNotExists(edgeBucket) edges := tx.Bucket(edgeBucket)
if err != nil { if edges == nil {
return err return ErrGraphNoEdgesFound
} }
edgeIndex, err := edges.CreateBucketIfNotExists(edgeIndexBucket) edgeIndex := edges.Bucket(edgeIndexBucket)
if err != nil { if edgeIndex == nil {
return err return ErrGraphNoEdgesFound
} }
byteOrder.PutUint64(channelID[:], chanID) byteOrder.PutUint64(channelID[:], chanID)