Skip to content

[#4236] feat(core): Supports the post-hook for the managers or dispatcher#4239

Merged
xunliu merged 3 commits intoapache:mainfrom
qqqttt123:ISSUE-4236
Jul 31, 2024
Merged

[#4236] feat(core): Supports the post-hook for the managers or dispatcher#4239
xunliu merged 3 commits intoapache:mainfrom
qqqttt123:ISSUE-4236

Conversation

@roryqi
Copy link
Contributor

@roryqi roryqi commented Jul 23, 2024

What changes were proposed in this pull request?

Supports the post-hook for the managers or dispatcher.
For example, after we create a securable object, we should set an owner for it. We can add a specific post hook to support it.
This pull request uses Java dynamic proxy mechanism to support this feature. We only support post-hook now, we can support pre-hook in the future.

Why are the changes needed?

Fix: #4236

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Add a new ut.

@roryqi roryqi force-pushed the ISSUE-4236 branch 5 times, most recently from d36f6d1 to feef232 Compare July 23, 2024 08:42
@roryqi
Copy link
Contributor Author

roryqi commented Jul 23, 2024

@jerryshao Could you take a look?

@roryqi
Copy link
Contributor Author

roryqi commented Jul 29, 2024

@xunliu Could you help me review this pull request?


// Provides a universal entrance to install lifecycle hooks. This method
// focuses the logic of installing hooks.
// We should reuse the ability of *NormalizeDispatcher to avoid solving
Copy link
Member

Choose a reason for hiding this comment

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

Which mean is *NormalizeDispatcher, Typo?
*NormalizeDispatcher*?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

NO. It represents TableNormalizeDispatcher,SchemaNormalizeDispatcher, etc.

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 better change to We should reuse the ability of (Metalake|Schema|Table|Fileset|...)NormalizeDispatcher to avoid solving

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

namespace);
}

public static <T> void prepareAuthorizationHooks(T manager, LifecycleHooks hooks) {
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 better to add some comments for this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}

public static <T> void prepareAuthorizationHooks(T manager, LifecycleHooks hooks) {
if (manager instanceof SupportsMetalakes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This method only hooks the event of createXXXX?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object result = method.invoke(dispatcher, args);
List<BiConsumer> postHooks = hooks.getPostHooks(method.getName());
for (BiConsumer hook : postHooks) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What if anyone fails halfway through?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

import java.util.List;
import java.util.function.BiConsumer;

class LifecycleHookProxy<T> implements InvocationHandler {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it's better to name the class DispatcherHookProxy

Copy link
Contributor Author

@roryqi roryqi Jul 31, 2024

Choose a reason for hiding this comment

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

Em.. all is ok for me. But many system use life cycle hook when they use similar mechinansim like K8S, Android.

Copy link
Member

@xunliu xunliu Jul 31, 2024

Choose a reason for hiding this comment

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

I also feeling DispatcherHookProxy as a better name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

Copy link
Member

@xunliu xunliu left a comment

Choose a reason for hiding this comment

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

LGTM

@xunliu xunliu merged commit 851c463 into apache:main Jul 31, 2024
@roryqi roryqi deleted the ISSUE-4236 branch July 31, 2024 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement] Add PostHook menchinism for managers

3 participants