You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/09/28 06:52:54 UTC

[GitHub] [dubbo] AlbumenJ opened a new pull request, #10691: Add dual chain support for state router, prevent update when invoke

AlbumenJ opened a new pull request, #10691:
URL: https://github.com/apache/dubbo/pull/10691

   ## What is the purpose of the change
   
   
   
   ## Brief changelog
   
   
   ## Verifying this change
   
   
   <!-- Follow this checklist to help us incorporate your contribution quickly and easily: -->
   
   ## Checklist
   - [x] Make sure there is a [GitHub_issue](https://github.com/apache/dubbo/issues) 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](https://github.com/apache/dubbo-samples) project.
   - [ ] Add some description to [dubbo-website](https://github.com/apache/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](https://github.com/apache/dubbo/wiki/Software-donation-guide).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] guohao commented on a diff in pull request #10691: Add dual chain support for state router, prevent update when invoke

Posted by GitBox <gi...@apache.org>.
guohao commented on code in PR #10691:
URL: https://github.com/apache/dubbo/pull/10691#discussion_r993201655


##########
dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java:
##########
@@ -103,264 +76,95 @@ public static <T> RouterChain<T> buildChain(Class<T> interfaceClass, URL url) {
 
         RouterSnapshotSwitcher routerSnapshotSwitcher = ScopeModelUtil.getFrameworkModel(moduleModel).getBeanFactory().getBean(RouterSnapshotSwitcher.class);
 
-        return new RouterChain<>(routers, stateRouters, shouldFailFast, routerSnapshotSwitcher);
+        return new SingleRouterChain<>(routers, stateRouters, shouldFailFast, routerSnapshotSwitcher);
     }
 
-    public RouterChain(List<Router> routers, List<StateRouter<T>> stateRouters, boolean shouldFailFast, RouterSnapshotSwitcher routerSnapshotSwitcher) {
-        initWithRouters(routers);
-
-        initWithStateRouters(stateRouters);
-
-        this.shouldFailFast = shouldFailFast;
-        this.routerSnapshotSwitcher = routerSnapshotSwitcher;
-    }
-
-    private void initWithStateRouters(List<StateRouter<T>> stateRouters) {
-        StateRouter<T> stateRouter = TailStateRouter.getInstance();
-        for (int i = stateRouters.size() - 1; i >= 0; i--) {
-            StateRouter<T> nextStateRouter = stateRouters.get(i);
-            nextStateRouter.setNextRouter(stateRouter);
-            stateRouter = nextStateRouter;
+    public RouterChain(SingleRouterChain<T>[] chains) {
+        if (chains.length != 2) {
+            throw new IllegalArgumentException("chains' size should be 2.");
         }
-        this.headStateRouter = stateRouter;
-        this.stateRouters = Collections.unmodifiableList(stateRouters);
+        this.mainChain = chains[0];
+        this.backupChain = chains[1];
+        this.currentChain = this.mainChain;
     }
 
-    /**
-     * the resident routers must being initialized before address notification.
-     * only for ut
-     */
-    public void initWithRouters(List<Router> builtinRouters) {
-        this.builtinRouters = builtinRouters;
-        this.routers = new LinkedList<>(builtinRouters);
+    public List<Invoker<T>> route(URL url, BitList<Invoker<T>> availableInvokers, Invocation invocation) {
+        return currentChain.route(url, availableInvokers, invocation);
     }
 
     /**
-     * If we use route:// protocol in version before 2.7.0, each URL will generate a Router instance, so we should
-     * keep the routers up to date, that is, each time router URLs changes, we should update the routers list, only
-     * keep the builtinRouters which are available all the time and the latest notified routers which are generated
-     * from URLs.
-     *
-     * @param routers routers from 'router://' rules in 2.6.x or before.
+     * Notify router chain of the initial addresses from registry at the first time.
+     * Notify whenever addresses in registry change.
      */
-    public void addRouters(List<Router> routers) {
-        List<Router> newRouters = new LinkedList<>();
-        newRouters.addAll(builtinRouters);
-        newRouters.addAll(routers);
-        CollectionUtils.sort(newRouters);
-        this.routers = newRouters;
-    }
-
-    public List<Router> getRouters() {
-        return routers;
-    }
-
-    public StateRouter<T> getHeadStateRouter() {
-        return headStateRouter;
-    }
-
-    public List<Invoker<T>> route(URL url, BitList<Invoker<T>> availableInvokers, Invocation invocation) {
-        if (RpcContext.getServiceContext().isNeedPrintRouterSnapshot()) {
-            return routeAndPrint(url, availableInvokers, invocation);
-        } else {
-            return simpleRoute(url, availableInvokers, invocation);
-        }
-    }
+    public synchronized void setInvokers(BitList<Invoker<T>> invokers) {
+        // 1. switch
+        currentChain = backupChain;
 
-    public List<Invoker<T>> routeAndPrint(URL url, BitList<Invoker<T>> availableInvokers, Invocation invocation) {
-        RouterSnapshotNode<T> snapshot = buildRouterSnapshot(url, availableInvokers, invocation);
-        logRouterSnapshot(url, invocation, snapshot);
-        return snapshot.getChainOutputInvokers();
-    }
-
-    public List<Invoker<T>> simpleRoute(URL url, BitList<Invoker<T>> availableInvokers, Invocation invocation) {
-        BitList<Invoker<T>> resultInvokers = availableInvokers.clone();
+        // 2. wait
+        waitChain(mainChain);
 
-        // 1. route state router
-        resultInvokers = headStateRouter.route(resultInvokers, url, invocation, false, null);
-        if (resultInvokers.isEmpty() && (shouldFailFast || routers.isEmpty())) {
-            printRouterSnapshot(url, availableInvokers, invocation);
-            return BitList.emptyList();
-        }
+        // 3. notify
+        mainChain.setInvokers(invokers);
 
-        if (routers.isEmpty()) {
-            return resultInvokers;
-        }
-        List<Invoker<T>> commonRouterResult = resultInvokers.cloneToArrayList();
-        // 2. route common router
-        for (Router router : routers) {
-            // Copy resultInvokers to a arrayList. BitList not support
-            RouterResult<Invoker<T>> routeResult = router.route(commonRouterResult, url, invocation, false);
-            commonRouterResult = routeResult.getResult();
-            if (CollectionUtils.isEmpty(commonRouterResult) && shouldFailFast) {
-                printRouterSnapshot(url, availableInvokers, invocation);
-                return BitList.emptyList();
-            }
-
-            // stop continue routing
-            if (!routeResult.isNeedContinueRoute()) {
-                return commonRouterResult;
-            }
-        }
+        // 4. switch back
+        currentChain = mainChain;
 
-        if (commonRouterResult.isEmpty()) {
-            printRouterSnapshot(url, availableInvokers, invocation);
-            return BitList.emptyList();
-        }
+        // 5. wait
+        waitChain(backupChain);
 
-        return commonRouterResult;
+        // 6. notify
+        backupChain.setInvokers(invokers);
     }
 
-    /**
-     * store each router's input and output, log out if empty
-     */
-    private void printRouterSnapshot(URL url, BitList<Invoker<T>> availableInvokers, Invocation invocation) {
-        if (logger.isWarnEnabled()) {
-            logRouterSnapshot(url, invocation, buildRouterSnapshot(url, availableInvokers, invocation));
+    private void waitChain(SingleRouterChain<T> oldChain) {
+        try {
+            Thread.sleep(1);

Review Comment:
   No need to wait if concurrency == 0



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] codecov-commenter commented on pull request #10691: Add dual chain support for state router, prevent update when invoke

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #10691:
URL: https://github.com/apache/dubbo/pull/10691#issuecomment-1272441303

   # [Codecov](https://codecov.io/gh/apache/dubbo/pull/10691?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#10691](https://codecov.io/gh/apache/dubbo/pull/10691?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (cb2d8ec) into [3.1](https://codecov.io/gh/apache/dubbo/commit/e6748c7cb76fddc01c95433d866999350e38a4c4?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (e6748c7) will **decrease** coverage by `0.35%`.
   > The diff coverage is `61.82%`.
   
   ```diff
   @@             Coverage Diff              @@
   ##                3.1   #10691      +/-   ##
   ============================================
   - Coverage     65.22%   64.87%   -0.36%     
   + Complexity      494      492       -2     
   ============================================
     Files          1336     1337       +1     
     Lines         56922    56973      +51     
     Branches       8435     8417      -18     
   ============================================
   - Hits          37129    36960     -169     
   - Misses        15827    16024     +197     
   - Partials       3966     3989      +23     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/dubbo/pull/10691?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...apache/dubbo/rpc/cluster/router/state/BitList.java](https://codecov.io/gh/apache/dubbo/pull/10691/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tY2x1c3Rlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZHViYm8vcnBjL2NsdXN0ZXIvcm91dGVyL3N0YXRlL0JpdExpc3QuamF2YQ==) | `78.38% <0.00%> (-0.68%)` | :arrow_down: |
   | [...rg/apache/dubbo/rpc/cluster/SingleRouterChain.java](https://codecov.io/gh/apache/dubbo/pull/10691/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tY2x1c3Rlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZHViYm8vcnBjL2NsdXN0ZXIvU2luZ2xlUm91dGVyQ2hhaW4uamF2YQ==) | `58.62% <58.62%> (ø)` | |
   | [...java/org/apache/dubbo/rpc/cluster/RouterChain.java](https://codecov.io/gh/apache/dubbo/pull/10691/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tY2x1c3Rlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZHViYm8vcnBjL2NsdXN0ZXIvUm91dGVyQ2hhaW4uamF2YQ==) | `84.21% <75.00%> (+22.42%)` | :arrow_up: |
   | [.../rpc/cluster/router/state/AbstractStateRouter.java](https://codecov.io/gh/apache/dubbo/pull/10691/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tY2x1c3Rlci9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZHViYm8vcnBjL2NsdXN0ZXIvcm91dGVyL3N0YXRlL0Fic3RyYWN0U3RhdGVSb3V0ZXIuamF2YQ==) | `83.01% <100.00%> (+2.24%)` | :arrow_up: |
   | [.../serialize/hessian2/Hessian2SerializerFactory.java](https://codecov.io/gh/apache/dubbo/pull/10691/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tc2VyaWFsaXphdGlvbi9kdWJiby1zZXJpYWxpemF0aW9uLWhlc3NpYW4yL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9jb21tb24vc2VyaWFsaXplL2hlc3NpYW4yL0hlc3NpYW4yU2VyaWFsaXplckZhY3RvcnkuamF2YQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...sian2/dubbo/DefaultHessian2FactoryInitializer.java](https://codecov.io/gh/apache/dubbo/pull/10691/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tc2VyaWFsaXphdGlvbi9kdWJiby1zZXJpYWxpemF0aW9uLWhlc3NpYW4yL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9jb21tb24vc2VyaWFsaXplL2hlc3NpYW4yL2R1YmJvL0RlZmF1bHRIZXNzaWFuMkZhY3RvcnlJbml0aWFsaXplci5qYXZh) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
   | [...ize/hessian2/dubbo/Hessian2FactoryInitializer.java](https://codecov.io/gh/apache/dubbo/pull/10691/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tc2VyaWFsaXphdGlvbi9kdWJiby1zZXJpYWxpemF0aW9uLWhlc3NpYW4yL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9jb21tb24vc2VyaWFsaXplL2hlc3NpYW4yL2R1YmJvL0hlc3NpYW4yRmFjdG9yeUluaXRpYWxpemVyLmphdmE=) | `0.00% <0.00%> (-60.00%)` | :arrow_down: |
   | [...common/serialize/hessian2/Hessian2ObjectInput.java](https://codecov.io/gh/apache/dubbo/pull/10691/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tc2VyaWFsaXphdGlvbi9kdWJiby1zZXJpYWxpemF0aW9uLWhlc3NpYW4yL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9jb21tb24vc2VyaWFsaXplL2hlc3NpYW4yL0hlc3NpYW4yT2JqZWN0SW5wdXQuamF2YQ==) | `0.00% <0.00%> (-51.86%)` | :arrow_down: |
   | [...ian2/dubbo/AbstractHessian2FactoryInitializer.java](https://codecov.io/gh/apache/dubbo/pull/10691/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tc2VyaWFsaXphdGlvbi9kdWJiby1zZXJpYWxpemF0aW9uLWhlc3NpYW4yL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9jb21tb24vc2VyaWFsaXplL2hlc3NpYW4yL2R1YmJvL0Fic3RyYWN0SGVzc2lhbjJGYWN0b3J5SW5pdGlhbGl6ZXIuamF2YQ==) | `0.00% <0.00%> (-50.00%)` | :arrow_down: |
   | [...ommon/serialize/hessian2/Hessian2ObjectOutput.java](https://codecov.io/gh/apache/dubbo/pull/10691/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZHViYm8tc2VyaWFsaXphdGlvbi9kdWJiby1zZXJpYWxpemF0aW9uLWhlc3NpYW4yL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9jb21tb24vc2VyaWFsaXplL2hlc3NpYW4yL0hlc3NpYW4yT2JqZWN0T3V0cHV0LmphdmE=) | `0.00% <0.00%> (-43.75%)` | :arrow_down: |
   | ... and [71 more](https://codecov.io/gh/apache/dubbo/pull/10691/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] AlbumenJ merged pull request #10691: Add dual chain support for state router, prevent update when invoke

Posted by GitBox <gi...@apache.org>.
AlbumenJ merged PR #10691:
URL: https://github.com/apache/dubbo/pull/10691


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org