[perf] Have SQLTraceStore use the cache.Cache interface.
Change-Id: I2fca1c7545a2160cb07bdf0750564086794d5f64
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/305857
Reviewed-by: Joe Gregorio <jcgregorio@google.com>
Commit-Queue: Joe Gregorio <jcgregorio@google.com>
diff --git a/perf/go/tracestore/sqltracestore/sqltracestore.go b/perf/go/tracestore/sqltracestore/sqltracestore.go
index 959bba2..c03c9b1 100644
--- a/perf/go/tracestore/sqltracestore/sqltracestore.go
+++ b/perf/go/tracestore/sqltracestore/sqltracestore.go
@@ -134,7 +134,6 @@
"text/template"
"time"
- lru "github.com/hashicorp/golang-lru"
"go.skia.org/infra/go/metrics2"
"go.skia.org/infra/go/paramtools"
"go.skia.org/infra/go/query"
@@ -143,6 +142,8 @@
"go.skia.org/infra/go/timer"
"go.skia.org/infra/go/util"
"go.skia.org/infra/go/vec32"
+ "go.skia.org/infra/perf/go/cache"
+ "go.skia.org/infra/perf/go/cache/local"
perfsql "go.skia.org/infra/perf/go/sql"
"go.skia.org/infra/perf/go/tracestore"
"go.skia.org/infra/perf/go/tracestore/sqltracestore/engine"
@@ -325,7 +326,7 @@
//
// For traceNames the md5 sum is used to keep the cache keys shorter, thus preserving
// memory and also allowing the use of memcached which restricts keys to 250 chars.
- cache *lru.Cache
+ cache cache.Cache
// tileSize is the number of commits per Tile.
tileSize int32
@@ -364,7 +365,7 @@
unpreparedStatements[key] = t
}
- cache, err := lru.New(cacheSize)
+ cache, err := local.New(cacheSize)
if err != nil {
return nil, skerr.Wrap(err)
}
@@ -823,8 +824,10 @@
s.cache.Add(hashedTraceName, traceID)
}
postingsCacheEntryKey := getPostingsCacheEntryKey(traceID, tileNumber)
- if !s.cache.Contains(postingsCacheEntryKey) {
+ if !s.cache.Exists(postingsCacheEntryKey) {
s.writeTraceIDAndPostingsPostingsCacheMissMetric.Inc(1)
+ // TODO(jcgregorio) Do a query on the database to see if the postings are there.
+
// Update postings.
if err := s.updatePostings(traceNameAsParams, tileNumber, traceID); err != nil {
return traceID, skerr.Wrapf(err, "traceName=%q tileNumber=%d traceID=%d", traceName, tileNumber, traceID)
diff --git a/perf/go/tracestore/sqltracestore/sqltracestore_test.go b/perf/go/tracestore/sqltracestore/sqltracestore_test.go
index 215c207..e0b54ce 100644
--- a/perf/go/tracestore/sqltracestore/sqltracestore_test.go
+++ b/perf/go/tracestore/sqltracestore/sqltracestore_test.go
@@ -77,7 +77,7 @@
got, ok := s.cache.Get(getHashedTraceName(traceName))
assert.True(t, ok)
assert.Equal(t, traceID, got.(traceIDFromSQL))
- assert.True(t, s.cache.Contains(getPostingsCacheEntryKey(traceID, tileNumber)))
+ assert.True(t, s.cache.Exists(getPostingsCacheEntryKey(traceID, tileNumber)))
const traceName2 = ",arch=arm,config=8888,"
p2 := paramtools.NewParams(traceName2)