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 2021/11/24 02:35:05 UTC
[GitHub] [dubbo-go-pixiu] mark4z commented on a change in pull request #262: add trie for route
mark4z commented on a change in pull request #262:
URL: https://github.com/apache/dubbo-go-pixiu/pull/262#discussion_r720780340
##########
File path: pkg/common/router/router.go
##########
@@ -54,23 +55,50 @@ func (rm *RouterCoordinator) Route(hc *http.HttpContext) (*model.RouteAction, er
return rm.activeConfig.Route(hc.Request)
}
+func getTrieKey(method string, path string, isPrefix bool) string {
+ if isPrefix {
+ return method + constant.PathSlash + path + constant.PathSlash + "**"
+ }
+ return method + constant.PathSlash + path
+}
+
// OnAddRouter add router
func (rm *RouterCoordinator) OnAddRouter(r *model.Router) {
+ //锁粒度 下期优化到 字典树node 级别
rm.rw.Lock()
defer rm.rw.Unlock()
+ if r.Match.Methods == nil {
+ r.Match.Methods = []string{constant.Get, constant.Put, constant.Delete, constant.Post}
+ }
+ isPrefix := r.Match.Prefix != ""
+ for _, method := range r.Match.Methods {
+ var key string
+ if isPrefix {
+ key = getTrieKey(method, r.Match.Prefix, isPrefix)
+ } else {
+ key = getTrieKey(method, r.Match.Path, isPrefix)
+ }
+ rm.activeConfig.RouteTrie.Put(key, r.Route)
+ }
Review comment:
resolve it
--
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