mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-09 15:27:11 +00:00
lib/storage: improve comments inside functions responsible for creating indexes for newly registered time series
This commit is contained in:
parent
691181867e
commit
9b2a5c8844
1 changed files with 15 additions and 12 deletions
|
@ -531,22 +531,23 @@ func (is *indexSearch) createGlobalIndexes(tsid *TSID, mn *MetricName) {
|
|||
ii := getIndexItems()
|
||||
defer putIndexItems(ii)
|
||||
|
||||
// Create MetricID -> MetricName index.
|
||||
// Create metricID -> metricName entry.
|
||||
ii.B = marshalCommonPrefix(ii.B, nsPrefixMetricIDToMetricName, mn.AccountID, mn.ProjectID)
|
||||
ii.B = encoding.MarshalUint64(ii.B, tsid.MetricID)
|
||||
ii.B = mn.Marshal(ii.B)
|
||||
ii.Next()
|
||||
|
||||
// Create MetricID -> TSID index.
|
||||
// Create metricID -> TSID entry.
|
||||
ii.B = marshalCommonPrefix(ii.B, nsPrefixMetricIDToTSID, mn.AccountID, mn.ProjectID)
|
||||
ii.B = encoding.MarshalUint64(ii.B, tsid.MetricID)
|
||||
ii.B = tsid.Marshal(ii.B)
|
||||
ii.Next()
|
||||
|
||||
prefix := kbPool.Get()
|
||||
prefix.B = marshalCommonPrefix(prefix.B[:0], nsPrefixTagToMetricIDs, mn.AccountID, mn.ProjectID)
|
||||
ii.registerTagIndexes(prefix.B, mn, tsid.MetricID)
|
||||
kbPool.Put(prefix)
|
||||
// Create tag -> metricID entries for every tag in mn.
|
||||
kb := kbPool.Get()
|
||||
kb.B = marshalCommonPrefix(kb.B[:0], nsPrefixTagToMetricIDs, mn.AccountID, mn.ProjectID)
|
||||
ii.registerTagIndexes(kb.B, mn, tsid.MetricID)
|
||||
kbPool.Put(kb)
|
||||
|
||||
is.db.tb.AddItems(ii.Items)
|
||||
}
|
||||
|
@ -2872,12 +2873,13 @@ func (is *indexSearch) createPerDayIndexes(date uint64, tsid *TSID, mn *MetricNa
|
|||
ii := getIndexItems()
|
||||
defer putIndexItems(ii)
|
||||
|
||||
// Create date -> metricID entry.
|
||||
ii.B = marshalCommonPrefix(ii.B, nsPrefixDateToMetricID, mn.AccountID, mn.ProjectID)
|
||||
ii.B = encoding.MarshalUint64(ii.B, date)
|
||||
ii.B = encoding.MarshalUint64(ii.B, tsid.MetricID)
|
||||
ii.Next()
|
||||
|
||||
// Create per-day inverted index entries for TSID.
|
||||
// Create metricName -> TSID entry.
|
||||
//
|
||||
// Do not use marshalCommonPrefix() here, since mn already contains (AccountID, ProjectID)
|
||||
ii.B = append(ii.B, nsPrefixDateMetricNameToTSID)
|
||||
|
@ -2887,17 +2889,18 @@ func (is *indexSearch) createPerDayIndexes(date uint64, tsid *TSID, mn *MetricNa
|
|||
ii.B = tsid.Marshal(ii.B)
|
||||
ii.Next()
|
||||
|
||||
// Create per-day inverted index entries for metricID.
|
||||
// Create per-day tag -> metricID entries for every tag in mn.
|
||||
kb := kbPool.Get()
|
||||
defer kbPool.Put(kb)
|
||||
kb.B = marshalCommonPrefix(kb.B[:0], nsPrefixDateTagToMetricIDs, mn.AccountID, mn.ProjectID)
|
||||
kb.B = encoding.MarshalUint64(kb.B, date)
|
||||
ii.registerTagIndexes(kb.B, mn, tsid.MetricID)
|
||||
kbPool.Put(kb)
|
||||
|
||||
is.db.tb.AddItems(ii.Items)
|
||||
}
|
||||
|
||||
func (ii *indexItems) registerTagIndexes(prefix []byte, mn *MetricName, metricID uint64) {
|
||||
// Add index entry for MetricGroup -> MetricID
|
||||
// Add MetricGroup -> metricID entry.
|
||||
ii.B = append(ii.B, prefix...)
|
||||
ii.B = marshalTagValue(ii.B, nil)
|
||||
ii.B = marshalTagValue(ii.B, mn.MetricGroup)
|
||||
|
@ -2905,7 +2908,7 @@ func (ii *indexItems) registerTagIndexes(prefix []byte, mn *MetricName, metricID
|
|||
ii.Next()
|
||||
ii.addReverseMetricGroupIfNeeded(prefix, mn, metricID)
|
||||
|
||||
// Add index entries for tags: tag -> MetricID
|
||||
// Add tag -> metricID entries.
|
||||
for _, tag := range mn.Tags {
|
||||
ii.B = append(ii.B, prefix...)
|
||||
ii.B = tag.Marshal(ii.B)
|
||||
|
@ -2913,7 +2916,7 @@ func (ii *indexItems) registerTagIndexes(prefix []byte, mn *MetricName, metricID
|
|||
ii.Next()
|
||||
}
|
||||
|
||||
// Add index entries for composite tags: MetricGroup+tag -> MetricID
|
||||
// Add index entries for composite tags: MetricGroup+tag -> metricID.
|
||||
compositeKey := kbPool.Get()
|
||||
for _, tag := range mn.Tags {
|
||||
compositeKey.B = marshalCompositeTagKey(compositeKey.B[:0], mn.MetricGroup, tag.Key)
|
||||
|
|
Loading…
Reference in a new issue