Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ We use the following categories for changes:

### Fixed
- Make Jaeger Event queryable using name and tags [#1553]
- Reset inverted labels cache on epoch change [#1561]

## [0.13.0] - 2022-07-20

Expand Down
2 changes: 1 addition & 1 deletion pkg/pgmodel/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ TODO (@ante do you want to write this?)

## Write Path

A `WriteRequest` is made out of a `[]TimeSeries` each of which contains a set of lables, each a `{string, string}`, and a set of samples, each a `{Timestamp, Value}`. Logically, the write path deals with this write request multiple stages. In Go notation, this can be thought of as follows
A `WriteRequest` is made out of a `[]TimeSeries` each of which contains a set of labels, each a `{string, string}`, and a set of samples, each a `{Timestamp, Value}`. Logically, the write path deals with this write request multiple stages. In Go notation, this can be thought of as follows

```go
type WriteRequest = []TimeSeries
Expand Down
6 changes: 5 additions & 1 deletion pkg/pgmodel/cache/inverted_labels_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type InvertedLabelsCache struct {
}

// Cache is thread-safe
func NewInvertedLablesCache(size uint64) (*InvertedLabelsCache, error) {
func NewInvertedLabelsCache(size uint64) (*InvertedLabelsCache, error) {
if size <= 0 {
return nil, fmt.Errorf("labels cache size must be > 0")
}
Expand All @@ -62,3 +62,7 @@ func (c *InvertedLabelsCache) Put(key LabelKey, val LabelInfo) bool {
_, added := c.cache.Insert(key, val, uint64(key.len())+uint64(val.len())+17)
return added
}

func (c *InvertedLabelsCache) Reset() {
c.cache.Reset()
}
8 changes: 7 additions & 1 deletion pkg/pgmodel/ingestor/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type pgxDispatcher struct {
conn pgxconn.PgxConn
metricTableNames cache.MetricCache
scache cache.SeriesCache
invertedLabelsCache *cache.InvertedLabelsCache
exemplarKeyPosCache cache.PositionCache
batchers sync.Map
completeMetricCreation chan struct{}
Expand Down Expand Up @@ -76,7 +77,7 @@ func newPgxDispatcher(conn pgxconn.PgxConn, mCache cache.MetricCache, scache cac
}

labelArrayOID := model.GetCustomTypeOID(model.LabelArray)
labelsCache, err := cache.NewInvertedLablesCache(cfg.InvertedLabelsCacheSize)
labelsCache, err := cache.NewInvertedLabelsCache(cfg.InvertedLabelsCacheSize)
if err != nil {
return nil, err
}
Expand All @@ -91,6 +92,7 @@ func newPgxDispatcher(conn pgxconn.PgxConn, mCache cache.MetricCache, scache cac
conn: conn,
metricTableNames: mCache,
scache: scache,
invertedLabelsCache: labelsCache,
exemplarKeyPosCache: eCache,
completeMetricCreation: make(chan struct{}, 1),
asyncAcks: cfg.AsyncAcks,
Expand Down Expand Up @@ -156,10 +158,14 @@ func (p *pgxDispatcher) refreshSeriesEpoch(existingEpoch model.SeriesEpoch) (mod
if err != nil {
// Trash the cache just in case an epoch change occurred, seems safer
p.scache.Reset()
// Also trash the inverted labels cache, which can also be invalidated when the series cache is
p.invertedLabelsCache.Reset()
return model.InvalidSeriesEpoch, err
}
if existingEpoch == model.InvalidSeriesEpoch || dbEpoch != existingEpoch {
p.scache.Reset()
// If the series cache needs to be invalidated, so does the inverted labels cache
p.invertedLabelsCache.Reset()
}
return dbEpoch, nil
}
Expand Down
26 changes: 21 additions & 5 deletions pkg/pgmodel/ingestor/ingestor_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func TestPGXInserterInsertSeries(t *testing.T) {
mock := model.NewSqlRecorder(c.sqlQueries, t)
scache := cache.NewSeriesCache(cache.DefaultConfig, nil)
scache.Reset()
lCache, _ := cache.NewInvertedLablesCache(10)
lCache, _ := cache.NewInvertedLabelsCache(10)
sw := NewSeriesWriter(mock, 0, lCache)

lsi := make([]model.Insertable, 0)
Expand Down Expand Up @@ -393,6 +393,21 @@ func TestPGXInserterCacheReset(t *testing.T) {
},
{Sql: "COMMIT;"},
{Sql: "BEGIN;"},
{
Sql: "SELECT * FROM _prom_catalog.get_or_create_label_ids($1, $2, $3, $4)",
Args: []interface{}{
"metric_1",
tableName,
[]string{"__name__", "name_1", "name_1"},
[]string{"metric_1", "value_1", "value_2"},
},
Results: model.RowResults{
{[]int32{1, 2, 2}, []int32{1, 2, 3}, []string{"__name__", "name_1", "name_1"}, []string{"metric_1", "value_1", "value_2"}},
},
Err: error(nil),
},
{Sql: "COMMIT;"},
{Sql: "BEGIN;"},
{
Sql: seriesInsertSQL,
Args: []interface{}{
Expand All @@ -419,11 +434,12 @@ func TestPGXInserterCacheReset(t *testing.T) {

mock := model.NewSqlRecorder(sqlQueries, t)
scache := cache.NewSeriesCache(cache.DefaultConfig, nil)
lcache, _ := cache.NewInvertedLablesCache(10)
lcache, _ := cache.NewInvertedLabelsCache(10)
sw := NewSeriesWriter(mock, 0, lcache)
inserter := pgxDispatcher{
conn: mock,
scache: scache,
conn: mock,
scache: scache,
invertedLabelsCache: lcache,
}

makeSamples := func(series []labels.Labels) []model.Insertable {
Expand Down Expand Up @@ -460,7 +476,7 @@ func TestPGXInserterCacheReset(t *testing.T) {
}
}

// refreshing during the same epoch givesthe same IDs without checking the DB
// refreshing during the same epoch gives the same IDs without checking the DB
_, err = inserter.refreshSeriesEpoch(1)
require.NoError(t, err)

Expand Down