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
458338afa5
commit
6bcc6c938b
1 changed files with 15 additions and 12 deletions
|
@ -509,22 +509,23 @@ func (is *indexSearch) createGlobalIndexes(tsid *TSID, mn *MetricName) {
|
||||||
ii := getIndexItems()
|
ii := getIndexItems()
|
||||||
defer putIndexItems(ii)
|
defer putIndexItems(ii)
|
||||||
|
|
||||||
// Create MetricID -> MetricName index.
|
// Create metricID -> metricName entry.
|
||||||
ii.B = marshalCommonPrefix(ii.B, nsPrefixMetricIDToMetricName)
|
ii.B = marshalCommonPrefix(ii.B, nsPrefixMetricIDToMetricName)
|
||||||
ii.B = encoding.MarshalUint64(ii.B, tsid.MetricID)
|
ii.B = encoding.MarshalUint64(ii.B, tsid.MetricID)
|
||||||
ii.B = mn.Marshal(ii.B)
|
ii.B = mn.Marshal(ii.B)
|
||||||
ii.Next()
|
ii.Next()
|
||||||
|
|
||||||
// Create MetricID -> TSID index.
|
// Create metricID -> TSID entry.
|
||||||
ii.B = marshalCommonPrefix(ii.B, nsPrefixMetricIDToTSID)
|
ii.B = marshalCommonPrefix(ii.B, nsPrefixMetricIDToTSID)
|
||||||
ii.B = encoding.MarshalUint64(ii.B, tsid.MetricID)
|
ii.B = encoding.MarshalUint64(ii.B, tsid.MetricID)
|
||||||
ii.B = tsid.Marshal(ii.B)
|
ii.B = tsid.Marshal(ii.B)
|
||||||
ii.Next()
|
ii.Next()
|
||||||
|
|
||||||
prefix := kbPool.Get()
|
// Create tag -> metricID entries for every tag in mn.
|
||||||
prefix.B = marshalCommonPrefix(prefix.B[:0], nsPrefixTagToMetricIDs)
|
kb := kbPool.Get()
|
||||||
ii.registerTagIndexes(prefix.B, mn, tsid.MetricID)
|
kb.B = marshalCommonPrefix(kb.B[:0], nsPrefixTagToMetricIDs)
|
||||||
kbPool.Put(prefix)
|
ii.registerTagIndexes(kb.B, mn, tsid.MetricID)
|
||||||
|
kbPool.Put(kb)
|
||||||
|
|
||||||
is.db.tb.AddItems(ii.Items)
|
is.db.tb.AddItems(ii.Items)
|
||||||
}
|
}
|
||||||
|
@ -2717,12 +2718,13 @@ func (is *indexSearch) createPerDayIndexes(date uint64, tsid *TSID, mn *MetricNa
|
||||||
ii := getIndexItems()
|
ii := getIndexItems()
|
||||||
defer putIndexItems(ii)
|
defer putIndexItems(ii)
|
||||||
|
|
||||||
|
// Create date -> metricID entry.
|
||||||
ii.B = marshalCommonPrefix(ii.B, nsPrefixDateToMetricID)
|
ii.B = marshalCommonPrefix(ii.B, nsPrefixDateToMetricID)
|
||||||
ii.B = encoding.MarshalUint64(ii.B, date)
|
ii.B = encoding.MarshalUint64(ii.B, date)
|
||||||
ii.B = encoding.MarshalUint64(ii.B, tsid.MetricID)
|
ii.B = encoding.MarshalUint64(ii.B, tsid.MetricID)
|
||||||
ii.Next()
|
ii.Next()
|
||||||
|
|
||||||
// Create per-day inverted index entries for TSID.
|
// Create metricName -> TSID entry.
|
||||||
ii.B = marshalCommonPrefix(ii.B, nsPrefixDateMetricNameToTSID)
|
ii.B = marshalCommonPrefix(ii.B, nsPrefixDateMetricNameToTSID)
|
||||||
ii.B = encoding.MarshalUint64(ii.B, date)
|
ii.B = encoding.MarshalUint64(ii.B, date)
|
||||||
ii.B = mn.Marshal(ii.B)
|
ii.B = mn.Marshal(ii.B)
|
||||||
|
@ -2730,17 +2732,18 @@ func (is *indexSearch) createPerDayIndexes(date uint64, tsid *TSID, mn *MetricNa
|
||||||
ii.B = tsid.Marshal(ii.B)
|
ii.B = tsid.Marshal(ii.B)
|
||||||
ii.Next()
|
ii.Next()
|
||||||
|
|
||||||
// Create per-day inverted index entries for metricID.
|
// Create per-day tag -> metricID entries for every tag in mn.
|
||||||
kb := kbPool.Get()
|
kb := kbPool.Get()
|
||||||
defer kbPool.Put(kb)
|
|
||||||
kb.B = marshalCommonPrefix(kb.B[:0], nsPrefixDateTagToMetricIDs)
|
kb.B = marshalCommonPrefix(kb.B[:0], nsPrefixDateTagToMetricIDs)
|
||||||
kb.B = encoding.MarshalUint64(kb.B, date)
|
kb.B = encoding.MarshalUint64(kb.B, date)
|
||||||
ii.registerTagIndexes(kb.B, mn, tsid.MetricID)
|
ii.registerTagIndexes(kb.B, mn, tsid.MetricID)
|
||||||
|
kbPool.Put(kb)
|
||||||
|
|
||||||
is.db.tb.AddItems(ii.Items)
|
is.db.tb.AddItems(ii.Items)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ii *indexItems) registerTagIndexes(prefix []byte, mn *MetricName, metricID uint64) {
|
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 = append(ii.B, prefix...)
|
||||||
ii.B = marshalTagValue(ii.B, nil)
|
ii.B = marshalTagValue(ii.B, nil)
|
||||||
ii.B = marshalTagValue(ii.B, mn.MetricGroup)
|
ii.B = marshalTagValue(ii.B, mn.MetricGroup)
|
||||||
|
@ -2748,7 +2751,7 @@ func (ii *indexItems) registerTagIndexes(prefix []byte, mn *MetricName, metricID
|
||||||
ii.Next()
|
ii.Next()
|
||||||
ii.addReverseMetricGroupIfNeeded(prefix, mn, metricID)
|
ii.addReverseMetricGroupIfNeeded(prefix, mn, metricID)
|
||||||
|
|
||||||
// Add index entries for tags: tag -> MetricID
|
// Add tag -> metricID entries.
|
||||||
for _, tag := range mn.Tags {
|
for _, tag := range mn.Tags {
|
||||||
ii.B = append(ii.B, prefix...)
|
ii.B = append(ii.B, prefix...)
|
||||||
ii.B = tag.Marshal(ii.B)
|
ii.B = tag.Marshal(ii.B)
|
||||||
|
@ -2756,7 +2759,7 @@ func (ii *indexItems) registerTagIndexes(prefix []byte, mn *MetricName, metricID
|
||||||
ii.Next()
|
ii.Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add index entries for composite tags: MetricGroup+tag -> MetricID
|
// Add index entries for composite tags: MetricGroup+tag -> metricID.
|
||||||
compositeKey := kbPool.Get()
|
compositeKey := kbPool.Get()
|
||||||
for _, tag := range mn.Tags {
|
for _, tag := range mn.Tags {
|
||||||
compositeKey.B = marshalCompositeTagKey(compositeKey.B[:0], mn.MetricGroup, tag.Key)
|
compositeKey.B = marshalCompositeTagKey(compositeKey.B[:0], mn.MetricGroup, tag.Key)
|
||||||
|
|
Loading…
Reference in a new issue