-
Notifications
You must be signed in to change notification settings - Fork 601
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
Conversation
These are then used for quicker tab completion.
There was a problem hiding this 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") |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
overlord/snapstate/snapmgr.go
Outdated
// ensureCatalogRefresh ensures that we refresh the cataloge | ||
// data periodically | ||
func (m *SnapManager) ensureCatalogRefresh() error { | ||
// sneakily don't do anything if in testing |
There was a problem hiding this comment.
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.
overlord/snapstate/snapmgr.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Below what?
There was a problem hiding this comment.
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)
overlord/snapstate/snapstate.go
Outdated
return err | ||
} | ||
|
||
namesFd, err := osutil.NewAtomicFile(dirs.SnapNamesFile, 0644, 0, -1, -1) |
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
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.
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) |
30a382c
to
fb5d914
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
There was a problem hiding this 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. |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
overlord/snapstate/snapmgr.go
Outdated
// catalog refresh does not carry on trying on error | ||
m.nextCatalogRefresh = next | ||
m.state.Unlock() | ||
logger.Debugf("Next catalog refresh scheduled for %s.", next) |
There was a problem hiding this comment.
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."
overlord/snapstate/snapmgr.go
Outdated
return nil | ||
} | ||
m.state.Lock() | ||
aStore := storestate.Store(m.state) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grep agrees with you
overlord/snapstate/snapstate.go
Outdated
return err | ||
} | ||
|
||
namesFd, err := osutil.NewAtomicFile(dirs.SnapNamesFile, 0644, 0, -1, -1) |
There was a problem hiding this comment.
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.
cmd/snap/complete.go
Outdated
} else { | ||
break | ||
} | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :-)
daemon/api_test.go
Outdated
@@ -288,6 +286,8 @@ func (s *apiBaseSuite) daemon(c *check.C) *Daemon { | |||
Serial: "serialserial", | |||
}) | |||
|
|||
snapstate.CanAutoRefresh = nil |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
tests/main/completion/task.yaml
Outdated
@@ -15,6 +23,7 @@ prepare: | | |||
expect -d -f key.exp0 | |||
|
|||
restore: | | |||
chattr -i /var/cache/snapd/names |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ - indeed
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
acccc7d
to
f7e1493
Compare
These are then used for quicker tab completion.