Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

siva: skip locations still not done in repo iter #54

Merged
merged 1 commit into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions siva/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ func (l *Location) checkAndUpdate() error {
return err
}

err = l.updateCache(cp)
if err != nil {
return err
if cp.Offset() > 0 {
err = l.updateCache(cp)
if err != nil {
return err
}
}

l.checkpoint = cp
Expand Down Expand Up @@ -162,6 +164,9 @@ func (l *Location) FS(mode borges.Mode) (sivafs.SivaFS, error) {
func (l *Location) fs(mode borges.Mode, cp *checkpoint) (sivafs.SivaFS, error) {
if mode == borges.ReadOnlyMode {
offset := cp.Offset()
if offset == 0 {
return nil, borges.ErrLocationNotExists.New(string(l.id))
}

if l.metadata != nil {
version := l.lib.Version()
Expand Down
40 changes: 23 additions & 17 deletions util/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,33 @@ func NewLocationRepositoryIterator(locs []borges.Location, mode borges.Mode) *Lo
// Next returns the next repository from the iterator. If the iterator has
// reached the end it will return io.EOF as an error.
func (iter *LocationRepositoryIterator) Next() (borges.Repository, error) {
if len(iter.locs) == 0 {
return nil, io.EOF
}
for {
if len(iter.locs) == 0 {
return nil, io.EOF
}

if iter.iter == nil {
i, err := iter.locs[0].Repositories(iter.mode)
if err != nil {
iter.locs = iter.locs[1:]
return nil, err
if iter.iter == nil {
i, err := iter.locs[0].Repositories(iter.mode)
if err != nil {
iter.locs = iter.locs[1:]
return nil, err
}
iter.iter = i
}
iter.iter = i
}

r, err := iter.iter.Next()
if err == io.EOF {
iter.locs = iter.locs[1:]
iter.iter = nil
return iter.Next()
r, err := iter.iter.Next()
switch err {
case nil:
return r, err
case io.EOF:
iter.locs = iter.locs[1:]
iter.iter = nil
default:
if !borges.ErrLocationNotExists.Is(err) {
return nil, err
}
}
}

return r, err
}

// ForEach call the function for each object contained on this iter until
Expand Down