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

CachingHiveMetastore: refactor cache creation and flushCache() #4872

Closed
wants to merge 2 commits into from
Closed

CachingHiveMetastore: refactor cache creation and flushCache() #4872

wants to merge 2 commits into from

Conversation

iirekm
Copy link

@iirekm iirekm commented Aug 18, 2020

No description provided.

@cla-bot cla-bot bot added the cla-signed label Aug 18, 2020
@iirekm iirekm requested a review from kokosing August 18, 2020 12:34
return loadPartitionsByNames(partitionNames);
}
}, executor));
class CacheFactory
Copy link
Author

Choose a reason for hiding this comment

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

mixture of factory method and method object patterns

tableStatisticsCache.invalidateAll();
partitionStatisticsCache.invalidateAll();
rolesCache.invalidateAll();
caches.forEach(Cache::invalidateAll);
Copy link
Author

Choose a reason for hiding this comment

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

it's nothing new, it's very similar to Closer already used in many places, the difference is that here objects can be 'closed' many times

Copy link
Member

Choose a reason for hiding this comment

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

Nit: We prefer normal for-each loops. Use foreach if there's a specific benefit to doing so, such as the terminal operation of a stream. Note that Map.forEach is far superior to for-each as it avoids unpacking the Entry.

Copy link
Member

@losipiuk losipiuk left a comment

Choose a reason for hiding this comment

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

loop in flushCache LGTM. I do not see a benefit from the rest of this PR.

@@ -114,6 +116,7 @@
private final LoadingCache<HivePrincipal, Set<RoleGrant>> roleGrantsCache;
private final LoadingCache<String, Set<RoleGrant>> grantedPrincipalsCache;
private final LoadingCache<String, Optional<String>> configValuesCache;
private final List<LoadingCache<?, ?>> caches = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

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

Initialize in constructor to ImmutableList

@iirekm
Copy link
Author

iirekm commented Aug 18, 2020 via email

@losipiuk
Copy link
Member

Benefit is: all caches are flushed (previously 4 were missing), code is more readable, avoids errors that somebody forgot to call caches.add

Fine :) THanks

@electrum
Copy link
Member

For the commit message, we write the title like a phrase or sentence, rather than prefixing with a component. So something like

Refactor Hive cache creation and flushing

Copy link
Member

@kokosing kokosing left a comment

Choose a reason for hiding this comment

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

Looks good % comments

return loadPartitionsByNames(partitionNames);
}
}, executor));
class CacheFactory
Copy link
Member

Choose a reason for hiding this comment

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

please extract private static inner class. Class definition inside the method body is hard to follow.

Copy link
Author

Choose a reason for hiding this comment

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

If it was deeper, it would be a good candidate for moving "up"; everything not too nested (let's say up to 4-5 nested { / }) is not a readability problem on today's wide screens; it even improves readability (moving this "up" would mean some boilerplate like explicit field and constructor declarations).

I think it's possible to configure Checkstyle such way: allow up to some 5 nested {s, block more than that.

Copy link
Author

Choose a reason for hiding this comment

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

in intellij it's possible to configure in Inspections > Class metrics / Method metrics

@@ -13,6 +13,8 @@
*/
Copy link
Member

Choose a reason for hiding this comment

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

WRT to commit message. It looks like the refactor is not the most important change here. The most important part is that you added missing invalidate for caches. And refactor is only about preventing this to happen in future again. Please consider writing better commit message.

Copy link
Author

Choose a reason for hiding this comment

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

couldn't find a better message: it's not just a bugfix, but also refactoring to remove duplication

Copy link
Member

Choose a reason for hiding this comment

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

it's not just a bugfix, but also refactoring to remove duplication

So maybe two commits. One bugfix. Second refactofing. WDYT?

@iirekm iirekm requested a review from kokosing August 24, 2020 10:21
@colebow
Copy link
Member

colebow commented Oct 19, 2022

👋 @iirekm - this PR has become inactive. If you're still interested in working on it, please let us know, and we can try to get reviewers to help with that.

We're working on closing out old and inactive PRs, so if you're too busy or this has too many merge conflicts to be worth picking back up, we'll be making another pass to close it out in a few weeks.

@colebow colebow closed this Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

5 participants