feat: improve locking: lock only after fetch completed#90
feat: improve locking: lock only after fetch completed#90mbruner merged 4 commits intocaraml-dev:mainfrom
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.
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.
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.
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.
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