Skip to content

Commit

Permalink
Profile base (#363)
Browse files Browse the repository at this point in the history
* code beautify
  • Loading branch information
Hoofffman authored Dec 18, 2023
1 parent b1745cd commit fd18d2e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func (a *Agent) reloadClusters(ctx *motan.Context) {
}

service := url.Path
mapKey := getClusterKey(url.Group, url.GetStringParamsWithDefault(motan.VersionKey, "0.1"), url.Protocol, url.Path)
mapKey := getClusterKey(url.Group, url.GetStringParamsWithDefault(motan.VersionKey, "1.0"), url.Protocol, url.Path)

// find exists old serviceMap
var serviceMapValue serviceMapItem
Expand Down Expand Up @@ -589,7 +589,7 @@ func (a *Agent) initCluster(url *motan.URL) {
}
a.serviceMap.UnsafeStore(url.Path, serviceMapItemArr)
})
mapKey := getClusterKey(url.Group, url.GetStringParamsWithDefault(motan.VersionKey, "0.1"), url.Protocol, url.Path)
mapKey := getClusterKey(url.Group, url.GetStringParamsWithDefault(motan.VersionKey, "1.0"), url.Protocol, url.Path)
a.clsLock.Lock() // Mutually exclusive with the reloadClusters method
defer a.clsLock.Unlock()
a.clusterMap.Store(mapKey, c)
Expand Down
2 changes: 1 addition & 1 deletion agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func TestAgent_InitCall(t *testing.T) {
}

//test init cluster with one path and one groups in clusterMap
temp := agent.clusterMap.LoadOrNil(getClusterKey("test1", "0.1", "", ""))
temp := agent.clusterMap.LoadOrNil(getClusterKey("test1", "1.0", "", ""))
assert.NotNil(t, temp, "init cluster with one path and two groups in clusterMap fail")

//test agentHandler call with group
Expand Down
7 changes: 3 additions & 4 deletions core/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ func (u *URL) IsMatch(service, group, protocol, version string) bool {
return false
}
}
return false
}
if version != "" && u.GetParam(VersionKey, "") != version {
return false
if version != "" && u.GetParam(VersionKey, "") != "" {
return version == u.GetParam(VersionKey, "")
}
return true
}
Expand Down Expand Up @@ -286,7 +285,7 @@ func (u *URL) CanServe(other *URL) bool {
vlog.Errorf("can not serve serialization, err : s1:%s, s2:%s", u.Parameters[SerializationKey], other.Parameters[SerializationKey])
return false
}
if !IsSame(u.Parameters, other.Parameters, VersionKey, "0.1") {
if !(IsSame(u.Parameters, other.Parameters, VersionKey, "0.1") || IsSame(u.Parameters, other.Parameters, VersionKey, "1.0")) {
vlog.Errorf("can not serve version, err : v1:%s, v2:%s", u.Parameters[VersionKey], other.Parameters[VersionKey])
return false
}
Expand Down
7 changes: 0 additions & 7 deletions protocol/motan1Protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,6 @@ func DecodeMotanV1Request(msg *MotanV1Message) (motan.Request, error) {
ctx := request.GetRPCContext(true)
ctx.OriginalMessage = msg
ctx.IsMotanV1 = true
// fill v2 attachment
if request.GetAttachment(MGroup) == "" {
request.SetAttachment(MGroup, request.GetAttachment(V1Group))
}
if request.GetAttachment(MVersion) == "" {
request.SetAttachment(MVersion, request.GetAttachment(V1Version))
}
return request, nil
}

Expand Down
7 changes: 7 additions & 0 deletions server/motanserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,13 @@ func (m *MotanServer) processV1(msg *mpro.MotanV1Message, start time.Time, ip st
var result []byte
var reqCtx *motan.RPCContext
req, err := mpro.DecodeMotanV1Request(msg)
// fill v2 attachment
if req.GetAttachment(mpro.MGroup) == "" {
req.SetAttachment(mpro.MGroup, req.GetAttachment(mpro.V1Group))
}
if req.GetAttachment(mpro.MVersion) == "" {
req.SetAttachment(mpro.MVersion, req.GetAttachment(mpro.V1Version))
}
if err != nil {
vlog.Errorf("decode v1 request fail. conn: %s, err:%s", conn.RemoteAddr().String(), err.Error())
result = mpro.BuildV1ExceptionResponse(msg.Rid, err.Error())
Expand Down

0 comments on commit fd18d2e

Please sign in to comment.