-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
redo: don't re-provide blocks we've provided very recently (take 2)
this redoes (again) 582e5de. License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
- Loading branch information
Showing
6 changed files
with
52 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,9 @@ type BlockService interface { | |
|
||
type blockService struct { | ||
// TODO don't expose underlying impl details | ||
blockstore blockstore.Blockstore | ||
exchange exchange.Interface | ||
blockstore blockstore.Blockstore | ||
exchange exchange.Interface | ||
checkFirst bool | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
// an Object is simply a typed block | ||
|
@@ -56,6 +57,21 @@ func New(bs blockstore.Blockstore, rem exchange.Interface) BlockService { | |
return &blockService{ | ||
blockstore: bs, | ||
exchange: rem, | ||
checkFirst: true, | ||
} | ||
} | ||
|
||
// NewWriteThrough ceates a BlockService that guarantees writes we go | ||
// through to the blockstore | ||
This comment has been minimized.
Sorry, something went wrong. |
||
func NewWriteThrough(bs blockstore.Blockstore, rem exchange.Interface) BlockService { | ||
if rem == nil { | ||
log.Warning("blockservice running in local (offline) mode.") | ||
} | ||
|
||
return &blockService{ | ||
blockstore: bs, | ||
exchange: rem, | ||
checkFirst: false, | ||
} | ||
} | ||
|
||
|
@@ -70,22 +86,19 @@ func (bs *blockService) Exchange() exchange.Interface { | |
// AddBlock adds a particular block to the service, Putting it into the datastore. | ||
// TODO pass a context into this if the remote.HasBlock is going to remain here. | ||
func (s *blockService) AddObject(o Object) (*cid.Cid, error) { | ||
// TODO: while this is a great optimization, we should think about the | ||
// possibility of streaming writes directly to disk. If we can pass this object | ||
// all the way down to the datastore without having to 'buffer' its data, | ||
// we could implement a `WriteTo` method on it that could do a streaming write | ||
// of the content, saving us (probably) considerable memory. | ||
c := o.Cid() | ||
has, err := s.blockstore.Has(key.Key(c.Hash())) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if s.checkFirst { | ||
has, err := s.blockstore.Has(key.Key(c.Hash())) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if has { | ||
return c, nil | ||
if has { | ||
return c, nil | ||
} | ||
} | ||
|
||
err = s.blockstore.Put(o) | ||
err := s.blockstore.Put(o) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -103,13 +116,14 @@ func (s *blockService) AddObjects(bs []Object) ([]*cid.Cid, error) { | |
for _, b := range bs { | ||
c := b.Cid() | ||
|
||
has, err := s.blockstore.Has(key.Key(c.Hash())) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if has { | ||
continue | ||
if s.checkFirst { | ||
This comment has been minimized.
Sorry, something went wrong.
whyrusleeping
Member
|
||
has, err := s.blockstore.Has(key.Key(c.Hash())) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if has { | ||
continue | ||
} | ||
} | ||
|
||
toput = append(toput, b) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
would like a comment here explaining what this does