-
Notifications
You must be signed in to change notification settings - Fork 315
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
Convert supervisor config to global singleton #1246
Conversation
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.
Looks like there are still a couple of CI failures (in test suites?), otherwise I'm liking this version of the code. Despite the raw pointer craziness, its calling API is really straightforward.
/// The package we are supervising | ||
pub package: Arc<RwLock<Package>>, | ||
/// Name of the package being supervised | ||
pub package_name: String, | ||
/// A pointer to our current Config | ||
pub config: &'a Config, |
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.
Bingo. That's a rather nice simplification.
/// Store a configuration, for later use through `gconfig()`. | ||
/// | ||
/// MUST BE CALLED BEFORE ANY CALLS TO `gconfig()`. | ||
pub fn gcache(config: Config) { |
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 presume that if we ever had to update the Config
, we'd call this again with a new copy (I noticed that .gconfig()
doesn't return a mut
borrow)?
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.
Right now, the Config struct is immutable after it is created. It's passed around as a reference, without mutability.
If we decide we want it to be mutable, we will need to refactor into having the static hold a RwLock<Config>
instead. Given that right now, for the supervisor at least, these are only options populated from the CLI, we're fine to let it remain immutable.
57c0a13
to
c1b18ae
Compare
Fixed the test suite - this should pass now. @fnichol, you have to approve my changes for merge. :) |
c1b18ae
to
40acf8d
Compare
Haha, I hold all the keys! |
This commit converts to using a global singleton for configuration, rather than threading a reference to everything that needs configuration data. Since we need to populate our `Config` struct with data from `clap`, we need to be able to modify it at runtime with an argument, rather than simply use `lazy_static!`. This implementation stores the configuration as a static pointer to a location on the heap via `Box`, and updates the pointer via `mem::transmute` in a `gcache()` method. This method is called early in `main` - right after we populate the configuration struct, in fact. Once `gcache()` has been called (one time only; subsequent calls will be ignored), you can access the `Config` struct through the `config::gconfig()` method. This removes all the references to threading an `&Config` through the code base, and replaces them with calls to `gconfig()`. In particular, it cleans up the need for lifetimes in the topology and worker code, which is a nice side effect. Signed-off-by: Adam Jacob <[email protected]>
40acf8d
to
6be32f2
Compare
This commit converts to using a global singleton for configuration,
rather than threading a reference to everything that needs configuration
data.
Since we need to populate our
Config
struct with data fromclap
, weneed to be able to modify it at runtime with an argument, rather than
simply use
lazy_static!
. This implementation stores the configurationas a static pointer to a location on the heap via
Box
, and updatesthe pointer via
mem::transmute
in agcache()
method. This methodis called early in
main
- right after we populate the configurationstruct, in fact.
Once
gcache()
has been called (one time only; subsequent calls will beignored), you can access the
Config
struct through theconfig::gconfig()
method.This removes all the references to threading an
&Config
through thecode base, and replaces them with calls to
gconfig()
.In particular, it cleans up the need for lifetimes in the topology and
worker code, which is a nice side effect.
Signed-off-by: Adam Jacob [email protected]