Skip to content

Commit

Permalink
[Controller] add debug update_time
Browse files Browse the repository at this point in the history
  • Loading branch information
jin-xiaofeng authored and sharang committed Jan 18, 2023
1 parent 9921a1a commit 86bd05f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
7 changes: 5 additions & 2 deletions cli/ctl/trisolaris_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net"
"sort"
"strconv"
"time"

"github.com/golang/protobuf/proto"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -318,9 +319,11 @@ func gpidAgentRequest(cmd *cobra.Command) {
fmt.Println(err)
return
}
fmt.Printf("response(ctrl_ip: %s ctrl_mac: %s vtap_id: %d)\n", response.GetCtrlIp(), response.GetCtrlMac(), response.GetVtapId())
req := response.GetSyncRequest()
tm := time.Unix(int64(response.GetUpdateTime()), 0)
fmt.Printf("response(ctrl_ip: %s ctrl_mac: %s vtap_id: %d update_time: %s)\n", req.GetCtrlIp(), req.GetCtrlMac(), req.GetVtapId(), tm.Format("2006-01-02 15:04:05"))
fmt.Println("Entries:")
for index, entry := range response.Entries {
for index, entry := range req.Entries {
JsonFormat(index+1, formatEntries(entry))
}
}
Expand Down
7 changes: 6 additions & 1 deletion message/trident.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ service Synchronizer {
// debug service
service Debug {
rpc DebugGPIDGlobalData (GPIDSyncRequest) returns(GPIDGlobalData) {}
rpc DebugGPIDVTapData (GPIDSyncRequest) returns(GPIDSyncRequest) {}
rpc DebugGPIDVTapData (GPIDSyncRequest) returns(GPIDVTapData) {}
rpc DebugRealGlobalData (GPIDSyncRequest) returns(RealGlobalData) {}
}

Expand Down Expand Up @@ -719,3 +719,8 @@ message RealClientToRealServer {
message RealGlobalData {
repeated RealClientToRealServer entries = 1;
}

message GPIDVTapData {
optional uint32 update_time = 1 [default = 0];
optional GPIDSyncRequest sync_request = 2;
}
15 changes: 7 additions & 8 deletions server/controller/trisolaris/services/grpc/debug/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,21 @@ func (s *service) DebugGPIDGlobalData(ctx context.Context, in *api.GPIDSyncReque
}, nil
}

func (s *service) DebugGPIDVTapData(ctx context.Context, in *api.GPIDSyncRequest) (*api.GPIDSyncRequest, error) {
func (s *service) DebugGPIDVTapData(ctx context.Context, in *api.GPIDSyncRequest) (*api.GPIDVTapData, error) {
vtapCacheKey := in.GetCtrlIp() + "-" + in.GetCtrlMac()
vtapCache := trisolaris.GetGVTapInfo().GetVTapCache(vtapCacheKey)
if vtapCache == nil {
log.Info("not found vtap(ctrl_ip: %s, ctrl_mac: %s) cache", in.GetCtrlIp(), in.GetCtrlMac())
return &api.GPIDSyncRequest{}, nil
return &api.GPIDVTapData{}, nil
}
log.Infof("receive DebugGPIDVTapLocalData about vtap(ctrl_ip: %s, ctrl_mac: %s, id: %d)",
in.GetCtrlIp(), in.GetCtrlMac(), vtapCache.GetVTapID())
processInfo := trisolaris.GetGVTapInfo().GetProcessInfo()
req := processInfo.GetVTapGPIDReq(uint32(vtapCache.GetVTapID()))
if req == nil {
req = &api.GPIDSyncRequest{}
}

return req, nil
req, updateTime := processInfo.GetVTapGPIDReq(uint32(vtapCache.GetVTapID()))
return &api.GPIDVTapData{
UpdateTime: &updateTime,
SyncRequest: req,
}, nil
}

func (s *service) DebugRealGlobalData(ctx context.Context, in *api.GPIDSyncRequest) (*api.RealGlobalData, error) {
Expand Down
27 changes: 17 additions & 10 deletions server/controller/trisolaris/vtap/process_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ func (c *CacheReq) getReq() *trident.GPIDSyncRequest {
return c.req
}

func (c *CacheReq) getUpdateTime() int {
if c == nil {
return 0
}
return int(c.updateTime.Unix())
}

func (c *CacheReq) After(r *CacheReq) bool {
if c == nil || r == nil {
return false
Expand Down Expand Up @@ -365,28 +372,27 @@ func (p *ProcessInfo) UpdateVTapGPIDReq(req *trident.GPIDSyncRequest) {
p.sendGPIDReq.updateReq(req)
}

func (p *ProcessInfo) GetVTapGPIDReq(vtapID uint32) *trident.GPIDSyncRequest {
var req *trident.GPIDSyncRequest
req = p.sendGPIDReq.getReq(vtapID)
if req == nil {
func (p *ProcessInfo) GetVTapGPIDReq(vtapID uint32) (*trident.GPIDSyncRequest, uint32) {
cacheReq := p.sendGPIDReq.getCacheReq(vtapID)
if cacheReq == nil {
localReq := p.vtapIDToLocalGPIDReq.getCacheReq(vtapID)
shareReq := p.vtapIDToShareGPIDReq.getCacheReq(vtapID)
if localReq != nil && shareReq != nil {
if localReq.After(shareReq) {
req = localReq.getReq()
cacheReq = localReq
} else {
req = shareReq.getReq()
cacheReq = shareReq
}
} else {
if localReq == nil {
req = shareReq.getReq()
cacheReq = shareReq
} else {
req = localReq.getReq()
cacheReq = localReq
}
}
}

return req
return cacheReq.getReq(), uint32(cacheReq.getUpdateTime())
}

func (p *ProcessInfo) UpdateGPIDReqFromShare(shareReq *trident.ShareGPIDSyncRequests) {
Expand Down Expand Up @@ -490,7 +496,8 @@ func (p *ProcessInfo) getGPIDInfoFromDB() {
}

func (p *ProcessInfo) GetGPIDResponseByVtapID(vtapID uint32) *trident.GPIDSyncResponse {
return p.GetGPIDResponseByReq(p.GetVTapGPIDReq(vtapID))
req, _ := p.GetVTapGPIDReq(vtapID)
return p.GetGPIDResponseByReq(req)
}

func (p *ProcessInfo) GetGPIDResponseByReq(req *trident.GPIDSyncRequest) *trident.GPIDSyncResponse {
Expand Down

0 comments on commit 86bd05f

Please sign in to comment.