Ittt #52

Merged
anbsky merged 62 commits from ittt into master 2021-07-24 02:35:22 +02:00
Showing only changes of commit 64ed7304f6 - Show all commits

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