From afd2323d102973c0c3186f9b83e0466b365288a0 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 26 Dec 2016 22:02:40 -0600 Subject: [PATCH] channeldb: use a read-txn rather than a write-txn in FetchChannelEdgesByID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- channeldb/graph.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/channeldb/graph.go b/channeldb/graph.go index 38ab863e1..83d81aa92 100644 --- a/channeldb/graph.go +++ b/channeldb/graph.go @@ -1075,24 +1075,24 @@ func (c *ChannelGraph) FetchChannelEdgesByID(chanID uint64) (*ChannelEdge, *Chan 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 // the Node pointers in each edge read from disk. - nodes, err := tx.CreateBucketIfNotExists(nodeBucket) - if err != nil { - return err + nodes := tx.Bucket(nodeBucket) + if nodes == nil { + return ErrGraphNotFound } // Next, grab the edge bucket which stores the edges, and also // the index itself so we can group the directed edges together // logically. - edges, err := tx.CreateBucketIfNotExists(edgeBucket) - if err != nil { - return err + edges := tx.Bucket(edgeBucket) + if edges == nil { + return ErrGraphNoEdgesFound } - edgeIndex, err := edges.CreateBucketIfNotExists(edgeIndexBucket) - if err != nil { - return err + edgeIndex := edges.Bucket(edgeIndexBucket) + if edgeIndex == nil { + return ErrGraphNoEdgesFound } byteOrder.PutUint64(channelID[:], chanID)