Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate vttablet metrics QueryCacheXX and rename to QueryPlanCacheXX #16289

Merged
merged 8 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 6 additions & 2 deletions changelog/20.0/20.0.0/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,12 @@ You can now run `VDiff`s on OnlineDDL schema change migrations, which are not ye

VTTablet exposes two new counter stats:

* `QueryCacheHits`: Query engine query cache hits
* `QueryCacheMisses`: Query engine query cache misses
* `QueryCacheHits`: Query engine query plan cache hits
* `QueryCacheMisses`: Query engine query plan cache misses

> [!NOTE]
> `QueryCache` does not refer to a query cache, but to a query plan cache.
> In v21, these metrics will be deprecated and replaced by `QueryPlanCacheHits` and `QueryPlanCacheMisses`.

### <a id="vttablet-query-text-characters-processed"/>VTTablet Query Text Characters Processed

Expand Down
8 changes: 6 additions & 2 deletions changelog/20.0/20.0.0/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,12 @@ You can now run `VDiff`s on OnlineDDL schema change migrations, which are not ye

VTTablet exposes two new counter stats:

* `QueryCacheHits`: Query engine query cache hits
* `QueryCacheMisses`: Query engine query cache misses
* `QueryCacheHits`: Query engine query plan cache hits
* `QueryCacheMisses`: Query engine query plan cache misses

> [!NOTE]
> `QueryCache` does not refer to a query cache, but to a query plan cache.
> In v21, these metrics will be deprecated and replaced by `QueryPlanCacheHits` and `QueryPlanCacheMisses`.

### <a id="vttablet-query-text-characters-processed"/>VTTablet Query Text Characters Processed

Expand Down
20 changes: 19 additions & 1 deletion changelog/21.0/21.0.0/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,31 @@
### Table of Contents

