add a lot of extra heavy debugging

This commit is contained in:
Niko Storni 2021-05-21 01:48:46 +02:00
parent 45130499cd
commit 006b04f6e9

View file

@ -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)
}