-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathcontention.go
76 lines (64 loc) · 2.54 KB
/
contention.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2021 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 contentionpb
import (
"fmt"
"strings"
"github.com/cockroachdb/cockroach/pkg/util/uuid"
)
const singleIndentation = " "
const doubleIndentation = singleIndentation + singleIndentation
const tripleIndentation = doubleIndentation + singleIndentation
const contentionEventsStr = "num contention events:"
const cumulativeContentionTimeStr = "cumulative contention time:"
const contendingTxnsStr = "contending txns:"
func (ice IndexContentionEvents) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf("tableID=%d indexID=%d\n", ice.TableID, ice.IndexID))
b.WriteString(fmt.Sprintf("%s%s %d\n", singleIndentation, contentionEventsStr, ice.NumContentionEvents))
b.WriteString(fmt.Sprintf("%s%s %s\n", singleIndentation, cumulativeContentionTimeStr, ice.CumulativeContentionTime))
b.WriteString(fmt.Sprintf("%skeys:\n", singleIndentation))
for i := range ice.Events {
b.WriteString(ice.Events[i].String())
}
return b.String()
}
func (skc SingleKeyContention) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf("%s%s %s\n", doubleIndentation, skc.Key, contendingTxnsStr))
for i := range skc.Txns {
b.WriteString(skc.Txns[i].String())
}
return b.String()
}
func toString(stx SingleTxnContention, indentation string) string {
return fmt.Sprintf("%sid=%s count=%d\n", indentation, stx.TxnID, stx.Count)
}
func (stx SingleTxnContention) String() string {
return toString(stx, tripleIndentation)
}
func (skc SingleNonSQLKeyContention) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf("non-SQL key %s %s\n", skc.Key, contendingTxnsStr))
b.WriteString(fmt.Sprintf("%s%s %d\n", singleIndentation, contentionEventsStr, skc.NumContentionEvents))
b.WriteString(fmt.Sprintf("%s%s %s\n", singleIndentation, cumulativeContentionTimeStr, skc.CumulativeContentionTime))
for i := range skc.Txns {
b.WriteString(toString(skc.Txns[i], doubleIndentation))
}
return b.String()
}
// Valid returns if the ResolvedTxnID is valid.
func (r *ResolvedTxnID) Valid() bool {
return !uuid.Nil.Equal(r.TxnID)
}
// Valid returns if the ExtendedContentionEvent is valid.
func (e *ExtendedContentionEvent) Valid() bool {
return e.BlockingEvent.TxnMeta.ID != uuid.UUID{}
}