- **[Major Changes](#major-changes)**
- **[Deprecations](#deprecations)**
- [Metrics](#deprecations-metrics)
- **[Deletions](#deletions)**
- [Deletion of deprecated metrics](#metric-deletion)
- **[Breaking changes](#breaking-changes)**

## <a id="major-changes"/>Major Changes

### <a id="deletions"/>Deletion
### <a id="deprecations"/>Deprecations

#### <a id="deprecations-metrics"/>Metrics

The following metrics are now deprecated, if provided please use their replacement.

| Component | Metric Name | Replaced By |
|------------|:---------------------:|:-------------------------:|
| `vttablet` | `QueryCacheLength` | `QueryPlanCacheLength` |
| `vttablet` | `QueryCacheSize` | `QueryPlanCacheSize` |
| `vttablet` | `QueryCacheCapacity` | `QueryPlanCacheCapacity` |
| `vttablet` | `QueryCacheEvictions` | `QueryPlanCacheEvictions` |
| `vttablet` | `QueryCacheHits` | `QueryPlanCacheHits` |
| `vttablet` | `QueryCacheMisses` | `QueryPlanCacheMisses` |


### <a id="deletions"/>Deletions

#### <a id="metric-deletion"/>Deletion of deprecated metrics

Expand Down
1 change: 0 additions & 1 deletion config/tablet/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ hotRowProtection:
consolidator: enable|disable|notOnPrimary # enable-consolidator, enable-consolidator-replicas
passthroughDML: false # queryserver-config-passthrough-dmls
streamBufferSize: 32768 # queryserver-config-stream-buffer-size
queryCacheSize: 5000 # queryserver-config-query-cache-size
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag was removed a while ago, I took the liberty of removing this from the config file.

schemaReloadIntervalSeconds: 1800 # queryserver-config-schema-reload-time
watchReplication: false # watch_replication_stream
terseErrors: false # queryserver-config-terse-errors
Expand Down
1 change: 0 additions & 1 deletion doc/design-docs/TabletServerParamsAsYAML.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ heartbeatIntervalMilliseconds: 0 # heartbeat_enable, heartbeat_interval
shutdownGracePeriodSeconds: 0 # transaction_shutdown_grace_period
passthroughDML: false # queryserver-config-passthrough-dmls
streamBufferSize: 32768 # queryserver-config-stream-buffer-size
queryCacheSize: 5000 # queryserver-config-query-cache-size
schemaReloadIntervalSeconds: 1800 # queryserver-config-schema-reload-time
watchReplication: false # watch_replication_stream
terseErrors: false # queryserver-config-terse-errors
Expand Down
8 changes: 4 additions & 4 deletions go/vt/vttablet/endtoend/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func TestConsolidatorReplicasOnly(t *testing.T) {
}
}

func TestQueryPlanCache(t *testing.T) {
func TestQueryPlanCacheSize(t *testing.T) {
var cachedPlanSize = int((&tabletserver.TabletPlan{}).CachedSize(true))

// sleep to avoid race between SchemaChanged event clearing out the plans cache which breaks this test
Expand All @@ -211,19 +211,19 @@ func TestQueryPlanCache(t *testing.T) {
assert.Equal(t, 1, framework.Server.QueryPlanCacheLen())

vend := framework.DebugVars()
assert.GreaterOrEqual(t, framework.FetchInt(vend, "QueryCacheSize"), cachedPlanSize)
assert.GreaterOrEqual(t, framework.FetchInt(vend, "QueryPlanCacheSize"), cachedPlanSize)

_, _ = client.Execute("select * from vitess_test where intval=:ival2", bindVars)
require.Equal(t, 2, framework.Server.QueryPlanCacheLen())

vend = framework.DebugVars()
assert.GreaterOrEqual(t, framework.FetchInt(vend, "QueryCacheSize"), 2*cachedPlanSize)
assert.GreaterOrEqual(t, framework.FetchInt(vend, "QueryPlanCacheSize"), 2*cachedPlanSize)

_, _ = client.Execute("select * from vitess_test where intval=1", bindVars)
require.Equal(t, 3, framework.Server.QueryPlanCacheLen())

vend = framework.DebugVars()
assert.GreaterOrEqual(t, framework.FetchInt(vend, "QueryCacheSize"), 3*cachedPlanSize)
assert.GreaterOrEqual(t, framework.FetchInt(vend, "QueryPlanCacheSize"), 3*cachedPlanSize)
}

func TestMaxResultSize(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/endtoend/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func TestTrailingComment(t *testing.T) {
}
v2 := framework.Server.QueryPlanCacheLen()
if v2 != v1+1 {
t.Errorf("QueryCacheLength(%s): %d, want %d", query, v2, v1+1)
t.Errorf("QueryPlanCacheLength(%s): %d, want %d", query, v2, v1+1)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion go/vt/vttablet/tabletserver/debugenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ func debugEnvHandler(tsv *TabletServer, w http.ResponseWriter, r *http.Request)
vars = addVar(vars, "PoolSize", tsv.PoolSize)
vars = addVar(vars, "StreamPoolSize", tsv.StreamPoolSize)
vars = addVar(vars, "TxPoolSize", tsv.TxPoolSize)
vars = addVar(vars, "QueryCacheCapacity", tsv.QueryPlanCacheCap)
vars = addVar(vars, "QueryCacheCapacity", tsv.QueryPlanCacheCap) // QueryCacheCapacity is deprecated in v21, it is replaced by QueryPlanCacheCapacity
vars = addVar(vars, "QueryPlanCacheCapacity", tsv.QueryPlanCacheCap)
vars = addVar(vars, "MaxResultSize", tsv.MaxResultSize)
vars = addVar(vars, "WarnResultSize", tsv.WarnResultSize)
vars = addVar(vars, "RowStreamerMaxInnoDBTrxHistLen", func() int64 { return tsv.Config().RowStreamer.MaxInnoDBTrxHistLen })
Expand Down
43 changes: 36 additions & 7 deletions go/vt/vttablet/tabletserver/query_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ type QueryEngine struct {
// stats
// Note: queryErrorCountsWithCode is similar to queryErrorCounts except it contains error code as an additional dimension
queryCounts, queryCountsWithTabletType, queryTimes, queryErrorCounts, queryErrorCountsWithCode, queryRowsAffected, queryRowsReturned, queryTextCharsProcessed *stats.CountersWithMultiLabels
queryCacheHits, queryCacheMisses *stats.CounterFunc
queryPlanCacheHits, queryPlanCacheMisses *stats.CounterFunc

// stats flags
enablePerWorkloadTableMetrics bool
Expand Down Expand Up @@ -269,22 +269,51 @@ func NewQueryEngine(env tabletenv.Env, se *schema.Engine) *QueryEngine {
env.Exporter().NewGaugeFunc("StreamBufferSize", "Query engine stream buffer size", qe.streamBufferSize.Load)
env.Exporter().NewCounterFunc("TableACLExemptCount", "Query engine table ACL exempt count", qe.tableaclExemptCount.Load)

env.Exporter().NewGaugeFunc("QueryCacheLength", "Query engine query cache length", func() int64 {
// QueryCacheLength is deprecated in v21 and will be removed in >v22. This metric is replaced by QueryPlanCacheLength.
env.Exporter().NewGaugeFunc("QueryCacheLength", "Query engine query plan cache length (deprecated: please use QueryPlanCacheLength)", func() int64 {
return int64(qe.plans.Len())
})
env.Exporter().NewGaugeFunc("QueryCacheSize", "Query engine query cache size", func() int64 {
env.Exporter().NewGaugeFunc("QueryPlanCacheLength", "Query engine query plan cache length", func() int64 {
return int64(qe.plans.Len())
})

// QueryCacheSize is deprecated in v21 and will be removed in >v22. This metric is replaced QueryPlanCacheSizeQueryPlanCacheLength.
env.Exporter().NewGaugeFunc("QueryCacheSize", "Query engine query plan cache size (deprecated: please use QueryPlanCacheSize)", func() int64 {
return int64(qe.plans.UsedCapacity())
})
env.Exporter().NewGaugeFunc("QueryPlanCacheSize", "Query engine query plan cache size", func() int64 {
return int64(qe.plans.UsedCapacity())
})
env.Exporter().NewGaugeFunc("QueryCacheCapacity", "Query engine query cache capacity", func() int64 {

// QueryCacheCapacity is deprecated in v21 and will be removed in >v22. This metric is replaced by QueryPlanCacheCapacity.
env.Exporter().NewGaugeFunc("QueryCacheCapacity", "Query engine query plan cache capacity (deprecated: please use QueryPlanCacheCapacity)", func() int64 {
return int64(qe.plans.MaxCapacity())
})
env.Exporter().NewGaugeFunc("QueryPlanCacheCapacity", "Query engine query plan cache capacity", func() int64 {
return int64(qe.plans.MaxCapacity())
})
env.Exporter().NewCounterFunc("QueryCacheEvictions", "Query engine query cache evictions", func() int64 {

// QueryCacheEvictions is deprecated in v21 and will be removed in >v22. This metric is replaced by QueryPlanCacheEvictions.
env.Exporter().NewCounterFunc("QueryCacheEvictions", "Query engine query plan cache evictions (deprecated: please use QueryPlanCacheEvictions)", func() int64 {
return qe.plans.Metrics.Evicted()
})
qe.queryCacheHits = env.Exporter().NewCounterFunc("QueryCacheHits", "Query engine query cache hits", func() int64 {
env.Exporter().NewCounterFunc("QueryPlanCacheEvictions", "Query engine query plan cache evictions", func() int64 {
return qe.plans.Metrics.Evicted()
})

// QueryCacheHits is deprecated in v21 and will be removed in >v22. This metric is replaced by QueryPlanCacheHits.
_ = env.Exporter().NewCounterFunc("QueryCacheHits", "Query engine query plan cache hits (deprecated: please use QueryPlanCacheHits)", func() int64 {
return qe.plans.Metrics.Hits()
})
qe.queryPlanCacheHits = env.Exporter().NewCounterFunc("QueryPlanCacheHits", "Query engine query plan cache hits", func() int64 {
return qe.plans.Metrics.Hits()
})
qe.queryCacheMisses = env.Exporter().NewCounterFunc("QueryCacheMisses", "Query engine query cache misses", func() int64 {

// QueryCacheMisses is deprecated in v21 and will be removed in >v22. This metric is replaced by QueryPlanCacheMisses.
_ = env.Exporter().NewCounterFunc("QueryCacheMisses", "Query engine query plan cache misses (deprecated: please use QueryPlanCacheMisses)", func() int64 {
return qe.plans.Metrics.Misses()
})
qe.queryPlanCacheMisses = env.Exporter().NewCounterFunc("QueryPlanCacheMisses", "Query engine query plan cache misses", func() int64 {
return qe.plans.Metrics.Misses()
})

Expand Down
12 changes: 6 additions & 6 deletions go/vt/vttablet/tabletserver/query_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,26 +197,26 @@ func TestQueryPlanCache(t *testing.T) {
ctx := context.Background()
logStats := tabletenv.NewLogStats(ctx, "GetPlanStats")

initialHits := qe.queryCacheHits.Get()
initialMisses := qe.queryCacheMisses.Get()
Comment on lines -200 to -201
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to ensure that we keep testing the old metrics until we delete them, we should keep the tests for them. That will require keeping the struct members also around until the metrics are deleted. Each vttablet has one instance of the queryEngine, so it should not be a big deal.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done via ade9210

initialHits := qe.queryPlanCacheHits.Get()
initialMisses := qe.queryPlanCacheMisses.Get()

firstPlan, err := qe.GetPlan(ctx, logStats, firstQuery, false)
require.NoError(t, err)
require.NotNil(t, firstPlan, "plan should not be nil")

assertPlanCacheSize(t, qe, 1)

require.Equal(t, int64(0), qe.queryCacheHits.Get()-initialHits)
require.Equal(t, int64(1), qe.queryCacheMisses.Get()-initialMisses)
require.Equal(t, int64(0), qe.queryPlanCacheHits.Get()-initialHits)
require.Equal(t, int64(1), qe.queryPlanCacheMisses.Get()-initialMisses)

secondPlan, err := qe.GetPlan(ctx, logStats, firstQuery, false)
require.NoError(t, err)
require.NotNil(t, secondPlan, "plan should not be nil")

assertPlanCacheSize(t, qe, 1)

require.Equal(t, int64(1), qe.queryCacheHits.Get()-initialHits)
require.Equal(t, int64(1), qe.queryCacheMisses.Get()-initialMisses)
require.Equal(t, int64(1), qe.queryPlanCacheHits.Get()-initialHits)
require.Equal(t, int64(1), qe.queryPlanCacheMisses.Get()-initialMisses)

qe.ClearQueryPlanCache()
}
Expand Down
Loading