diff --git a/holder.go b/holder.go index 256871058..3e40ea14b 100644 --- a/holder.go +++ b/holder.go @@ -1277,10 +1277,8 @@ func (h *Holder) LoadNodeID() (string, error) { // Log startup time and version to $DATA_DIR/.startup.log func (h *Holder) logStartup() error { - time, err := time.Now().MarshalText() - if err != nil { - return errors.Wrap(err, "creating timestamp") - } + RFC3339NanoFixedWidth := "2006-01-02T15:04:05.000000 07:00" + time := time.Now().Format(RFC3339NanoFixedWidth) logLine := fmt.Sprintf("%s\t%s\n", time, Version) f, err := os.OpenFile(h.path+"/.startup.log", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) diff --git a/server/handler_test.go b/server/handler_test.go index 593f801cc..c17a61fd7 100644 --- a/server/handler_test.go +++ b/server/handler_test.go @@ -25,6 +25,8 @@ import ( "math" gohttp "net/http" "net/http/httptest" + "os" + "path/filepath" "reflect" "sort" "strings" @@ -1607,6 +1609,11 @@ func Test_DiskUsage_Roaring(t *testing.T) { } // check usage for empty cluster + dumpFile(holder.Path() + "/.id") + dumpFile(holder.Path() + "/.startup.log") + dumpFile(holder.Path() + "/.topology") + dumpFile(holder.Path() + "/idalloc.db") + dumpDir(holder.Path()) exp0 := fmt.Sprintf(exp0f[n], capacity) w := httptest.NewRecorder() @@ -1647,6 +1654,8 @@ func Test_DiskUsage_Roaring(t *testing.T) { // check usage with data exp1 := fmt.Sprintf(exp1f[n], capacity) + dumpDir(holder.Path()) + w = httptest.NewRecorder() h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/ui/usage", nil)) if w.Code != gohttp.StatusOK { @@ -1660,6 +1669,44 @@ func Test_DiskUsage_Roaring(t *testing.T) { } } +func dumpFile(pth string) { + file, err := os.Open(pth) + defer file.Close() + msg := pth + if err != nil { + fmt.Printf("\n", err) + return + } + b, err := ioutil.ReadAll(file) + if err != nil { + fmt.Printf("\n", err) + } + msg += fmt.Sprintf(" (%d bytes):", len(b)) + if len(b) <= 1000 { + msg += fmt.Sprintf(string(b)) + } + fmt.Printf(msg) + fmt.Printf("\n") +} + +func dumpDir(pth string) { + var files []string + + err := filepath.Walk(pth, func(path string, info os.FileInfo, err error) error { + files = append(files, path) + return nil + }) + if err != nil { + panic(err) + } + for _, pth2 := range files { + file, _ := os.Open(pth2) + b, _ := ioutil.ReadAll(file) + fmt.Printf("%10d %s\n", len(b), pth2) + file.Close() + } +} + func mustJSONDecode(t *testing.T, r io.Reader) (ret map[string]interface{}) { dec := json.NewDecoder(r) err := dec.Decode(&ret)