From 006b04f6e9bc140572c4a9b1acdb2a7a1232adb6 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Fri, 21 May 2021 01:48:46 +0200 Subject: [PATCH] add a lot of extra heavy debugging --- store/disk.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/store/disk.go b/store/disk.go index eaecfbb..f108204 100644 --- a/store/disk.go +++ b/store/disk.go @@ -101,6 +101,12 @@ func (d *DiskStore) Get(hash string) (stream.Blob, shared.BlobTrace, error) { // Put stores the blob on disk func (d *DiskStore) Put(hash string, blob stream.Blob) error { + start := time.Now() + defer func() { + if time.Since(start) > 100*time.Millisecond { + log.Infof("it took %s to write %s", time.Since(start), hash) + } + }() err := d.initOnce() if err != nil { return err @@ -110,8 +116,26 @@ func (d *DiskStore) Put(hash string, blob stream.Blob) error { if err != nil { return err } - + hashBytes := sha512.Sum384(blob) + readHash := hex.EncodeToString(hashBytes[:]) + matchesBeforeWriting := readHash == hash err = ioutil.WriteFile(d.path(hash), blob, 0644) + if err != nil { + log.Errorf("Error saving to disk: %s", err.Error()) + } + readBlob, err := ioutil.ReadFile(d.path(hash)) + matchesAfterReading := false + if err != nil { + log.Errorf("for some fucking reasons I can't read the blob I just wrote %s", err.Error()) + } else { + hashBytes = sha512.Sum384(readBlob) + readHash = hex.EncodeToString(hashBytes[:]) + matchesAfterReading = readHash == hash + } + + log.Infof(`writing %s to disk: hash match: %t, error: %t +reading after writing: hash match: %t`, hash, matchesBeforeWriting, err == nil, matchesAfterReading) + return errors.Err(err) }