Skip to content

Commit

Permalink
fix and add log output during long key usage analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
DocSavage committed Mar 24, 2024
1 parent 5d6c0d8 commit 7190785
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,10 +852,11 @@ func GetStorageSummary() (string, error) {
}

// Convert data to JSON string
m, err := json.Marshal(breakdown)
m, err := json.MarshalIndent(breakdown, "", " ")
if err != nil {
return "", err
}
dvid.Infof("Key usage:\n%s\n", string(m))
return string(m), nil
}

Expand Down
6 changes: 3 additions & 3 deletions storage/badger/badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ func (db *BadgerDB) GetKeyUsage(ranges []storage.KeyRange) (hitsPerInstance []ma
opts.PrefetchValues = false
it := txn.NewIterator(opts)
defer it.Close()
dvid.Infof("Checking key usage for Badger @ %s ...\n", db.directory)
for i, kr := range ranges {
// Allocate histogram for this key range (i.e., a data instance)
hitsPerInstance[i] = make(map[int]int)
Expand All @@ -316,9 +317,7 @@ func (db *BadgerDB) GetKeyUsage(ranges []storage.KeyRange) (hitsPerInstance []ma

// Add version to the stats for this key.
if bytes.Compare(kv.K, maxVersionKey) > 0 {
if storage.Key(kv.K).IsDataKey() {
maxVersionKey = storage.MaxVersionDataKeyFromKey(kr.Start)
}
maxVersionKey = storage.MaxVersionDataKeyFromKey(kv.K)
hitsPerInstance[i][numVersions]++
numVersions = 0
}
Expand All @@ -331,6 +330,7 @@ func (db *BadgerDB) GetKeyUsage(ranges []storage.KeyRange) (hitsPerInstance []ma

}
}
dvid.Infof("Key usage for Badger @ %s:\n %v\n", db.directory, hitsPerInstance)
return nil
})
return
Expand Down

0 comments on commit 7190785

Please sign in to comment.