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

HIVE-25892: Group HMSHandler's thread locals into a single context #2967

Merged
merged 6 commits into from
Feb 10, 2022

Conversation

dengzhhu653
Copy link
Member

What changes were proposed in this pull request?

Why are the changes needed?

Does this PR introduce any user-facing change?

How was this patch tested?

@pvary
Copy link
Contributor

pvary commented Jan 25, 2022

Could we provide a way to clear the context? In Iceberg we create a HMS instance for our tests, and because of the threadlocals here and in the TxnHandler we leak information between the tests.

@dengzhhu653
Copy link
Member Author

Could we provide a way to clear the context? In Iceberg we create a HMS instance for our tests, and because of the threadlocals here and in the TxnHandler we leak information between the tests.

Add a CleanupHook here to clear the locals by calling HMSHandlerContext#clear(CleanupHook cleanupHook), not sure it enough for the iceberg case.

public static RawStore getRawStore() {
return threadLocalMS.get();
return HMSHandlerContext.getRawStore().orElse(null);
}

static void cleanupRawStore() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a cleanupRawStore for a good while...
How widely used is this? Could we rename this?

Copy link
Member Author

@dengzhhu653 dengzhhu653 Jan 25, 2022

Choose a reason for hiding this comment

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

It's been used only in two places(HMSHandler&HiveMetaStore) when client disconnects,can we rename it to cleanupHandlerContext with public modifier? Thank you for the suggestions!

public static void clear(CleanupHook cleanupHook) {
HMSHandlerContext ctx = context.get();
context.remove();
if (ctx != null && cleanupHook != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels a bit like overengineering to me.
Why not just do this the cleanupHook stuff outside, and clear the values here?

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, let me take a look. Thanks

LOG.info(addPrefix("Opening raw store with implementation class:" + rawStoreClassName));
return RawStoreProxy.getProxy(newConf, conf, rawStoreClassName, threadLocalId.get());
LOG.info("Opening raw store with implementation class: {}", rawStoreClassName);
return RawStoreProxy.getProxy(newConf, conf, rawStoreClassName, HMSHandlerContext.getThreadId());
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the threadId is not used in the RawStoreProxy

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, i was thinking if we can remove the getThreadId from IHMSHandler, which is declared as InterfaceAudience.Private, the getThreadId is only used for logging now, how about raising another pr for this? I also want to improve the metrics and audit of the HMSHandler #2441.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. Then we will be able to remove the ThreadId threadlocal

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it, I opened https://issues.apache.org/jira/browse/HIVE-25896 for the removal of getThreadId

@dengzhhu653
Copy link
Member Author

Hi @pvary, could you please take another look if have some secs? Thank you!

@pvary
Copy link
Contributor

pvary commented Feb 7, 2022

@dengzhhu653: Sorry, I was out of town last week.
LGTM

@kgyrtkirk, or @nrg4878 would you like to take a look?

Thanks,
Peter

*/
public final class HMSHandlerContext {

private static final ThreadLocal<HMSHandlerContext> context = new ThreadLocal<>();
Copy link
Member

Choose a reason for hiding this comment

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

I think we may create a new instance of the context in initialValue() and remove quite a few conditionals from the getters

Copy link
Member Author

Choose a reason for hiding this comment

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

Make sense, Thank you for the suggestion, @kgyrtkirk!

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@dengzhhu653 dengzhhu653 merged commit 88219d2 into apache:master Feb 10, 2022
DongWei-4 pushed a commit to DongWei-4/hive that referenced this pull request Oct 28, 2022
…pache#2967) (Zhihua Deng, reviewed by Peter Vary and Zoltan Haindrich)
dengzhhu653 added a commit to dengzhhu653/hive that referenced this pull request Dec 15, 2022
…pache#2967) (Zhihua Deng, reviewed by Peter Vary and Zoltan Haindrich)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants