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

many: implement fetching sections and package names periodically. #3866

Merged
merged 11 commits into from
Sep 15, 2017

Conversation

chipaca
Copy link
Contributor

@chipaca chipaca commented Sep 6, 2017

These are then used for quicker tab completion.

These are then used for quicker tab completion.
Copy link
Contributor

@zyga zyga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 with some suggestions.

dirs/dirs.go Outdated
@@ -187,6 +191,10 @@ func SetRootDir(rootdir string) {

SnapStateFile = filepath.Join(rootdir, snappyDir, "state.json")

SnapCacheDir = filepath.Join(rootdir, snappyDir, "cache")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not /var/cache/snapd?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like it to be /var/cache/snapd as well, but that would mean adding that to writable-paths, and I don't know the impact on packaging elsewhere (is /var/cache/{package} universal?); keeping it under snappyDir makes it a no-brainer.

// ensureCatalogRefresh ensures that we refresh the cataloge
// data periodically
func (m *SnapManager) ensureCatalogRefresh() error {
// sneakily don't do anything if in testing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move the mkdir here so that it stays operational even if someone just goes and does rm -rf on the thing after snapd started.

@@ -278,6 +282,9 @@ func Manager(st *state.State) (*SnapManager, error) {
if err := os.MkdirAll(dirs.SnapCookieDir, 0700); err != nil {
return nil, fmt.Errorf("cannot create directory %q: %v", dirs.SnapCookieDir, err)
}
if err := os.MkdirAll(dirs.SnapCacheDir, 0755); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider moving this below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below what?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

below, where his other comment is (or was). I know what he means (and i forgot to do it in my last round)

return err
}

namesFd, err := osutil.NewAtomicFile(dirs.SnapNamesFile, 0644, 0, -1, -1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, much less gray hair today :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: namesFile? namesf? "fd" is generally a file descriptor in this context.

@chipaca
Copy link
Contributor Author

chipaca commented Sep 7, 2017

Marking this blocked so it isn't merged in error (agreed with server-side about sorting the names endpoint, so we'll wait for that)

@chipaca chipaca added this to the 2.29 milestone Sep 7, 2017
ogra1 added a commit to canonical/core-build that referenced this pull request Sep 7, 2017
ogra1 added a commit to canonical/core-build that referenced this pull request Sep 7, 2017
@codecov-io
Copy link

codecov-io commented Sep 12, 2017

Codecov Report

Merging #3866 into master will decrease coverage by 0.07%.
The diff coverage is 55.39%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3866      +/-   ##
==========================================
- Coverage   75.93%   75.85%   -0.08%     
==========================================
  Files         416      416              
  Lines       35983    36122     +139     
==========================================
+ Hits        27325    27402      +77     
- Misses       6744     6794      +50     
- Partials     1914     1926      +12
Impacted Files Coverage Δ
overlord/storestate/storestate.go 100% <ø> (ø) ⬆️
cmd/snap/cmd_find.go 62.5% <0%> (-2.72%) ⬇️
dirs/dirs.go 98% <100%> (+0.08%) ⬆️
cmd/snap/complete.go 57.2% <17.24%> (-5.25%) ⬇️
overlord/snapstate/snapstate.go 80% <37.5%> (-0.87%) ⬇️
store/store.go 79.57% <66.66%> (-0.58%) ⬇️
overlord/snapstate/snapmgr.go 82.29% <92%> (+0.59%) ⬆️
interfaces/builtin/network.go 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 50b555e...a1e630b. Read the comment docs.

Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the new logic, John.

Several trivial nitpicks, and one point we need to address about the new directory.

@@ -456,14 +463,26 @@ func (m *SnapManager) LastRefresh() (time.Time, error) {
return lastRefresh, nil
}

// NextRefresh returns the time the next update of the system's snaps
// will be attempted.
// The caller should be holding the state lock.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comments.

if CanAutoRefresh == nil {
return nil
}
m.state.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer m.state.Unlock()

If there's a reason to unlock at the end, the logic may be reversed for predictable correct termination:

m.state.Unlock()
defer m.state.Lock()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to hold the lock to get the cached store object, and to set the next timeout; I need it unlocked to call refreshCatalogs. So it'd have to be

m.state.Lock()
defer m.state.Unlock()
// do stuff
m.state.Unlock()
defer m.state.Lock()
// do other stuff

I thought it best to avoid the resulting spurious lock/unlock defers

Copy link
Contributor

@niemeyer niemeyer Sep 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll be worse if we get a lock out because something in the middle panics. I'm not quite sure about what's the call chain leading here by now, but if we have a Lock on a restore up chain, this would prevent even the systemd restart that would usually happen, and potentially render a device dead.

Note that the Lock/Unlock is pretty fast if there are no writes inside it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, there's another alternative as well: splitting the logic out into a function.

// catalog refresh does not carry on trying on error
m.nextCatalogRefresh = next
m.state.Unlock()
logger.Debugf("Next catalog refresh scheduled for %s.", next)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be confusing to see that when the next catalog refresh will actually happen right now. Perhaps:

"Catalog refresh starting now and will try again at %s."

return nil
}
m.state.Lock()
aStore := storestate.Store(m.state)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we generally call it theStore inside this package. I don't mind which way we go, but would be nice to eventually have a global convention for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grep agrees with you

return err
}

