Skip to content

Commit

Permalink
Merge pull request #17733 from a-robinson/capacity
Browse files Browse the repository at this point in the history
*: Address issues with tracking disk usage as capacity minus availability
  • Loading branch information
a-robinson authored Aug 18, 2017
2 parents 500efb7 + 050bc89 commit 522f43a
Show file tree
Hide file tree
Showing 23 changed files with 551 additions and 171 deletions.
121 changes: 112 additions & 9 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.

64 changes: 64 additions & 0 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.

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

// String returns a string representation of the StoreCapacity.
func (sc StoreCapacity) String() string {
return fmt.Sprintf("diskUsed=%s/%s (%.2f%%), "+
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-sc.Available), humanizeutil.IBytes(sc.Capacity),
sc.FractionUsed()*100, sc.RangeCount, sc.LeaseCount, sc.WritesPerSecond,
humanizeutil.IBytes(sc.Capacity), humanizeutil.IBytes(sc.Available),
humanizeutil.IBytes(sc.Used), humanizeutil.IBytes(sc.LogicalBytes),
sc.RangeCount, sc.LeaseCount, sc.WritesPerSecond,
sc.BytesPerReplica, sc.WritesPerReplica)
}

Expand All @@ -275,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 522f43a

Please sign in to comment.