From 1e0d740f2a380d8d729a32efef24ffe9d613c643 Mon Sep 17 00:00:00 2001 From: "Matt T. Proud" Date: Wed, 6 Mar 2013 19:04:51 -0800 Subject: [PATCH] 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. --- storage/metric/leveldb.go | 46 ++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/storage/metric/leveldb.go b/storage/metric/leveldb.go index 7e7f6e3ab..88ba8f59b 100644 --- a/storage/metric/leveldb.go +++ b/storage/metric/leveldb.go @@ -281,18 +281,19 @@ func (l *LevelDBMetricPersistence) AppendSamples(samples model.Samples) (err err fingerprintSet, ok := labelNameFingerprints[labelName] if !ok { fingerprintSet = utility.Set{} + + fingerprints, err := l.GetFingerprintsForLabelName(labelName) + if err != nil { + panic(err) + doneBuildingLabelNameIndex <- err + return + } + + for _, fingerprint := range fingerprints { + fingerprintSet.Add(fingerprint) + } } - fingerprints, err := l.GetFingerprintsForLabelName(labelName) - if err != nil { - panic(err) - doneBuildingLabelNameIndex <- err - return - } - - for _, fingerprint := range fingerprints { - fingerprintSet.Add(fingerprint) - } fingerprintSet.Add(fingerprint) labelNameFingerprints[labelName] = fingerprintSet } @@ -344,20 +345,21 @@ func (l *LevelDBMetricPersistence) AppendSamples(samples model.Samples) (err err fingerprintSet, ok := labelPairFingerprints[labelPair] if !ok { fingerprintSet = utility.Set{} + + fingerprints, err := l.GetFingerprintsForLabelSet(model.LabelSet{ + labelName: labelValue, + }) + if err != nil { + panic(err) + doneBuildingLabelPairIndex <- err + return + } + + for _, fingerprint := range fingerprints { + fingerprintSet.Add(fingerprint) + } } - fingerprints, err := l.GetFingerprintsForLabelSet(model.LabelSet{ - labelName: labelValue, - }) - if err != nil { - panic(err) - doneBuildingLabelPairIndex <- err - return - } - - for _, fingerprint := range fingerprints { - fingerprintSet.Add(fingerprint) - } fingerprintSet.Add(fingerprint) labelPairFingerprints[labelPair] = fingerprintSet }