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(triple): Dubbo triple&rest protocol convergense #13607

Merged
merged 19 commits into from Feb 1, 2024

Conversation

oxsean
Copy link
Collaborator

@oxsean oxsean commented Jan 3, 2024

What is the purpose of the change

See #13427,only for code review.

Brief changelog

  1. Refine Triple Transport layer code for the REST protocol support.
  2. Added initial support for the REST protocol.
    image

Verifying this change

Checklist

  • Make sure there is a GitHub_issue field for the change (usually before you start working on it). Trivial changes like typos do not require a GitHub issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Check if is necessary to patch to Dubbo 3 if you are work on Dubbo 2.7
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Add some description to dubbo-website project if you are requesting to add a feature.
  • GitHub Actions works fine on your own branch.
  • If this contribution is large, please follow the Software Donation Guide.

@AlbumenJ
Copy link
Member

AlbumenJ commented Jan 4, 2024

image
image

Please these compiling issues

@oxsean oxsean force-pushed the feature-13427-triple-convergence-rest branch from 566f6db to 00679b1 Compare January 4, 2024 13:41
@oxsean
Copy link
Collaborator Author

oxsean commented Jan 4, 2024

image image

Please these compiling issues

Done, but just for design review at this time.

@oxsean oxsean force-pushed the feature-13427-triple-convergence-rest branch 2 times, most recently from 4494714 to 56c928a Compare January 4, 2024 14:48
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Copy link
Member

Choose a reason for hiding this comment

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

Add test scope

@@ -1,63 +0,0 @@
/*
Copy link
Member

Choose a reason for hiding this comment

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

Why remove these classes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When analyzing the code, it was found that org.apache.dubbo.rpc.protocol.tri.transport.TripleHttp2FrameServerHandler is no longer in use, so I cleaned up the related classes to facilitate code reference analysis. The test class org.apache.dubbo.reactive.CreateObserverAdapter referred to the unnecessary ServerCallToObserverAdapter.
When it's time for the final merge, I will split the cleanup work into a separate PR.

@oxsean oxsean force-pushed the feature-13427-triple-convergence-rest branch from 56c928a to 4a5d381 Compare January 5, 2024 01:17
}

@Override
public boolean IsHttp2() {
Copy link
Member

Choose a reason for hiding this comment

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

lower first letter

Copy link
Collaborator Author

@oxsean oxsean Jan 5, 2024

Choose a reason for hiding this comment

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

😂, confusing to write both java and csharp, I'll check them.

import org.apache.dubbo.remoting.http12.HttpMetadata;
import org.apache.dubbo.remoting.http12.HttpResponse;

@Activate
Copy link
Member

Choose a reason for hiding this comment

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

Would scope bean be better?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would scope bean be better?

Consider adapting to the servlet model when the user includes the servlet API, enabling support for scenarios requiring the servlet system.

@oxsean oxsean force-pushed the feature-13427-triple-convergence-rest branch 11 times, most recently from fdf421d to 60848cf Compare January 6, 2024 14:26
* When the data accessed for the first time, add it to history list. If the size of history list reaches max capacity, eliminate the earliest data (first in first out).
* When the data already exists in the history list, and be accessed for the second time, then it will be put into cache.
*
* </p>
* TODO, consider replacing with ConcurrentHashMap to improve performance under concurrency
*/
public class LRU2Cache<K, V> extends LinkedHashMap<K, V> {
Copy link
Member

Choose a reason for hiding this comment

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

LRU2Cache 和 LRUCache 历史上存在过并发或者是内存泄漏问题,如果需要使用的话这部分需要验证下

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok,只是加了一个computeIfAbsent,这个之前没重写缺了锁

Copy link
Member

Choose a reason for hiding this comment

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

这个变动如果跟这个PR没有关联,可以单独提个PR。

import org.apache.dubbo.remoting.http12.HttpChannel;
import org.apache.dubbo.remoting.http12.RequestMetadata;

@SPI(value = CommonConstants.TRIPLE, scope = ExtensionScope.FRAMEWORK)
Copy link
Member

Choose a reason for hiding this comment

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

对于只有一个实现的 SPI,直接使用 ScopeBean 的模式去处理

import org.apache.dubbo.remoting.http12.HttpResponse;
import org.apache.dubbo.remoting.http12.message.HttpMessageAdapterFactory;

@Activate(order = -100, onClass = "javax.servlet.http.HttpServletRequest")
Copy link
Member

Choose a reason for hiding this comment

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

  1. HttpServletRequest 目前是不是还没有实现
  2. 这里使用 Activate 机制的模式有点奇怪,这里应该是需要基于数据源是哪种类型动态切换的吧,最好是用 Adaptive 的模式基于参数动态路由?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

这个主要是希望能够支持servlet生态,在应用依赖里面有servlet包的时候,直接适配成HttpServletRequest,这样在扩展filter里面就可以支持很多spring web和servlet的能力

});
}

private void register(RequestMapping mapping, HandlerMeta handler) {
Copy link
Member

Choose a reason for hiding this comment

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

Rename to register0 would be better


import java.util.function.Supplier;

public interface FluentLogger {
Copy link
Member

Choose a reason for hiding this comment

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

This change should not be in this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The current logger parameters are too lengthy and prone to misuse; in almost every instance, two empty strings are being passed. using fluent style api is more user-friendly. However, there are only two classes involved. While it's possible to split them, it doesn't seem particularly necessary.

} else {
return values.iterator().next();
}
}

