Fix for race conditions in presistence plugins #1543
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR should fix race problems with lazy-loaded persistent plugins (#1522). It turns out that lazy loading isn't actually needed. Also plugins cache has been refactored to work in safer manner.
[EDIT:30.12.2015] More description
Actual problem seemed to lay in the way the plugin handlers were registered in
Persistence
extension. Because of concurrent access, all parties (i.e. persistent actors) were trying to lazily initialize plugin handler andAddOrUpdate
it to concurrent dictionary - this part was handled correctly. However when there are no entry in dictionary, new plugin was initialized and overriding concurrently updated entry, that may appeared in the meantime, as the default dictionary conflict resolution was to take latest plugin created. However one of the plugin handler actions was new journal actor creation - that means, the latest plugin handler would trigger actor creation failure as that actor was already created by earlier plugin handlers already registered.I think there were two solutions for this problem:
ConcurrentDictionary.GetOrAdd
method - this also seems to solve an issue, but lack of good example to recreate the problem on the first place seems a more riskier to me. Also turning back from concurrent dictionary into combination of atomic + immutable collection seems to be better option.