Skip to content

Commit

Permalink
changes as per review
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed May 21, 2021
1 parent 2c9f592 commit 50e023e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions extern/sector-storage/piece_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func (p *pieceProvider) tryReadUnsealedPiece(ctx context.Context, sector storage
// ReadPiece is used to read an Unsealed piece at the given offset and of the given size from a Sector
// If an Unsealed sector file exists with the Piece Unsealed in it, we'll use that for the read.
// Otherwise, we will Unseal a Sealed sector file for the given sector and read the Unsealed piece from it.
// If we do NOT have an existing unsealed file containing the given piece thus causing us to schedule an Unseal,
// the returned boolean parameter will be set to true.
// If we have an existing unsealed file containing the given piece, the returned boolean will be set to false.
func (p *pieceProvider) ReadPiece(ctx context.Context, sector storage.SectorRef, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize, ticket abi.SealRandomness, unsealed cid.Cid) (io.ReadCloser, bool, error) {
if err := offset.Valid(); err != nil {
return nil, false, xerrors.Errorf("offset is not valid: %w", err)
Expand Down
1 change: 0 additions & 1 deletion extern/sector-storage/stores/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ func (handler *FetchHandler) remoteGetSector(w http.ResponseWriter, r *http.Requ
}
} else {
w.Header().Set("Content-Type", "application/octet-stream")
w.WriteHeader(200)
// will do a ranged read over the file at the given path if the caller has asked for a ranged read in the request headers.
http.ServeFile(w, r, path)
}
Expand Down
10 changes: 8 additions & 2 deletions extern/sector-storage/stores/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,13 +560,15 @@ func (r *Remote) Reader(ctx context.Context, s storage.SectorRef, offset, size a
return si[i].Weight > si[j].Weight
})

var lastErr error
for _, info := range si {
for _, url := range info.URLs {
// checkAllocated makes a JSON RPC query to a remote worker to determine if it has
// unsealed piece in their unsealed sector file.
ok, err := r.checkAllocated(ctx, url, s.ProofType, offset, size)
if err != nil {
log.Warnw("check if remote has piece", "url", url, "error", err)
lastErr = err
continue
}
if !ok {
Expand All @@ -578,6 +580,7 @@ func (r *Remote) Reader(ctx context.Context, s storage.SectorRef, offset, size a
rd, err := r.readRemote(ctx, url, offset, size)
if err != nil {
log.Warnw("reading from remote", "url", url, "error", err)
lastErr = err
continue
}
log.Infof("Read remote %s (+%d,%d)", url, offset, size)
Expand All @@ -586,12 +589,15 @@ func (r *Remote) Reader(ctx context.Context, s storage.SectorRef, offset, size a
}

// we couldn't find a unsealed file with the unsealed piece, will return a nil reader.
log.Debugf("returning nil reader, did not find unsealed piece for %+v (+%d,%d)", s, offset, size)
log.Debugf("returning nil reader, did not find unsealed piece for %+v (+%d,%d), last error=%s", s, offset, size, lastErr)
return nil, nil
}

func (r *Remote) Reserve(ctx context.Context, sid storage.SectorRef, ft storiface.SectorFileType, storageIDs storiface.SectorPaths, overheadTab map[storiface.SectorFileType]int) (func(), error) {
panic("not implemented")
log.Warnf("reserve called on remote store, sectorID: %v", sid.ID)
return func() {

}, nil
}

var _ Store = &Remote{}
5 changes: 5 additions & 0 deletions extern/sector-storage/stores/util_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package stores

import (
"bytes"
"os"
"os/exec"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -37,6 +38,10 @@ func move(from, to string) error {

var cmd *exec.Cmd
if runtime.GOOS == "darwin" {
if err := os.MkdirAll(toDir, 0777); err != nil {
return xerrors.Errorf("failed exec MkdirAll: %s", err)
}

cmd = exec.Command("/usr/bin/env", "mv", from, toDir) // nolint
} else {
cmd = exec.Command("/usr/bin/env", "mv", "-t", toDir, from) // nolint
Expand Down

0 comments on commit 50e023e

Please sign in to comment.