From: Matt Joiner Date: Wed, 31 Aug 2016 11:00:44 +0000 (+1000) Subject: storage.boltDB: Some comments, and use global completedValue X-Git-Tag: v1.0.0~598 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=db3be3441f72025e4db40eef70f6ee3121517d60;p=btrtrc.git storage.boltDB: Some comments, and use global completedValue --- diff --git a/storage/boltdb.go b/storage/boltdb.go index f65382b3..b7c40645 100644 --- a/storage/boltdb.go +++ b/storage/boltdb.go @@ -5,19 +5,30 @@ import ( "io" "path/filepath" + "github.com/anacrolix/missinggo" "github.com/boltdb/bolt" "github.com/anacrolix/torrent/metainfo" ) -const chunkSize = 1 << 14 +const ( + // Chosen to match the usual chunk size in a torrent client. This way, + // most chunk writes are to exactly one full item in bolt DB. + chunkSize = 1 << 14 +) var ( - data = []byte("data") + // The key for the data bucket. + data = []byte("data") + // The key for the completion flag bucket. completed = []byte("completed") + // The value to assigned to pieces that are complete in the completed + // bucket. + completedValue = []byte{1} ) type boltDBClient struct { + // TODO: This is never closed. db *bolt.DB } @@ -76,7 +87,7 @@ func (me *boltDBPiece) MarkComplete() error { if err != nil { return } - b.Put(me.key[:], make([]byte, 1)) + b.Put(me.key[:], completedValue) return }) }