public static <T> T first(List<T> values) {
Copy link
Member

Choose a reason for hiding this comment

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

This can be replaced by first(Collection<T> values)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It will eliminate one class type check and as an overloaded method, it has no significant usage cost.

Comment on lines 431 to 474
public static <T> Set<T> newHashSet(int expectedSize) {
return new HashSet<>(capacity(expectedSize));
}

public static <T> Set<T> newLinkedHashSet(int expectedSize) {
return new LinkedHashSet<>(capacity(expectedSize));
}

public static <T, K> Map<K, T> newHashMap(int expectedSize) {
return new HashMap<>(capacity(expectedSize));
}

public static <T, K> Map<K, T> newLinkedHashMap(int expectedSize) {
return new LinkedHashMap<>(capacity(expectedSize));
}

public static int capacity(int expectedSize) {
if (expectedSize < 3) {
if (expectedSize < 0) {
throw new IllegalArgumentException("expectedSize cannot be negative but was: " + expectedSize);
}
return expectedSize + 1;
}
if (expectedSize < 1 << (Integer.SIZE - 2)) {
return (int) (expectedSize / 0.75F + 1.0F);
}
return Integer.MAX_VALUE;
}
Copy link
Member

Choose a reason for hiding this comment

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

What are the benefits of this part of the code? If not, I think we can focus on the important content of the PR itself first, and this part can be deleted first.

Copy link
Collaborator Author

@oxsean oxsean Jan 18, 2024

Choose a reason for hiding this comment

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

* When the data accessed for the first time, add it to history list. If the size of history list reaches max capacity, eliminate the earliest data (first in first out).
* When the data already exists in the history list, and be accessed for the second time, then it will be put into cache.
*
* </p>
* TODO, consider replacing with ConcurrentHashMap to improve performance under concurrency
*/
public class LRU2Cache<K, V> extends LinkedHashMap<K, V> {
Copy link
Member

Choose a reason for hiding this comment

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

这个变动如果跟这个PR没有关联,可以单独提个PR。

@@ -73,4 +73,29 @@ private static synchronized void startTicker() {
isTickerAlive = true;
}
}

public static Long parseTimeoutToMills(String timeoutVal) {
Copy link
Member

Choose a reason for hiding this comment

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

This section is recommended to be put back into the corresponding module first, it does not seem to be general enough.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

LRU2Cache has been updated with overwrite 'computeIfAbsent' method. This wasn't overridden before, and using it could lead to concurrency issues due to the lack of locking.

public class DefaultHttpResult<T> implements HttpResult<T> {

private int status;
private Map<String, List<String>> headers;
Copy link
Member

Choose a reason for hiding this comment

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

Why is the value of the header an array?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For example, with something like 'set-cookie', there can be multiple instances, so it should be a list.


public class DefaultHttpResult<T> implements HttpResult<T> {

private int status;
Copy link
Member

Choose a reason for hiding this comment

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

statusCode?

@oxsean oxsean force-pushed the feature-13427-triple-convergence-rest branch 4 times, most recently from 941ff49 to 67ce0fa Compare January 19, 2024 05:39
@oxsean oxsean force-pushed the feature-13427-triple-convergence-rest branch from 0ec19b1 to e453da0 Compare January 22, 2024 14:47
@oxsean oxsean force-pushed the feature-13427-triple-convergence-rest branch from e453da0 to a0263d9 Compare January 22, 2024 15:55
@codecov-commenter
Copy link

codecov-commenter commented Jan 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (46af145) 41.41% compared to head (a56c34d) 38.51%.
Report is 44 commits behind head on 3.3.

Additional details and impacted files
@@            Coverage Diff             @@
##              3.3   #13607      +/-   ##
==========================================
- Coverage   41.41%   38.51%   -2.90%     
==========================================
  Files        1750     1895     +145     
  Lines       73370    79258    +5888     
  Branches    10371    11532    +1161     
==========================================
+ Hits        30388    30529     +141     
- Misses      38691    44435    +5744     
- Partials     4291     4294       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@oxsean oxsean force-pushed the feature-13427-triple-convergence-rest branch from d31286d to 3c7432d Compare January 26, 2024 06:45
@oxsean oxsean force-pushed the feature-13427-triple-convergence-rest branch from 7a19a9d to 3816b3c Compare January 26, 2024 12:11
@oxsean oxsean force-pushed the feature-13427-triple-convergence-rest branch 4 times, most recently from 0161ebc to efe149f Compare January 29, 2024 16:07
@oxsean oxsean force-pushed the feature-13427-triple-convergence-rest branch from efe149f to f66fed1 Compare January 29, 2024 16:08
@oxsean oxsean force-pushed the feature-13427-triple-convergence-rest branch from 918cba1 to a56c34d Compare January 31, 2024 09:21
Copy link

sonarcloud bot commented Jan 31, 2024

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

317 New issues
0 Security Hotspots
0.0% Coverage on New Code
1.5% Duplication on New Code

See analysis details on SonarCloud

@AlbumenJ AlbumenJ merged commit 2dde7ac into apache:3.3 Feb 1, 2024
19 checks passed
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.

None yet

4 participants