-
Notifications
You must be signed in to change notification settings - Fork 110
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
RSDK-8598 - Replace cache after sync #4343
Conversation
Saw this failure showing up in tests, e.g:
|
@maximpertsov @dgottlieb tests are passing and properly ready for review now. Also tests manually with both local and cloud configs, in both online/offline startup cases |
config/config.go
Outdated
@@ -238,6 +244,30 @@ func (c Config) FindComponent(name string) *resource.Config { | |||
return nil | |||
} | |||
|
|||
// SetUnprocessedConfig sets unprocessedConfig with a copy of the config passed in. | |||
func (c *Config) SetUnprocessedConfig(cfg *Config) error { | |||
cpy, err := cfg.CopyOnlyPublicFields() |
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'm assuming json.MarshalIndent
only writes public fields and therefore we're confident CopyOnlyPublicFields
is the only thing stuff we need to pull out into a copy?
Having SetUnprocessedConfig
doing the marshalling would be obviously equivalent to me. But happy to just get an OK and not worry about 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.
yep, it's the same.
definitely could marshal earlier as well, went ahead and did that
robot/impl/local_robot.go
Outdated
@@ -1174,13 +1174,6 @@ func (r *localRobot) applyLocalModuleVersions(cfg *config.Config) { | |||
} | |||
|
|||
func (r *localRobot) reconfigure(ctx context.Context, newConfig *config.Config, forceSync bool) { | |||
r.configRevisionMu.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.
Is the consequence here that we now only report a newer config revision after* package downloading succeeds?
Also I don't see the configRevisionMu being locked. Is that 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.
the missing lock is a miss, added it back in.
thinking about it more, the config revision should update at the top of the function so users will know the new config did get pulled and is being processed. In theory, it may make sense to rollback the revision if we exit reconfiguration if download fails, but I also think it's ok to keep the new revision as a sign that the new config did get loaded. whether we revert the revision or not, it will be unclear what state robot reconfiguration is in, so maybe we need to add more information in there
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 know @maximpertsov and I talked about how to represent "mixed" state when a new revision is being applied/doesn't apply completely.
so maybe we need to add more information in there
I agree the only path to do better is to add more information. And I agree it's best to do that thinking/work in a separate ticket.
config/config.go
Outdated
// unprocessedConfig stores the unprocessed version of the config that will be cached. | ||
// This version is kept because the config is changed as it moves through the system. | ||
unprocessedConfig *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.
[minor] maybe we can shorten this field name - conceptually an "unprocessed" config is the marshaled config struct, right?
// unprocessedConfig stores the unprocessed version of the config that will be cached. | |
// This version is kept because the config is changed as it moves through the system. | |
unprocessedConfig *Config | |
// raw stores the unprocessed version of the config that will be cached. | |
// This version is kept because the config is changed as it moves through the system. | |
raw *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.
changed the name to toCache
to be clearer, what do you think?
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.
yep makes sense
@@ -238,6 +245,29 @@ func (c Config) FindComponent(name string) *resource.Config { | |||
return nil | |||
} | |||
|
|||
// SetToCache sets toCache with a marshalled copy of the config passed in. | |||
func (c *Config) SetToCache(cfg *Config) error { |
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.
[minor] this method is public to accommodate it's usage in config/watcher_test.go
right? or are we planning to use it other packages as well? If the former, I suggest we make this method private and define a public version of it in config/export_test.go
. This seems to be a common pattern that the golang standard library uses to export test-only functions that are used across different packages and _test
modules.
(This is a general pattern we can use around our code-base to if we like 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.
I think being public here is fine -- even if for the sake of testing. Data tried playing games with keeping things private, but publishing selective things for testing and it became a huge mess.
I think if we want to be aggressive about making things private and paying a code complexity/readability cost elsewhere, we should start making tangible measurements for when a public method creates a problem .
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.
will leave as is for now
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 being public here is fine -- even if for the sake of testing. Data tried playing games with keeping things private, but publishing selective things for testing and it became a huge mess.
What made it a mess? Was it unclear what methods were actually public vs public for testing only? If so, I think we can clarify that with some simple sign-posts like requiring any test-only method to take a testing.TB
interface or something like that. But in any case I don't feel too strongly about this. Happy to leave as is.
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.
What made it a mess? Was it unclear what methods were actually public vs public for testing only?
No, worse. The indirection resulted in a bunch of interfaces. And finding out which method was getting called (in testing and* in production) was impossible without knowing how the magic worked.
If I wanted to pick a single file as the starting point, I'd say it's this file.
What is a DMService? What is a ManagerConstructor? Following the ManagerConstructor definition, what is a datasync.Manager? Is the *datamanger.builtin.builtin
type a datamanager.internal.DMService
? Is it a DMService if testing is not enabled? Does that even matter?
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.
woah, that file adds a test-only global? that's a bit confusing...
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 is definitely an improvement! i have one small suggestion to minimize the config's public API, but otherwise looks good.
going to pare down changes so that the first set of changes will be a strict improvement while we continue discussions for a more complete solution