Conditionalize LevelDB index retrievals.

The LevelDB index retrievals could be repeated in a given operation
batch if multiple queued mutations affect the same (Label Name) singles
and (Label Name, Label Value) doubles.  This is wasteful and
inefficient, as a single retrieval suffices.  Thusly this commit
retrieves the canonical index mappings if the said mapping has not
been looked up in a given batch.
This commit is contained in:
Matt T. Proud 2013-03-06 19:04:51 -08:00
parent 34a921e16d
commit 1e0d740f2a
1 changed files with 24 additions and 22 deletions

View File

@ -281,7 +281,6 @@ func (l *LevelDBMetricPersistence) AppendSamples(samples model.Samples) (err err
fingerprintSet, ok := labelNameFingerprints[labelName] fingerprintSet, ok := labelNameFingerprints[labelName]
if !ok { if !ok {
fingerprintSet = utility.Set{} fingerprintSet = utility.Set{}
}
fingerprints, err := l.GetFingerprintsForLabelName(labelName) fingerprints, err := l.GetFingerprintsForLabelName(labelName)
if err != nil { if err != nil {
@ -293,6 +292,8 @@ func (l *LevelDBMetricPersistence) AppendSamples(samples model.Samples) (err err
for _, fingerprint := range fingerprints { for _, fingerprint := range fingerprints {
fingerprintSet.Add(fingerprint) fingerprintSet.Add(fingerprint)
} }
}
fingerprintSet.Add(fingerprint) fingerprintSet.Add(fingerprint)
labelNameFingerprints[labelName] = fingerprintSet labelNameFingerprints[labelName] = fingerprintSet
} }
@ -344,7 +345,6 @@ func (l *LevelDBMetricPersistence) AppendSamples(samples model.Samples) (err err
fingerprintSet, ok := labelPairFingerprints[labelPair] fingerprintSet, ok := labelPairFingerprints[labelPair]
if !ok { if !ok {
fingerprintSet = utility.Set{} fingerprintSet = utility.Set{}
}
fingerprints, err := l.GetFingerprintsForLabelSet(model.LabelSet{ fingerprints, err := l.GetFingerprintsForLabelSet(model.LabelSet{
labelName: labelValue, labelName: labelValue,
@ -358,6 +358,8 @@ func (l *LevelDBMetricPersistence) AppendSamples(samples model.Samples) (err err
for _, fingerprint := range fingerprints { for _, fingerprint := range fingerprints {
fingerprintSet.Add(fingerprint) fingerprintSet.Add(fingerprint)
} }
}
fingerprintSet.Add(fingerprint) fingerprintSet.Add(fingerprint)
labelPairFingerprints[labelPair] = fingerprintSet labelPairFingerprints[labelPair] = fingerprintSet
} }