Skip to content
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

Fix type assertion in AdaptiveDirectoryCacheMaintainer #2525

Merged

Conversation

ReubenBond
Copy link
Member

@ReubenBond ReubenBond commented Dec 16, 2016

Fixes an error in AdaptiveDirectoryCacheMaintainer which was performing a type check which would never succeed. TValue in the below code is always IReadOnlyList<Tuple<SiloAddress, ActivationId>>, but the type check assumed it was List<Tuple<SiloAddress, ActivationId>>.

See the //TODO: below for the source of the error.

This removes the check and pushes the responsibility onto the caller.

@@ -14,14 +13,19 @@ internal class AdaptiveDirectoryCacheMaintainer<TValue> : AsynchAgent

private readonly AdaptiveGrainDirectoryCache<TValue> cache;
private readonly LocalGrainDirectory router;
private readonly Func<List<ActivationAddress>, TValue> updateFunc;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update function is not a great name, but can't think of a better one.
This pattern, over all, is awful, but not sure how to fix it, atm. :/
No change requested.. just making noises as bits of my soul die.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair call. Originally I labelled it cacheUpdateFunc, but maybe cacheRefreshCallback or cacheMaintenanceCallback - I don't know. I'm not very familiar with this end of the codebase yet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, I don't think the pattern here is that bad.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the name, it seems to be a translation function. It translates the list of activation addresses to whatever the cache is storing. Since there are no assumptions may about the cached data there is no general way to translate, hence the need for a function. While this is not horrible, it definitely smells. Maybe using some sort of functor, like dictionaries use comparers, provided as a generic might be a cleaner approach. AdaptiveDirectoryCacheMaintainer<TValue,TTranslator>? In any case, this pattern at least deserves a look at for refactoring, but I understand that such is beyond the scope of this bugfix.

@jason-bragg
Copy link
Contributor

LGTM

@jason-bragg jason-bragg merged commit cb79c6e into dotnet:master Dec 16, 2016
@ReubenBond ReubenBond deleted the fix-directorycache-typeassertion branch February 23, 2017 09:58
@github-actions github-actions bot locked and limited conversation to collaborators Dec 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants