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

feat: split rpcContext #10798

Merged
merged 23 commits into from
Nov 10, 2022
Merged

Conversation

aamingaa
Copy link
Contributor

This is the pure version

@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2022

Codecov Report

Merging #10798 (b4dad1d) into 3.2 (51fc01c) will decrease coverage by 0.05%.
The diff coverage is 56.34%.

@@             Coverage Diff              @@
##                3.2   #10798      +/-   ##
============================================
- Coverage     64.82%   64.76%   -0.06%     
+ Complexity      392      391       -1     
============================================
  Files          1355     1356       +1     
  Lines         57595    57699     +104     
  Branches       8491     8506      +15     
============================================
+ Hits          37336    37371      +35     
- Misses        16272    16326      +54     
- Partials       3987     4002      +15     
Impacted Files Coverage Δ
...ubbo/metadata/definition/model/TypeDefinition.java 72.09% <ø> (ø)
...rc/main/java/com/alibaba/dubbo/rpc/RpcContext.java 6.72% <0.00%> (-0.36%) ⬇️
...gistry/client/ReflectionBasedServiceDiscovery.java 0.00% <0.00%> (ø)
...g/apache/dubbo/rpc/RpcServerContextAttachment.java 55.71% <55.71%> (ø)
...ava/org/apache/dubbo/rpc/filter/ContextFilter.java 82.08% <57.14%> (-7.20%) ⬇️
...src/main/java/org/apache/dubbo/rpc/RpcContext.java 47.14% <70.83%> (+0.75%) ⬆️
.../cluster/filter/support/ConsumerContextFilter.java 67.39% <75.00%> (+0.72%) ⬆️
...egistry/kubernetes/KubernetesServiceDiscovery.java 77.83% <100.00%> (-2.36%) ⬇️
.../protocol/tri/call/AbstractServerCallListener.java 75.00% <100.00%> (ø)
...e/dubbo/rpc/protocol/tri/transport/WriteQueue.java 72.72% <0.00%> (-12.13%) ⬇️
... and 19 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@AlbumenJ AlbumenJ left a comment

Choose a reason for hiding this comment

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

What is the difference between #10793

Comment on lines 60 to 70
@Override
public RpcContextAttachment setObjectAttachment(String key, Object value) {
if (value == null) {
attachments.remove(key);
} else {
RpcContext.getServerResponseContext().setAttachment(key, value);
attachments.put(key, value);
}
return this;
}
};
Copy link
Member

Choose a reason for hiding this comment

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

override all methods in RpcContextAttachment, and proxy to serverResponse / clientResponse


@Override
public String getAttachment(String key) {
return RpcContext.getClientResponseContext().getAttachment(key);
Copy link
Member

Choose a reason for hiding this comment

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

Get from serverResponse first and then fall back to clientResponse


@Override
public Object getObjectAttachment(String key) {
return RpcContext.getClientResponseContext().getObjectAttachment(key);
Copy link
Member

Choose a reason for hiding this comment

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

Get from serverResponse first and then fall back to clientResponse


@Override
public RpcContextAttachment removeAttachment(String key) {
return RpcContext.getServerResponseContext().removeAttachment(key);
Copy link
Member

Choose a reason for hiding this comment

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

Remove in both serverResponse and clientResponse


@Override
public Map<String, String> getAttachments() {
return RpcContext.getServerResponseContext().getAttachments();
Copy link
Member

Choose a reason for hiding this comment

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

Create a new map, add all attachments from clientResponse and serverResponse. serverResponse should override clientResponse.


@Override
public Map<String, Object> getObjectAttachments() {
return RpcContext.getServerResponseContext().getObjectAttachments();
Copy link
Member

Choose a reason for hiding this comment

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

Create a new map, add all attachments from clientResponse and serverResponse. serverResponse should override clientResponse.


@Override
public Object get(String key) {
return RpcContext.getServerResponseContext().get(key);
Copy link
Member

Choose a reason for hiding this comment

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

Deprecated method. Proxy it to getAttachment


@Override
public RpcContextAttachment copyOf(boolean needCopy) {
return RpcContext.getServerResponseContext().copyOf(needCopy);
Copy link
Member

Choose a reason for hiding this comment

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

Internal method, should not be called. Throw exception directly. BTW, check the usage.


@Override
protected boolean isValid() {
return RpcContext.getServerResponseContext().isValid();
Copy link
Member

Choose a reason for hiding this comment

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

Internal method, should not be called. Throw exception directly. BTW, check the usage.

Comment on lines 67 to 69
public ContextFilter() {
ApplicationModel applicationModel = ApplicationModel.defaultModel();
ExtensionLoader<PenetrateAttachmentSelector> selectorExtensionLoader = applicationModel.getExtensionLoader(PenetrateAttachmentSelector.class);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public ContextFilter() {
ApplicationModel applicationModel = ApplicationModel.defaultModel();
ExtensionLoader<PenetrateAttachmentSelector> selectorExtensionLoader = applicationModel.getExtensionLoader(PenetrateAttachmentSelector.class);
public ContextFilter(ApplicationModel applicationModel) {
ExtensionLoader<PenetrateAttachmentSelector> selectorExtensionLoader = applicationModel.getExtensionLoader(PenetrateAttachmentSelector.class);

Comment on lines 35 to 38
@Override
public Map<String, Object> selectReverse(Invocation invocation, RpcContextAttachment clientResponseContext, RpcContextAttachment serverResponseContext) {
return null;
}
Copy link
Member

Choose a reason for hiding this comment

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

Add some test cases for this

Copy link
Member

@AlbumenJ AlbumenJ left a comment

Choose a reason for hiding this comment

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

Comment on lines 164 to 165
Map<String, String> attachmentMap = this;
attachmentMap.putAll(getAllAttachmentMap());
Copy link
Member

Choose a reason for hiding this comment

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

what is the purpose of these two lines

Comment on lines 53 to 54
RpcContext.getServerResponseContext().setRemoteAddress(remoteAddress);
RpcContext.getServerContext().setRemoteAddress(remoteAddress);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
RpcContext.getServerResponseContext().setRemoteAddress(remoteAddress);
RpcContext.getServerContext().setRemoteAddress(remoteAddress);
RpcContext.getServiceContext().setRemoteAddress(remoteAddress);

Comment on lines 58 to 59
RpcContext.getServerResponseContext().setRemoteApplicationName(remoteApp);
RpcContext.getServerContext().setRemoteApplicationName(remoteApp);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
RpcContext.getServerResponseContext().setRemoteApplicationName(remoteApp);
RpcContext.getServerContext().setRemoteApplicationName(remoteApp);
RpcContext.getServiceContext().setRemoteApplicationName(remoteApp);

RpcContext.getServerContext().setRemoteApplicationName(remoteApp);
}
};
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
};
}

Copy link
Member

@AlbumenJ AlbumenJ left a comment

Choose a reason for hiding this comment

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

LGTM

@AlbumenJ AlbumenJ merged commit ee9d01a into apache:3.2 Nov 10, 2022
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.

3 participants