Skip to content

Commit c34091e

Browse files
committed
add size to FilStorage, add Query method for CidInfo
Signed-off-by: Aaron Sutula <hi@asutula.com>
1 parent bcd5578 commit c34091e

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

ffs/filcold/filcold.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ func (fc *FilCold) waitForDeals(ctx context.Context, c cid.Cid, storeResults []d
242242
Duration: duration,
243243
Miner: d.Config.Miner,
244244
ActivationEpoch: di.ActivationEpoch,
245+
Size: di.Size,
245246
}
246247
delete(notDone, di.ProposalCid)
247248
fc.l.Log(ctx, c, "Deal %d with miner %s is active on-chain", di.DealID, di.Miner)

ffs/scheduler/cistore/cistore.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import (
66

77
"github.com/ipfs/go-cid"
88
"github.com/ipfs/go-datastore"
9+
"github.com/ipfs/go-datastore/query"
10+
logging "github.com/ipfs/go-log/v2"
911
"github.com/textileio/powergate/ffs"
1012
"github.com/textileio/powergate/ffs/scheduler"
1113
)
1214

1315
var (
1416
dsBase = datastore.NewKey("cistore")
17+
log = logging.Logger("ffs-sched-cistore")
1518
)
1619

1720
// Store is an Datastore implementation of CidInfoStore
@@ -59,6 +62,32 @@ func (s *Store) Put(ci ffs.CidInfo) error {
5962
return nil
6063
}
6164

65+
// Query returns a list of CidInfo
66+
func (s *Store) Query(selector func(ffs.CidInfo) bool) ([]ffs.CidInfo, error) {
67+
q := query.Query{Prefix: ""}
68+
res, err := s.ds.Query(q)
69+
if err != nil {
70+
return nil, fmt.Errorf("executing query in datastore: %s", err)
71+
}
72+
defer func() {
73+
if err := res.Close(); err != nil {
74+
log.Errorf("closing query result: %s", err)
75+
}
76+
}()
77+
78+
var infos []ffs.CidInfo
79+
for r := range res.Next() {
80+
var i ffs.CidInfo
81+
if err := json.Unmarshal(r.Value, &i); err != nil {
82+
return nil, fmt.Errorf("unmarshalling push config action in query: %s", err)
83+
}
84+
if selector(i) {
85+
infos = append(infos, i)
86+
}
87+
}
88+
return infos, nil
89+
}
90+
6291
func makeKey(c cid.Cid) datastore.Key {
6392
return dsBase.ChildString(c.String())
6493
}

ffs/scheduler/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ type ActionStore interface {
5656
type CidInfoStore interface {
5757
Put(ffs.CidInfo) error
5858
Get(cid.Cid) (ffs.CidInfo, error)
59+
Query(func(ffs.CidInfo) bool) ([]ffs.CidInfo, error)
5960
}

ffs/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ type FilStorage struct {
336336
Duration int64
337337
ActivationEpoch int64
338338
Miner string
339+
Size uint64
339340
}
340341

341342
// CidLoggerCtxKey is a type to use in ctx values for CidLogger.

0 commit comments

Comments
 (0)