Skip to content

Commit

Permalink
fix(fsi): fsi.ReadDir sets the '/fsi' path prefix
Browse files Browse the repository at this point in the history
allows outside systems to distinguish datasets read from an FSI dir
  • Loading branch information
b5 committed Nov 30, 2020
1 parent 938060a commit 3d64468
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
2 changes: 2 additions & 0 deletions cmd/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ type SearchTestRunner struct {
}

// NewSearchTestRunner sets up state needed for the search test
// TODO (b5) - add an explicit RepoPath to the SearchTestRunner. Tests are
// relying on the "RootPath" property, which should be configurable per-test
func NewSearchTestRunner(t *testing.T) *SearchTestRunner {
run := SearchTestRunner{}

Expand Down
29 changes: 21 additions & 8 deletions fsi/fsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,29 @@ var (
ErrNoLink = fmt.Errorf("dataset is not linked to the filesystem")
)

// PathPrefix indicates paths that are using file system integration
const PathPrefix = "/fsi"

// FilesystemPathToLocal converts a qfs.Filesystem path that has an /fsi prefix
// to a local path
func FilesystemPathToLocal(qfsPath string) string {
return strings.TrimPrefix(qfsPath, "/fsi")
return strings.TrimPrefix(qfsPath, PathPrefix)
}

func localPathToFSIPath(absLocalPath string) string {
if absLocalPath == "" {
return ""
}
if strings.HasPrefix(absLocalPath, PathPrefix) {
return absLocalPath
}
return fmt.Sprintf("%s%s", PathPrefix, absLocalPath)
}

// IsFSIPath is a utility function that returns whether the given path is a
// local filesystem path
func IsFSIPath(path string) bool {
return strings.HasPrefix(path, PathPrefix)
}

// GetLinkedFilesysRef returns whether a directory is linked to a dataset in your repo, and
Expand Down Expand Up @@ -99,18 +118,12 @@ func (fsi *FSI) ResolvedPath(ref *dsref.Ref) error {
}

if vi.FSIPath != "" {
ref.Path = fmt.Sprintf("/fsi%s", vi.FSIPath)
ref.Path = fmt.Sprintf("%s%s", PathPrefix, vi.FSIPath)
return nil
}
return ErrNoLink
}

// IsFSIPath is a utility function that returns whether the given path is a
// local filesystem path
func IsFSIPath(path string) bool {
return strings.HasPrefix(path, "/fsi")
}

// ListLinks returns a list of linked datasets and their connected
// directories
func (fsi *FSI) ListLinks(offset, limit int) ([]dsref.VersionInfo, error) {
Expand Down
1 change: 1 addition & 0 deletions fsi/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func ReadDir(dir string) (*dataset.Dataset, error) {
if err != nil {
return nil, err
}
ds.Path = localPathToFSIPath(ds.Path)
return ds, nil
}

Expand Down
9 changes: 4 additions & 5 deletions stats/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"math"
"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -169,8 +170,6 @@ func (c *localCache) cacheKey(key string) string {
return b32Enc.EncodeToString([]byte(key))
}

const uintSize = 32 << (^uint(0) >> 32 & 1)

func (c *localCache) addAndPurgeExpired(cacheKey string, statProps, targetProps didmod.Props) {
c.infoLk.Lock()
defer c.infoLk.Unlock()
Expand All @@ -180,15 +179,15 @@ func (c *localCache) addAndPurgeExpired(cacheKey string, statProps, targetProps

var (
lowestKey string
lowestModTime int
lowestModTime int64
)

for c.info.Size() > c.maxSize {
lowestKey = ""
lowestModTime = 1<<(uintSize-1) - 1
lowestModTime = math.MaxInt64

for key, fileProps := range c.info.StatFileProps {
if int(fileProps.Mtime.Unix()) < lowestModTime && key != cacheKey {
if fileProps.Mtime.Unix() < lowestModTime && key != cacheKey {
lowestKey = key
}
}
Expand Down
6 changes: 1 addition & 5 deletions stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import (

var log = logger.Logger("stats")

func init() {
logger.SetLogLevel("stats", "debug")
}

// Service can generate an array of statistical info for a dataset
type Service struct {
cache Cache
Expand Down Expand Up @@ -117,7 +113,7 @@ func (s *Service) cacheKey(ds *dataset.Dataset) (string, error) {
if fsi.IsFSIPath(ds.Path) {
// if the passed-in dataset is FSI-linked, use the body file
// as a basis for the cache key
// TODO(b5) - the design of this system means changing the structure
// TODO(b5) - using only one file as a target means changing the structure
// component can't invalidate the cache. We should be able to specify
// an arbitrary number of target files for cache invalidation along with
// a single canonical path
Expand Down

0 comments on commit 3d64468

Please sign in to comment.