You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/03/19 02:35:53 UTC
[incubator-servicecomb-service-center] branch master updated:
SCB-389 SC does not re-create the tracing file. (#309)
This is an automated email from the ASF dual-hosted git repository.
littlecui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-service-center.git
The following commit(s) were added to refs/heads/master by this push:
new 29fbda9 SCB-389 SC does not re-create the tracing file. (#309)
29fbda9 is described below
commit 29fbda9e72860b957de02ba71e68f0ae59244dee
Author: little-cui <su...@qq.com>
AuthorDate: Mon Mar 19 10:35:51 2018 +0800
SCB-389 SC does not re-create the tracing file. (#309)
* SCB-389 SC does not re-create the tracing file.
* SCB-389 SC does not re-create the tracing file.
(cherry picked from commit 3ad1664)
* SCB-389 Optimize log print
---
.../plugin/infra/tracing/buildin/file_collector.go | 30 ++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/server/plugin/infra/tracing/buildin/file_collector.go b/server/plugin/infra/tracing/buildin/file_collector.go
index b61b8c2..a10fc29 100644
--- a/server/plugin/infra/tracing/buildin/file_collector.go
+++ b/server/plugin/infra/tracing/buildin/file_collector.go
@@ -51,6 +51,12 @@ func (f *FileCollector) write(batch []*zipkincore.Span) (c int) {
if len(batch) == 0 {
return
}
+
+ if err := f.checkFile(); err != nil {
+ util.Logger().Errorf(err, "check tracing file failed")
+ return
+ }
+
newLine := [...]byte{'\n'}
w := bufio.NewWriter(f.Fd)
for _, span := range batch {
@@ -70,6 +76,30 @@ func (f *FileCollector) write(batch []*zipkincore.Span) (c int) {
return
}
+func (f *FileCollector) checkFile() error {
+ if util.PathExist(f.Fd.Name()) {
+ return nil
+ }
+
+ stat, err := f.Fd.Stat()
+ if err != nil {
+ return fmt.Errorf("stat %s: %s", f.Fd.Name(), err)
+ }
+
+ util.Logger().Warnf(nil, "tracing file %s does not exist, re-create one", f.Fd.Name())
+ fd, err := os.OpenFile(f.Fd.Name(), os.O_APPEND|os.O_CREATE|os.O_RDWR, stat.Mode())
+ if err != nil {
+ return fmt.Errorf("open %s: %s", f.Fd.Name(), err)
+ }
+
+ var old *os.File
+ f.Fd, old = fd, f.Fd
+ if err := old.Close(); err != nil {
+ util.Logger().Errorf(err, "close %s", f.Fd.Name())
+ }
+ return nil
+}
+
func (f *FileCollector) loop(stopCh <-chan struct{}) {
var (
batch []*zipkincore.Span
--
To stop receiving notification emails like this one, please contact
littlecui@apache.org.