@@ -133,7 +133,7 @@ func (a *Agent) RegisterCommandHandler(f CommandHandler) {
133
133
a .commandHandlers = append (a .commandHandlers , f )
134
134
}
135
135
136
- func (a * Agent ) GetDynamicRegistryInfo () * registrySnapInfoStorage {
136
+ func (a * Agent ) GetDynamicRegistryInfo () * RegistrySnapInfoStorage {
137
137
return a .configurer .getRegistryInfo ()
138
138
}
139
139
@@ -150,7 +150,7 @@ func (a *Agent) RuntimeDir() string {
150
150
return a .runtimedir
151
151
}
152
152
153
- // get Agent server
153
+ // GetAgentServer get Agent server
154
154
func (a * Agent ) GetAgentServer () motan.Server {
155
155
return a .agentServer
156
156
}
@@ -300,7 +300,7 @@ func (a *Agent) initStatus() {
300
300
301
301
func (a * Agent ) saveStatus () {
302
302
statSnapFile := a .runtimedir + string (filepath .Separator ) + defaultStatusSnap
303
- err := ioutil .WriteFile (statSnapFile , []byte (strconv .Itoa (int ( http .StatusOK ) )), 0644 )
303
+ err := ioutil .WriteFile (statSnapFile , []byte (strconv .Itoa (http .StatusOK )), 0644 )
304
304
if err != nil {
305
305
vlog .Errorln ("Save status error: " + err .Error ())
306
306
return
@@ -351,6 +351,14 @@ func (a *Agent) initParam() {
351
351
initLog (logDir , section )
352
352
registerSwitchers (a .Context )
353
353
354
+ processPoolSize := 0
355
+ if section != nil && section ["processPoolSize" ] != nil {
356
+ processPoolSize = section ["processPoolSize" ].(int )
357
+ }
358
+ if processPoolSize > 0 {
359
+ mserver .SetProcessPoolSize (processPoolSize )
360
+ }
361
+
354
362
port := * motan .Port
355
363
if port == 0 && section != nil && section ["port" ] != nil {
356
364
port = section ["port" ].(int )
@@ -474,7 +482,7 @@ func (a *Agent) reloadClusters(ctx *motan.Context) {
474
482
serviceItemKeep := make (map [string ]bool )
475
483
clusterMap := make (map [interface {}]interface {})
476
484
serviceMap := make (map [interface {}]interface {})
477
- var allRefersURLs = []* motan.URL {}
485
+ var allRefersURLs []* motan.URL
478
486
if a .configurer != nil {
479
487
//keep all dynamic refers
480
488
for _ , url := range a .configurer .subscribeNodes {
@@ -490,7 +498,7 @@ func (a *Agent) reloadClusters(ctx *motan.Context) {
490
498
}
491
499
492
500
service := url .Path
493
- mapKey := getClusterKey (url .Group , url .GetStringParamsWithDefault (motan .VersionKey , "0.1" ), url .Protocol , url .Path )
501
+ mapKey := getClusterKey (url .Group , url .GetStringParamsWithDefault (motan .VersionKey , motan . DefaultReferVersion ), url .Protocol , url .Path )
494
502
495
503
// find exists old serviceMap
496
504
var serviceMapValue serviceMapItem
@@ -589,7 +597,7 @@ func (a *Agent) initCluster(url *motan.URL) {
589
597
}
590
598
a .serviceMap .UnsafeStore (url .Path , serviceMapItemArr )
591
599
})
592
- mapKey := getClusterKey (url .Group , url .GetStringParamsWithDefault (motan .VersionKey , "0.1" ), url .Protocol , url .Path )
600
+ mapKey := getClusterKey (url .Group , url .GetStringParamsWithDefault (motan .VersionKey , motan . DefaultReferVersion ), url .Protocol , url .Path )
593
601
a .clsLock .Lock () // Mutually exclusive with the reloadClusters method
594
602
defer a .clsLock .Unlock ()
595
603
a .clusterMap .Store (mapKey , c )
@@ -748,7 +756,9 @@ func (a *agentMessageHandler) httpCall(request motan.Request, ck string, httpClu
748
756
if err != nil {
749
757
return getDefaultResponse (request .GetRequestID (), "do http request failed : " + err .Error ())
750
758
}
751
- res = & motan.MotanResponse {RequestID : request .GetRequestID ()}
759
+ httpMotanResp := mhttp .AcquireHttpMotanResponse ()
760
+ httpMotanResp .RequestID = request .GetRequestID ()
761
+ res = httpMotanResp
752
762
mhttp .FasthttpResponseToMotanResponse (res , httpResponse )
753
763
return res
754
764
}
@@ -794,61 +804,38 @@ func (a *agentMessageHandler) Call(request motan.Request) (res motan.Response) {
794
804
}
795
805
return res
796
806
}
797
- func (a * agentMessageHandler ) matchRule (typ , cond , key string , data []serviceMapItem , f func (u * motan.URL ) string ) (foundClusters []serviceMapItem , err error ) {
798
- if cond == "" {
799
- err = fmt .Errorf ("empty %s is not supported" , typ )
807
+
808
+ func (a * agentMessageHandler ) findCluster (request motan.Request ) (c * cluster.MotanCluster , key string , err error ) {
809
+ service := request .GetServiceName ()
810
+ if service == "" {
811
+ err = fmt .Errorf ("empty service is not supported. service: %s" , service )
800
812
return
801
813
}
802
- for _ , item := range data {
803
- if f ( item . url ) == cond {
804
- foundClusters = append ( foundClusters , item )
805
- }
814
+ serviceItemArrI , exists := a . agent . serviceMap . Load ( service )
815
+ if ! exists {
816
+ err = fmt . Errorf ( "cluster not found. service: %s" , service )
817
+ return
806
818
}
807
- if len (foundClusters ) == 0 {
808
- err = fmt .Errorf ("cluster not found. cluster:%s" , key )
819
+ clusters := serviceItemArrI .([]serviceMapItem )
820
+ if len (clusters ) == 1 {
821
+ //TODO: add strict mode to avoid incorrect group call
822
+ c = clusters [0 ].cluster
809
823
return
810
824
}
811
- return
812
- }
813
- func (a * agentMessageHandler ) findCluster (request motan.Request ) (c * cluster.MotanCluster , key string , err error ) {
814
- service := request .GetServiceName ()
815
825
group := request .GetAttachment (mpro .MGroup )
816
- version := request .GetAttachment (mpro .MVersion )
817
- protocol := request .GetAttachment (mpro .MProxyProtocol )
818
- reqInfo := fmt .Sprintf ("request information: {service: %s, group: %s, protocol: %s, version: %s}" ,
819
- service , group , protocol , version )
820
- serviceItemArrI , exists := a .agent .serviceMap .Load (service )
821
- if ! exists {
822
- err = fmt .Errorf ("cluster not found. cluster:%s, %s" , service , reqInfo )
826
+ if group == "" {
827
+ err = fmt .Errorf ("multiple clusters are matched with service: %s, but the group is empty" , service )
823
828
return
824
829
}
825
- search := []struct {
826
- tip string
827
- cond string
828
- condFn func (u * motan.URL ) string
829
- }{
830
- {"service" , service , func (u * motan.URL ) string { return u .Path }},
831
- {"group" , group , func (u * motan.URL ) string { return u .Group }},
832
- {"protocol" , protocol , func (u * motan.URL ) string { return u .Protocol }},
833
- {"version" , version , func (u * motan.URL ) string { return u .GetParam (motan .VersionKey , "" ) }},
834
- }
835
- foundClusters := serviceItemArrI .([]serviceMapItem )
836
- for i , rule := range search {
837
- if i == 0 {
838
- key = rule .cond
839
- } else {
840
- key += "_" + rule .cond
841
- }
842
- foundClusters , err = a .matchRule (rule .tip , rule .cond , key , foundClusters , rule .condFn )
843
- if err != nil {
844
- return
845
- }
846
- if len (foundClusters ) == 1 {
847
- c = foundClusters [0 ].cluster
830
+ version := request .GetAttachment (mpro .MVersion )
831
+ protocol := request .GetAttachment (mpro .MProxyProtocol )
832
+ for _ , j := range clusters {
833
+ if j .url .IsMatch (service , group , protocol , version ) {
834
+ c = j .cluster
848
835
return
849
836
}
850
837
}
851
- err = fmt .Errorf ("less condition to select cluster, maybe this service belongs to multiple group, protocol, version; cluster : %s, %s " , key , reqInfo )
838
+ err = fmt .Errorf ("no cluster matches the request; info: { service: %s, group: %s, protocol : %s, version: %s} " , service , group , protocol , version )
852
839
return
853
840
}
854
841
@@ -1145,7 +1132,7 @@ func (a *Agent) startMServer() {
1145
1132
continue
1146
1133
}
1147
1134
a .mport = port
1148
- managementListener = motan.TCPKeepAliveListener {listener .(* net.TCPListener )}
1135
+ managementListener = motan.TCPKeepAliveListener {TCPListener : listener .(* net.TCPListener )}
1149
1136
break
1150
1137
}
1151
1138
if managementListener == nil {
@@ -1158,7 +1145,7 @@ func (a *Agent) startMServer() {
1158
1145
vlog .Infof ("listen manage port %d failed:%s" , a .mport , err .Error ())
1159
1146
return
1160
1147
}
1161
- managementListener = motan.TCPKeepAliveListener {listener .(* net.TCPListener )}
1148
+ managementListener = motan.TCPKeepAliveListener {TCPListener : listener .(* net.TCPListener )}
1162
1149
}
1163
1150
1164
1151
vlog .Infof ("start listen manage for address: %s" , managementListener .Addr ().String ())
0 commit comments