MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / Read

Method Read

pkg/controller/rtctrl/log_dispatcher.go:68–205  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

66}
67
68func (d *stdLogDispatcher) Read() {
69 buf := make([]byte, d.bufferLength+1)
70 next := 0 // offset
71 lnTabCnt := 0 // tab count in recent line
72 var lnReqID string
73 var ls LogStatStore
74 for {
75
76 // bytes count from connection
77 read, err := d.conn.Read(buf[next:d.bufferLength])
78 d.logger.V(9).Infof("recv res: read %d, data %s, err %+v", read, string(buf[next:next+read]), err)
79 if err != nil {
80 d.logger.V(5).Errorf("recv failed: %s", err.Error())
81 return
82 }
83
84 // if log store map is empty, discard the data
85 if len(d.logStoreMap.storeMap) == 0 {
86 d.logger.Warn("can't find log store map")
87 next = 0
88 continue
89 }
90
91 // if can't get the log store of the last request, discard the data
92 ls, err = d.logStoreMap.getLast()
93 if err != nil {
94 d.logger.Warnf("get last log store of %s failed", d.logStoreMap.String())
95 next = 0
96 continue
97 }
98 if ls == nil {
99 next = 0
100 continue
101 }
102
103 next += read
104
105 nzero := 0
106 lastln := -1
107 lastTab := -1
108
109 // parse data
110 for i := 0; i < next; i++ {
111 if buf[i] == ZeroByte { // \0 means the end of the request
112 d.logger.V(9).Infof("next %d lastln %d i %d nzero %d", next, lastln, i, nzero)
113 nzero++
114 copy(buf[i:], buf[i+1:next]) // remove \0
115 i--
116 next--
117 nwrite, err := ls.WriteStdLog(d.logFrom, buf[lastln+1:i+1], true)
118 // write error: discard the log data, start the new line process
119 // write all success: start the new line process
120 if err != nil || nwrite == i-lastln {
121 if err != nil {
122 d.logger.Errorf("write std log %s len %d with eof lastln %d i %d failed: %s", ls.String(), nwrite, lastln, i, err)
123 } else {
124 d.logger.V(6).Infof("write std log %s len %d with eof lastln %d i %d", ls.String(), nwrite, lastln, i)
125 }

Callers

nothing calls this directly

Calls 10

StringMethod · 0.95
WriteStdLogMethod · 0.95
InfofMethod · 0.80
VMethod · 0.80
ErrorfMethod · 0.80
WarnMethod · 0.80
getLastMethod · 0.80
WarnfMethod · 0.80
ErrorMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected