Skip to content

Commit

Permalink
sqlite,renterd: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Mar 5, 2024
1 parent 73a44dd commit 03fd5eb
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 35 deletions.
3 changes: 3 additions & 0 deletions persist/sqlite/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func normalizeCid(c cid.Cid) cid.Cid {
return cid.NewCidV1(c.Type(), c.Hash())
}

// BlockLocation returns the bucket and object key of a pinned block.
func (s *Store) BlockLocation(c cid.Cid) (bucket, key string, err error) {
c = normalizeCid(c)
err = s.transaction(func(tx *txn) error {
Expand All @@ -31,6 +32,7 @@ INNER JOIN blocks b ON (b.id=pb.block_id) WHERE b.cid=$1`, dbEncode(c)).Scan(&bu
return
}

// Unpin deletes a block from the store.
func (s *Store) Unpin(c cid.Cid) error {
c = normalizeCid(c)
return s.transaction(func(tx *txn) error {
Expand All @@ -39,6 +41,7 @@ func (s *Store) Unpin(c cid.Cid) error {
})
}

// Pin adds a block to the store.
func (s *Store) Pin(b renterd.PinnedBlock) error {
b.Cid = normalizeCid(b.Cid)
s.log.Debug("pinning block", zap.Stringer("cid", b.Cid), zap.String("bucket", b.Bucket), zap.String("objectKey", b.ObjectKey))
Expand Down
10 changes: 4 additions & 6 deletions persist/sqlite/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ func (d *decodable) Scan(src any) error {

switch src := src.(type) {
case string:
switch v := d.v.(type) {
case *cid.Cid:
if v, ok := d.v.(*cid.Cid); ok {
c, err := cid.Parse(src)
if err != nil {
return err
Expand All @@ -47,11 +46,10 @@ func (d *decodable) Scan(src any) error {
return nil
}
case []byte:
switch v := d.v.(type) {
case *uint64:
*v = binary.LittleEndian.Uint64(src)
if v, ok := d.v.(*uint64); ok {
*v = binary.BigEndian.Uint64(src)
return nil
}
return nil
case int64:
switch v := d.v.(type) {
case *uint64:
Expand Down
27 changes: 0 additions & 27 deletions persist/sqlite/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"database/sql"
"math/rand"
"strings"
"time"

_ "github.com/mattn/go-sqlite3" // import sqlite3 driver
Expand Down Expand Up @@ -171,32 +170,6 @@ func (tx *txn) QueryRow(query string, args ...any) *row {
return &row{r, tx.log.Named("row")}
}

func queryPlaceHolders(n int) string {
if n == 0 {
return ""
} else if n == 1 {
return "?"
}
var b strings.Builder
b.Grow(((n - 1) * 2) + 1) // ?,?
for i := 0; i < n-1; i++ {
b.WriteString("?,")
}
b.WriteString("?")
return b.String()
}

func queryArgs[T any](args []T) []any {
if len(args) == 0 {
return nil
}
out := make([]any, len(args))
for i, arg := range args {
out[i] = arg
}
return out
}

// getDBVersion returns the current version of the database.
func getDBVersion(db *sql.DB) (version int64) {
// error is ignored -- the database may not have been initialized yet.
Expand Down
2 changes: 2 additions & 0 deletions renterd/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type (

priorityQueue []*blockResponse

// A MetadataStore is a store for IPFS block metadata. It is used to
// optimize block downloads by prefetching linked blocks.
MetadataStore interface {
BlockLocation(c cid.Cid) (bucket, key string, err error)
BlockSiblings(c cid.Cid, max int) (siblings []cid.Cid, err error)
Expand Down
1 change: 0 additions & 1 deletion renterd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func WithMetadataStore(s MetadataStore) Option {
return func(o *options) {
o.Store = s
}

}

// WithBucket sets the bucket name.
Expand Down
3 changes: 3 additions & 0 deletions renterd/persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package renterd
import "github.com/ipfs/go-cid"

type (
// A PinnedBlock is an IPFS block that is stored on a renterd node.
PinnedBlock struct {
Cid cid.Cid `json:"cid"`
Bucket string `json:"bucket"`
ObjectKey string `json:"objectKey"`
Links []cid.Cid `json:"links"`
}

// A MetadataStore is a store for IPFS block metadata. It is used to
// link blocks to their location on a renterd node.
MetadataStore interface {
Pin(PinnedBlock) error
Unpin(c cid.Cid) error
Expand Down
1 change: 0 additions & 1 deletion renterd/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ func (bs *BlockStore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) {
log := bs.log.Named("AllKeysChan")
ch := make(chan cid.Cid)
go func() {

for i := 0; ; i += 1000 {
cids, err := bs.metadata.Pinned(i, 1000)
if err != nil {
Expand Down

0 comments on commit 03fd5eb

Please sign in to comment.