-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat: improve locking: lock only after fetch completed #90
Conversation
@faqiharifian I have one concern: right now the Init method does three things:
With the proposed change, we split it into three independent critical sections, and it is possible, for example, new requests will be processed after initProjectSegmenters() and before initExperiments(). What is the chance that the state will be inconsistent? What do you think about refactoring it to something like:
|
if existingSettings.GetProjectId() == projectSettings.GetProjectId() { | ||
return nil | ||
} | ||
existingProjectSettings := s.findProjectSettingsById(ProjectId(projectSettings.GetProjectId())) |
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.
if the locking mechanism is not running in here yet, is it possible that there will be two client who requests the same ProjectID
, and therefore the s.ProjectSettings
in here will have duplicate item?
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 just moving things around to optimize the locking, there's no new logic added in this MR and this method is not used by the Poller changes we introduced previously. Will not do it in this MR.
|
||
// In case new project was just created and we are subscribed to its ID | ||
// we'll try to retrieve it from management service | ||
projectSettings, err := s.fetchProjectSettingsWithId(projectId) |
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 we put the !ContainsProjectId(s.subscribedProjectIds, projectId)
before this function? It is possible that projectSettings
above is still nil, not because just the project can't be find, but also we don't subscribe to this project. If this is intended with the new change, perhaps can modify the comment above 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.
Not sure about the intention of this, I just moving things around to optimize the locking, including the comment
What this PR does / why we need it:
When pubsub disabled and poll enabled, every time poller runs XP treatment service tries to acquire write lock and the treatment service refreshes the local storage by doing multiple calls to management service and update the data/maps.
This causes other part that use RLock to be blocked until all the calls and update are done.
This MR moved the write lock to after all the calls are completed, this reduces duration of RLock being blocked