-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flush MVCC stats to range and store counters. #125
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,21 @@ const ( | |
scanRowCount = int64(1 << 8) | ||
) | ||
|
||
// encodeMVCCStatValue constructs a proto.Value using the supplied | ||
// stat increment and then encodes that into a byte slice. Encoding | ||
// errors cause panice (as they should never happen). Returns false | ||
// if stat is equal to 0 to avoid unnecessary merge. | ||
func encodeMVCCStatValue(stat int64) (ok bool, enc []byte) { | ||
if stat == 0 { | ||
return false, nil | ||
} | ||
data, err := gogoproto.Marshal(&proto.Value{Integer: gogoproto.Int64(stat)}) | ||
if err != nil { | ||
panic("could not marshal proto.Value") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should you return the Error() too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of returning errors in the event that errors aren't possible. The day we can't proto.Marshal a Value object is the day the entire system falls off a cliff. Sometimes an assertion is the better option. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah sorry, I meant print the Error() in the panic, not return it.... but you're right that it shouldn't probably happen There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah good point! Changed. |
||
} | ||
return true, data | ||
} | ||
|
||
// MVCCStats tracks byte and instance counts for: | ||
// - Live key/values (i.e. what a scan at current time will reveal; | ||
// note that this includes intent keys and values, but not keys and | ||
|
@@ -615,6 +630,43 @@ func (mvcc *MVCC) ResolveWriteIntentRange(key, endKey Key, max int64, txn *proto | |
return num, nil | ||
} | ||
|
||
// FlushStats flushes stats to merge counters for both the affected | ||
// range and store. | ||
func (mvcc *MVCC) FlushStats(rangeID int64, storeID int32) { | ||
if ok, encLiveBytes := encodeMVCCStatValue(mvcc.LiveBytes); ok { | ||
mvcc.batch.Merge(MakeRangeStatKey(rangeID, StatLiveBytes), encLiveBytes) | ||
mvcc.batch.Merge(MakeStoreStatKey(storeID, StatLiveBytes), encLiveBytes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you make a util func for both MakeRangeStatKey and MakeStoreStatKey thus we don't need to duplicate codes here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
if ok, encKeyBytes := encodeMVCCStatValue(mvcc.KeyBytes); ok { | ||
mvcc.batch.Merge(MakeRangeStatKey(rangeID, StatKeyBytes), encKeyBytes) | ||
mvcc.batch.Merge(MakeStoreStatKey(storeID, StatKeyBytes), encKeyBytes) | ||
} | ||
if ok, encValBytes := encodeMVCCStatValue(mvcc.ValBytes); ok { | ||
mvcc.batch.Merge(MakeRangeStatKey(rangeID, StatValBytes), encValBytes) | ||
mvcc.batch.Merge(MakeStoreStatKey(storeID, StatValBytes), encValBytes) | ||
} | ||
if ok, encIntentBytes := encodeMVCCStatValue(mvcc.IntentBytes); ok { | ||
mvcc.batch.Merge(MakeRangeStatKey(rangeID, StatIntentBytes), encIntentBytes) | ||
mvcc.batch.Merge(MakeStoreStatKey(storeID, StatIntentBytes), encIntentBytes) | ||
} | ||
if ok, encLiveCount := encodeMVCCStatValue(mvcc.LiveCount); ok { | ||
mvcc.batch.Merge(MakeRangeStatKey(rangeID, StatLiveCount), encLiveCount) | ||
mvcc.batch.Merge(MakeStoreStatKey(storeID, StatLiveCount), encLiveCount) | ||
} | ||
if ok, encKeyCount := encodeMVCCStatValue(mvcc.KeyCount); ok { | ||
mvcc.batch.Merge(MakeRangeStatKey(rangeID, StatKeyCount), encKeyCount) | ||
mvcc.batch.Merge(MakeStoreStatKey(storeID, StatKeyCount), encKeyCount) | ||
} | ||
if ok, encValCount := encodeMVCCStatValue(mvcc.ValCount); ok { | ||
mvcc.batch.Merge(MakeRangeStatKey(rangeID, StatValCount), encValCount) | ||
mvcc.batch.Merge(MakeStoreStatKey(storeID, StatValCount), encValCount) | ||
} | ||
if ok, encIntentCount := encodeMVCCStatValue(mvcc.IntentCount); ok { | ||
mvcc.batch.Merge(MakeRangeStatKey(rangeID, StatIntentCount), encIntentCount) | ||
mvcc.batch.Merge(MakeStoreStatKey(storeID, StatIntentCount), encIntentCount) | ||
} | ||
} | ||
|
||
// a splitSampleItem wraps a key along with an aggregate over key range | ||
// preceding it. | ||
type splitSampleItem struct { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/s/panice/panic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.