namesFd, err := osutil.NewAtomicFile(dirs.SnapNamesFile, 0644, 0, -1, -1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: namesFile? namesf? "fd" is generally a file descriptor in this context.

} else {
break
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly easier to read:

if line < match {
        continue
}
if strings.HasPrefix(line, match) {
        ret = append(ret, ...)
        continue
}
break

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll believe you on this one :-)

@@ -288,6 +286,8 @@ func (s *apiBaseSuite) daemon(c *check.C) *Daemon {
Serial: "serialserial",
})

snapstate.CanAutoRefresh = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this moved? Seems much safer to have it very early on while the suite is being setup rather than on a function after much logic has been run, and even the daemon was created.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the overlord manager's init now writes that variable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please have a comment? Seems tempting to move it elsewhere.

@@ -63,10 +62,6 @@ func (s *daemonSuite) checkAuthorizationForPid(pid uint32, actionId string, deta
return s.authorized, s.err
}

func (s *daemonSuite) SetUpSuite(c *check.C) {
snapstate.CanAutoRefresh = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

@@ -15,6 +23,7 @@ prepare: |
expect -d -f key.exp0

restore: |
chattr -i /var/cache/snapd/names
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be removed since prepare created it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

starting snapd created it. Maybe the test should stop snapd, move the old names aside, then do this, and restore it on restore?

Copy link
Contributor

@niemeyer niemeyer Sep 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just remove it again, which sounds easier.. the test just removed it anyway (by overwriting it), and this is the one test that cares the most about this file being right.

@@ -187,6 +191,10 @@ func SetRootDir(rootdir string) {

SnapStateFile = filepath.Join(rootdir, snappyDir, "state.json")

SnapCacheDir = filepath.Join(rootdir, "/var/cache/snapd")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to fix packaging so there's proper ownership on this directory on all distributions, and the packaging purging logic for all distros also need to account for this new directory.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ - indeed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gah. you are correct. See, this is (one of the reasons) why I'd originally had it under /var/lib/snapd -- laziness.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, to be honest I wouldn't mind having these files inside /var/lib/snapd either.

Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Responded to your comments. LGTM once you're satisfied with all points.

The last master merge broke some tests; fixed them.  Addressed the
last few bits of review feedback.  Added packaging bits for suse,
fedora to clean up /var/cache/snapd on remove.
@chipaca chipaca merged commit 79b6e3b into canonical:master Sep 15, 2017
@chipaca chipaca deleted the snap-commands-ng branch September 15, 2017 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants