mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-10 15:14:09 +00:00
lib/storage: generate the first tag->metricIDs item in a mergeset block with a single metricID
The first item from each mergeset block goes into index (lib/mergeset.blockHeader), so it must be short in order to reduce index size.
This commit is contained in:
parent
0a9cb6368e
commit
d2ed8cb0b2
1 changed files with 15 additions and 1 deletions
|
@ -2369,7 +2369,21 @@ func (tmm *tagToMetricIDsRowsMerger) flushPendingMetricIDs(dstData []byte, dstIt
|
|||
dstData = mp.Tag.Marshal(dstData)
|
||||
// Use sort.Sort instead of sort.Slice in order to reduce memory allocations
|
||||
sort.Sort(&tmm.pendingMetricIDs)
|
||||
for _, metricID := range tmm.pendingMetricIDs {
|
||||
pendingMetricIDs := tmm.pendingMetricIDs
|
||||
if len(dstItems) == 0 {
|
||||
// Put the first item with a single metricID, since this item goes into index, so it must be short.
|
||||
dstData = encoding.MarshalUint64(dstData, pendingMetricIDs[0])
|
||||
dstItems = append(dstItems, dstData[dstDataLen:])
|
||||
pendingMetricIDs = pendingMetricIDs[1:]
|
||||
if len(pendingMetricIDs) == 0 {
|
||||
tmm.pendingMetricIDs = tmm.pendingMetricIDs[:0]
|
||||
return dstData, dstItems
|
||||
}
|
||||
dstDataLen = len(dstData)
|
||||
dstData = marshalCommonPrefix(dstData, nsPrefixTagToMetricIDs, mp.AccountID, mp.ProjectID)
|
||||
dstData = mp.Tag.Marshal(dstData)
|
||||
}
|
||||
for _, metricID := range pendingMetricIDs {
|
||||
dstData = encoding.MarshalUint64(dstData, metricID)
|
||||
}
|
||||
tmm.pendingMetricIDs = tmm.pendingMetricIDs[:0]
|
||||
|
|
Loading…
Reference in a new issue