-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
83684: kvstreamer: reuse incomplete Get requests on resume batches r=yuzefovich a=yuzefovich Previously, for all incomplete requests in a batch we'd allocate new Get and Scan requests (since - due to a known issue #75452 - at the moment the lifecycle of the requests is not clearly defined, so we're not allowed to modify them). However, we can reuse the Get requests since they won't be ever modified (i.e. they are either complete or incomplete, and, unlike for Scan requests, the start key won't ever be shifted), so this commit takes advantage of this observation. Release note: None 83709: pkg/util/tracing: Add hidden tag group, make server responsible for sorting. r=benbardin a=benbardin Release note: none This moves all tags marked as "hidden" into a single tag group at the UI layer. This declutters the trace page a little bit and makes it easier to pick out more important information. <img width="1620" alt="Screen Shot 2022-07-01 at 12 37 07 PM" src="https://user-images.githubusercontent.com/261508/176937757-bf8ac920-9e28-4908-8de4-1fbc077fd2c7.png"> 83834: outliers: extract a Registry interface. r=matthewtodd a=matthewtodd This is a pure mechanical refactoring, preparing us for #81021, where we'll move outlier processing off of the hot execution path. The idea is that the outside world will continue to talk to us as a Registry, but we'll now have a seam into which we can insert some asynchrony. Release note: None Co-authored-by: Yahor Yuzefovich <[email protected]> Co-authored-by: Ben Bardin <[email protected]> Co-authored-by: Matthew Todd <[email protected]>
- Loading branch information
Showing
16 changed files
with
254 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package outliers | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/settings/cluster" | ||
"github.com/cockroachdb/cockroach/pkg/sql/clusterunique" | ||
"github.com/cockroachdb/cockroach/pkg/util/cache" | ||
"github.com/cockroachdb/cockroach/pkg/util/syncutil" | ||
"github.com/cockroachdb/cockroach/pkg/util/uint128" | ||
"github.com/cockroachdb/cockroach/pkg/util/uuid" | ||
) | ||
|
||
// maxCacheSize is the number of detected outliers we will retain in memory. | ||
// We choose a small value for the time being to allow us to iterate without | ||
// worrying about memory usage. See #79450. | ||
const ( | ||
maxCacheSize = 10 | ||
) | ||
|
||
// registry is the central object in the outliers subsystem. It observes | ||
// statement execution to determine which statements are outliers and | ||
// exposes the set of currently retained outliers. | ||
type registry struct { | ||
detector detector | ||
|
||
// Note that this single mutex places unnecessary constraints on outlier | ||
// detection and reporting. We will develop a higher-throughput system | ||
// before enabling the outliers subsystem by default. | ||
mu struct { | ||
syncutil.RWMutex | ||
statements map[clusterunique.ID][]*Outlier_Statement | ||
outliers *cache.UnorderedCache | ||
} | ||
} | ||
|
||
var _ Registry = ®istry{} | ||
|
||
func newRegistry(st *cluster.Settings, metrics Metrics) Registry { | ||
config := cache.Config{ | ||
Policy: cache.CacheFIFO, | ||
ShouldEvict: func(size int, key, value interface{}) bool { | ||
return size > maxCacheSize | ||
}, | ||
} | ||
r := ®istry{ | ||
detector: anyDetector{detectors: []detector{ | ||
latencyThresholdDetector{st: st}, | ||
newLatencyQuantileDetector(st, metrics), | ||
}}} | ||
r.mu.statements = make(map[clusterunique.ID][]*Outlier_Statement) | ||
r.mu.outliers = cache.NewUnorderedCache(config) | ||
return r | ||
} | ||
|
||
func (r *registry) ObserveStatement( | ||
sessionID clusterunique.ID, | ||
statementID clusterunique.ID, | ||
statementFingerprintID roachpb.StmtFingerprintID, | ||
latencyInSeconds float64, | ||
) { | ||
if !r.enabled() { | ||
return | ||
} | ||
r.mu.Lock() | ||
defer r.mu.Unlock() | ||
r.mu.statements[sessionID] = append(r.mu.statements[sessionID], &Outlier_Statement{ | ||
ID: statementID.GetBytes(), | ||
FingerprintID: statementFingerprintID, | ||
LatencyInSeconds: latencyInSeconds, | ||
}) | ||
} | ||
|
||
func (r *registry) ObserveTransaction(sessionID clusterunique.ID, txnID uuid.UUID) { | ||
if !r.enabled() { | ||
return | ||
} | ||
r.mu.Lock() | ||
defer r.mu.Unlock() | ||
statements := r.mu.statements[sessionID] | ||
delete(r.mu.statements, sessionID) | ||
|
||
hasOutlier := false | ||
for _, s := range statements { | ||
if r.detector.isOutlier(s) { | ||
hasOutlier = true | ||
} | ||
} | ||
|
||
if hasOutlier { | ||
for _, s := range statements { | ||
r.mu.outliers.Add(uint128.FromBytes(s.ID), &Outlier{ | ||
Session: &Outlier_Session{ID: sessionID.GetBytes()}, | ||
Transaction: &Outlier_Transaction{ID: &txnID}, | ||
Statement: s, | ||
}) | ||
} | ||
} | ||
} | ||
|
||
func (r *registry) IterateOutliers(ctx context.Context, visitor func(context.Context, *Outlier)) { | ||
r.mu.RLock() | ||
defer r.mu.RUnlock() | ||
r.mu.outliers.Do(func(e *cache.Entry) { | ||
visitor(ctx, e.Value.(*Outlier)) | ||
}) | ||
} | ||
|
||
// TODO(todd): | ||
// Once we can handle sufficient throughput to live on the hot | ||
// execution path in #81021, we can probably get rid of this external | ||
// concept of "enabled" and let the detectors just decide for themselves | ||
// internally. | ||
func (r *registry) enabled() bool { | ||
return r.detector.enabled() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.