Skip to content

Commit

Permalink
*: Add Used field to StoreCapacity to reduce disk accounting confusion
Browse files Browse the repository at this point in the history
Fixes #13548
  • Loading branch information
a-robinson committed Aug 17, 2017
1 parent 764407c commit 87c6e8d
Show file tree
Hide file tree
Showing 17 changed files with 336 additions and 108 deletions.
68 changes: 60 additions & 8 deletions c-deps/libroach/protos/cockroach/pkg/roachpb/metadata.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 35 additions & 3 deletions c-deps/libroach/protos/cockroach/pkg/roachpb/metadata.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions pkg/roachpb/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ func (p Percentiles) String() string {

// String returns a string representation of the StoreCapacity.
func (sc StoreCapacity) String() string {
return fmt.Sprintf("disk (capacity=%s, available=%s, logicalBytes=%s), "+
return fmt.Sprintf("disk (capacity=%s, available=%s, used=%s, logicalBytes=%s), "+
"ranges=%d, leases=%d, writes=%.2f, "+
"bytesPerReplica={%s}, writesPerReplica={%s}",
humanizeutil.IBytes(sc.Capacity), humanizeutil.IBytes(sc.Available),
humanizeutil.IBytes(sc.LogicalBytes),
humanizeutil.IBytes(sc.Used), humanizeutil.IBytes(sc.LogicalBytes),
sc.RangeCount, sc.LeaseCount, sc.WritesPerSecond,
sc.BytesPerReplica, sc.WritesPerReplica)
}
Expand All @@ -276,7 +276,17 @@ func (sc StoreCapacity) FractionUsed() float64 {
if sc.Capacity == 0 {
return 0
}
return float64(sc.Capacity-sc.Available) / float64(sc.Capacity)
// Prefer computing the fraction of available disk space used by considering
// anything on the disk that isn't in the store's data directory just a sunk
// cost, not truly part of the disk's capacity. This means that the disk's
// capacity is really just the available space plus cockroach's usage.
//
// Fall back to a more pessimistic calcuation of disk usage if we don't know
// how much space the store's data is taking up.
if sc.Used == 0 {
return float64(sc.Capacity-sc.Available) / float64(sc.Capacity)
}
return float64(sc.Used) / float64(sc.Available+sc.Used)
}

// CombinedAttrs returns the full list of attributes for the store, including
Expand Down
Loading

0 comments on commit 87c6e8d

Please sign in to comment.