-
-
Notifications
You must be signed in to change notification settings - Fork 631
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
[pantsd] Daemon lifecycle for options changes. #5045
[pantsd] Daemon lifecycle for options changes. #5045
Conversation
353ce56
to
1ef31bf
Compare
b43fd8e
to
df179a8
Compare
5fcc82c
to
c32408e
Compare
c32408e
to
148e236
Compare
sep = sep or self.FINGERPRINT_CMD_SEP | ||
cmdline = cmdline or [] | ||
for cmd_part in cmdline: | ||
if cmd_part.startswith('{}='.format(key, sep)): |
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.
s/=/{}/
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.
fixed!
checker.await_pantsd() | ||
|
||
# Check for no stray pantsd-runner prcesses. | ||
self.assertFalse(check_process_exists_by_command('pantsd-runner')) |
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.
There used to be a checker.assert_running()
here which feels important
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.
checker.await_pantsd()
implicitly calls assert_running()
, so it should be equivalent.
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 Kris!
:param list exclude_keys: A list of keys to exclude from fingerprint computation. | ||
""" | ||
exclude_keys = set(exclude_keys or []) | ||
acceptable_types = set((bytes, str, list, tuple, dict, int, float, bool, type(None))) |
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.
Would be good to define this set statically.
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.
removed.
hasher.update(k) | ||
v = self.get(k) | ||
assert type(v) in acceptable_types, 'unhashable option type: {}'.format(type(v)) | ||
# N.B. This relies on implicit string conversion to do the right thing for |
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.
This should use src/python/pants/option/options_fingerprinter.py
to get the correct behaviour for file-options, etc.
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.
refactored.
@@ -169,6 +169,20 @@ def watchman_launcher(self): | |||
def is_killed(self): | |||
return self._kill_switch.is_set() | |||
|
|||
@property | |||
def options_fingerprint(self): | |||
return self._bootstrap_options.sha1( |
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.
There is already a facility for marking options as fingerprint=True
... it would be good to reuse that here if possible:
pants/src/python/pants/option/options.py
Line 320 in 33e98e1
def get_fingerprintable_for_scope(self, scope, include_passthru=False): |
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.
great idea. refactored.
def fingerprint(self): | ||
"""The fingerprint of the current process. | ||
|
||
:returns: The fingerprint of the running process as read from the process table, ProcessManager |
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's not clear why this is an OR... a bit more information about why we would check X then Y would be good.
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.
added a comment in the docstring.
Well, crap. It did not occur to me that so many of these are not already marked fingerprint=True, because they should not affect target fingerprinting. Can probably completely ignore my feedback. Sorry! |
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.
(pre-approving: but you'll need to revert the addition of fingerprint=True
)
826473f
to
279678a
Compare
@stuhood think I see another way - can mark these |
279678a
to
6115528
Compare
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.
This feels cleaner to me then the blacklist of options, so I think it's the right call.
But some sanity check that daemon=True
has been passed outside of global options (I think: for any scope other than the global scope ?) would be good. Another thought would be to see whether it's possible to invert the default in this context.
done and done. |
4e4c8e5
to
53f1141
Compare
53f1141
to
5e85274
Compare
Problem Currently, if options (from cli args, pants.ini, env vars, rc files et al) affecting the daemon change between runs the daemon does not detect this and will happily run with trapped, stale state. Solution Fingerprint the relevant subset of bootstrap options at startup time in the thin client and compare that fingerprint to the one used at launch time for the current pantsd process to determine if the daemon needs to be restarted in advance of the run. This piggy-backs on top of the daemon externalization work. Result Fixes pantsbuild#3941.
Problem
Currently, if options (from cli args, pants.ini, env vars, rc files et al) affecting the daemon change between runs the daemon does not detect this and will happily run with trapped, stale state.
Solution
Fingerprint the relevant subset of bootstrap options at startup time in the thin client and compare that fingerprint to the one used at launch time for the current pantsd process to determine if the daemon needs to be restarted in advance of the run. This piggy-backs on top of the daemon externalization work.
Result
Fixes #3941.