lotus/storage/sectorblocks/blockstore.go

78 lines
1.6 KiB
Go
Raw Normal View History

2019-08-26 10:04:57 +00:00
package sectorblocks
2019-08-26 08:02:26 +00:00
import (
2019-08-26 10:04:57 +00:00
"context"
2019-08-27 18:45:21 +00:00
"github.com/ipfs/go-block-format"
2019-08-26 08:02:26 +00:00
"github.com/ipfs/go-cid"
2019-08-27 18:45:21 +00:00
blockstore "github.com/ipfs/go-ipfs-blockstore"
2019-08-26 08:02:26 +00:00
)
2019-08-27 18:45:21 +00:00
type SectorBlockStore struct {
// local blockstore.Blockstore // staging before GC // TODO: Pass staging
sectorBlocks *SectorBlocks
2019-08-26 09:08:39 +00:00
2019-08-27 18:45:21 +00:00
approveUnseal func() error
2019-08-26 08:02:26 +00:00
}
2019-08-27 18:45:21 +00:00
func (s *SectorBlockStore) DeleteBlock(cid.Cid) error {
panic("not supported")
2019-08-26 09:08:39 +00:00
}
2019-08-27 18:45:21 +00:00
func (s *SectorBlockStore) GetSize(cid.Cid) (int, error) {
panic("not supported")
2019-08-26 08:02:26 +00:00
}
2019-08-27 18:45:21 +00:00
func (s *SectorBlockStore) Put(blocks.Block) error {
panic("not supported")
2019-08-26 08:02:26 +00:00
}
2019-08-27 18:45:21 +00:00
func (s *SectorBlockStore) PutMany([]blocks.Block) error {
panic("not supported")
2019-08-26 08:02:26 +00:00
}
2019-08-27 18:45:21 +00:00
func (s *SectorBlockStore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) {
panic("not supported")
}
2019-08-26 08:02:26 +00:00
2019-08-27 18:45:21 +00:00
func (s *SectorBlockStore) HashOnRead(enabled bool) {
panic("not supported")
2019-08-26 08:02:26 +00:00
}
2019-08-27 18:45:21 +00:00
func (s *SectorBlockStore) Has(c cid.Cid) (bool, error) {
/*has, err := s.local.Has(c) // TODO: Pass staging
2019-08-26 08:02:26 +00:00
if err != nil {
2019-08-27 18:45:21 +00:00
return false, err
2019-08-26 08:02:26 +00:00
}
2019-08-27 18:45:21 +00:00
if has {
return true, nil
}*/
2019-08-26 08:02:26 +00:00
2019-08-27 18:45:21 +00:00
return s.sectorBlocks.Has(c)
2019-08-26 08:02:26 +00:00
}
2019-08-26 10:04:57 +00:00
2019-08-27 18:45:21 +00:00
func (s *SectorBlockStore) Get(c cid.Cid) (blocks.Block, error) {
/*val, err := s.local.Get(c) // TODO: Pass staging
if err == nil {
return val, nil
2019-08-26 10:04:57 +00:00
}
2019-08-27 18:45:21 +00:00
if err != blockstore.ErrNotFound {
return nil, err
}*/
2019-08-26 10:04:57 +00:00
2019-08-27 18:45:21 +00:00
refs, err := s.sectorBlocks.GetRefs(c)
2019-08-26 10:04:57 +00:00
if err != nil {
return nil, err
}
2019-08-27 18:45:21 +00:00
if len(refs) == 0 {
return nil, blockstore.ErrNotFound
2019-08-26 10:04:57 +00:00
}
2019-08-27 18:45:21 +00:00
data, err := s.sectorBlocks.unsealed.getRef(context.TODO(), refs, s.approveUnseal)
2019-08-26 13:45:36 +00:00
if err != nil {
return nil, err
}
2019-08-27 18:45:21 +00:00
return blocks.NewBlockWithCid(data, c)
2019-08-26 13:45:36 +00:00
}
2019-08-27 18:45:21 +00:00
var _ blockstore.Blockstore = &SectorBlockStore{}