提交 342fd27e 编写于 作者: martianzhang's avatar martianzhang

update vendor

上级 6734ef20
......@@ -31,7 +31,7 @@ var (
_ DMLNode = &SelectStmt{}
_ DMLNode = &ShowStmt{}
_ DMLNode = &LoadDataStmt{}
_ DMLNode = &SplitIndexRegionStmt{}
_ DMLNode = &SplitRegionStmt{}
_ Node = &Assignment{}
_ Node = &ByItem{}
......@@ -777,6 +777,18 @@ func (n *SelectStmt) Restore(ctx *RestoreCtx) error {
ctx.WritePlain(" ")
}
if n.SelectStmtOpts.SQLSmallResult {
ctx.WriteKeyWord("SQL_SMALL_RESULT ")
}
if n.SelectStmtOpts.SQLBigResult {
ctx.WriteKeyWord("SQL_BIG_RESULT ")
}
if n.SelectStmtOpts.SQLBufferResult {
ctx.WriteKeyWord("SQL_BUFFER_RESULT ")
}
if !n.SelectStmtOpts.SQLCache {
ctx.WriteKeyWord("SQL_NO_CACHE ")
}
......@@ -2404,60 +2416,119 @@ func (n *FrameBound) Accept(v Visitor) (Node, bool) {
return v.Leave(n)
}
type SplitIndexRegionStmt struct {
type SplitRegionStmt struct {
dmlNode
Table *TableName
IndexName string
IndexName model.CIStr
SplitOpt *SplitOption
}
type SplitOption struct {
Lower []ExprNode
Upper []ExprNode
Num int64
ValueLists [][]ExprNode
}
func (n *SplitIndexRegionStmt) Restore(ctx *RestoreCtx) error {
func (n *SplitRegionStmt) Restore(ctx *RestoreCtx) error {
ctx.WriteKeyWord("SPLIT TABLE ")
if err := n.Table.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore SplitIndexRegionStmt.Table")
}
if len(n.IndexName.L) > 0 {
ctx.WriteKeyWord(" INDEX ")
ctx.WriteName(n.IndexName)
ctx.WriteKeyWord(" BY ")
for i, row := range n.ValueLists {
if i != 0 {
ctx.WritePlain(",")
}
ctx.WritePlain("(")
for j, v := range row {
if j != 0 {
ctx.WritePlain(",")
}
if err := v.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while restore SplitIndexRegionStmt.ValueLists[%d][%d]", i, j)
ctx.WriteName(n.IndexName.String())
}
}
ctx.WritePlain(")")
}
return nil
ctx.WritePlain(" ")
err := n.SplitOpt.Restore(ctx)
return err
}
func (n *SplitIndexRegionStmt) Accept(v Visitor) (Node, bool) {
func (n *SplitRegionStmt) Accept(v Visitor) (Node, bool) {
newNode, skipChildren := v.Enter(n)
if skipChildren {
return v.Leave(newNode)
}
n = newNode.(*SplitIndexRegionStmt)
n = newNode.(*SplitRegionStmt)
node, ok := n.Table.Accept(v)
if !ok {
return n, false
}
n.Table = node.(*TableName)
for i, list := range n.ValueLists {
for i, val := range n.SplitOpt.Lower {
node, ok := val.Accept(v)
if !ok {
return n, false
}
n.SplitOpt.Lower[i] = node.(ExprNode)
}
for i, val := range n.SplitOpt.Upper {
node, ok := val.Accept(v)
if !ok {
return n, false
}
n.SplitOpt.Upper[i] = node.(ExprNode)
}
for i, list := range n.SplitOpt.ValueLists {
for j, val := range list {
node, ok := val.Accept(v)
if !ok {
return n, false
}
n.ValueLists[i][j] = node.(ExprNode)
n.SplitOpt.ValueLists[i][j] = node.(ExprNode)
}
}
return v.Leave(n)
}
func (n *SplitOption) Restore(ctx *RestoreCtx) error {
if len(n.ValueLists) == 0 {
ctx.WriteKeyWord("BETWEEN ")
ctx.WritePlain("(")
for j, v := range n.Lower {
if j != 0 {
ctx.WritePlain(",")
}
if err := v.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while restore SplitOption Lower")
}
}
ctx.WritePlain(")")
ctx.WriteKeyWord(" AND ")
ctx.WritePlain("(")
for j, v := range n.Upper {
if j != 0 {
ctx.WritePlain(",")
}
if err := v.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while restore SplitOption Upper")
}
}
ctx.WritePlain(")")
ctx.WriteKeyWord(" REGIONS")
ctx.WritePlainf(" %d", n.Num)
return nil
}
ctx.WriteKeyWord("BY ")
for i, row := range n.ValueLists {
if i != 0 {
ctx.WritePlain(",")
}
ctx.WritePlain("(")
for j, v := range row {
if j != 0 {
ctx.WritePlain(",")
}
if err := v.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while restore SplitOption.ValueLists[%d][%d]", i, j)
}
}
ctx.WritePlain(")")
}
return nil
}
......@@ -1379,6 +1379,7 @@ const (
AdminChecksumTable
AdminShowSlow
AdminShowNextRowID
AdminReloadExprPushdownBlacklist
)
// HandleRange represents a range where handle value >= Begin and < End.
......@@ -1547,6 +1548,8 @@ func (n *AdminStmt) Restore(ctx *RestoreCtx) error {
if err := n.ShowSlow.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore AdminStmt.ShowSlow")
}
case AdminReloadExprPushdownBlacklist:
ctx.WriteKeyWord("RELOAD EXPR_PUSHDOWN_BLACKLIST")
default:
return errors.New("Unsupported AdminStmt type")
}
......@@ -1975,7 +1978,10 @@ func (i Ident) String() string {
// SelectStmtOpts wrap around select hints and switches
type SelectStmtOpts struct {
Distinct bool
SQLBigResult bool
SQLBufferResult bool
SQLCache bool
SQLSmallResult bool
CalcFoundRows bool
StraightJoin bool
Priority mysql.PriorityEnum
......
......@@ -58,6 +58,7 @@ type Scanner struct {
}
type specialCommentScanner interface {
stmtTexter
scan() (tok int, pos Pos, lit string)
}
......@@ -85,11 +86,18 @@ func (s *optimizerHintScanner) scan() (tok int, pos Pos, lit string) {
pos.Line += s.Pos.Line
pos.Col += s.Pos.Col
pos.Offset += s.Pos.Offset
if tok == 0 {
switch tok {
case 0:
if !s.end {
tok = hintEnd
s.end = true
}
case invalid:
// an optimizer hint is allowed to contain invalid characters, the
// remaining hints are just ignored.
// force advance the lexer even when encountering an invalid character
// to prevent infinite parser loop. (see issue #336)
s.r.inc()
}
return
}
......@@ -110,6 +118,10 @@ func (s *Scanner) reset(sql string) {
}
func (s *Scanner) stmtText() string {
if s.specialComment != nil {
return s.specialComment.stmtText()
}
endPos := s.r.pos().Offset
if s.r.s[endPos-1] == '\n' {
endPos = endPos - 1 // trim new line
......@@ -220,6 +232,15 @@ func (s *Scanner) EnableWindowFunc(val bool) {
s.supportWindowFunc = val
}
// InheritScanner returns a new scanner object which inherits configurations from the parent scanner.
func (s *Scanner) InheritScanner(sql string) *Scanner {
return &Scanner{
r: reader{s: sql},
sqlMode: s.sqlMode,
supportWindowFunc: s.supportWindowFunc,
}
}
// NewScanner returns a new scanner object.
func NewScanner(s string) *Scanner {
return &Scanner{r: reader{s: s}}
......@@ -396,7 +417,7 @@ func startWithSlash(s *Scanner) (tok int, pos Pos, lit string) {
end := len(comment) - 2
sql := comment[begin:end]
s.specialComment = &optimizerHintScanner{
Scanner: NewScanner(sql),
Scanner: s.InheritScanner(sql),
Pos: Pos{
pos.Line,
pos.Col,
......@@ -413,7 +434,7 @@ func startWithSlash(s *Scanner) (tok int, pos Pos, lit string) {
if strings.HasPrefix(comment, "/*!") {
sql := specCodePattern.ReplaceAllStringFunc(comment, TrimComment)
s.specialComment = &mysqlSpecificCodeScanner{
Scanner: NewScanner(sql),
Scanner: s.InheritScanner(sql),
Pos: Pos{
pos.Line,
pos.Col,
......
......@@ -234,6 +234,7 @@ var tokenMap = map[string]int{
"DELETE": deleteKwd,
"DESC": desc,
"DESCRIBE": describe,
"DIRECTORY": directory,
"DISABLE": disable,
"DISTINCT": distinct,
"DISTINCTROW": distinct,
......@@ -289,6 +290,7 @@ var tokenMap = map[string]int{
"HASH": hash,
"HAVING": having,
"HIGH_PRIORITY": highPriority,
"HISTORY": history,
"HOUR": hour,
"HOUR_MICROSECOND": hourMicrosecond,
"HOUR_MINUTE": hourMinute,
......@@ -338,6 +340,7 @@ var tokenMap = map[string]int{
"LIMIT": limit,
"LINES": lines,
"LINEAR": linear,
"LIST": list,
"LOAD": load,
"LOCAL": local,
"LOCALTIME": localTime,
......@@ -380,6 +383,7 @@ var tokenMap = map[string]int{
"NO_WRITE_TO_BINLOG": noWriteToBinLog,
"NODE_ID": nodeID,
"NODE_STATE": nodeState,
"NODEGROUP": nodegroup,
"NONE": none,
"NOT": not,
"NOW": now,
......@@ -429,6 +433,7 @@ var tokenMap = map[string]int{
"REDUNDANT": redundant,
"REFERENCES": references,
"REGEXP": regexpKwd,
"REGIONS": regions,
"RELOAD": reload,
"RENAME": rename,
"REPEAT": repeat,
......@@ -469,9 +474,12 @@ var tokenMap = map[string]int{
"SOME": some,
"SPLIT": split,
"SQL": sql,
"SQL_BIG_RESULT": sqlBigResult,
"SQL_BUFFER_RESULT": sqlBufferResult,
"SQL_CACHE": sqlCache,
"SQL_CALC_FOUND_ROWS": sqlCalcFoundRows,
"SQL_NO_CACHE": sqlNoCache,
"SQL_SMALL_RESULT": sqlSmallResult,
"SOURCE": source,
"SSL": ssl,
"START": start,
......@@ -485,6 +493,7 @@ var tokenMap = map[string]int{
"STATUS": status,
"SWAPS": swaps,
"SWITCHES": switchesSym,
"SYSTEM_TIME": systemTime,
"OPEN": open,
"STD": stddevPop,
"STDDEV": stddevPop,
......@@ -579,6 +588,7 @@ var tokenMap = map[string]int{
"ZEROFILL": zerofill,
"BINDING": binding,
"BINDINGS": bindings,
"EXPR_PUSHDOWN_BLACKLIST": exprPushdownBlacklist,
}
// See https://dev.mysql.com/doc/refman/5.7/en/function-resolution.html for details
......
......@@ -56,6 +56,8 @@ const (
ActionDropView ActionType = 24
ActionRecoverTable ActionType = 25
ActionModifySchemaCharsetAndCollate ActionType = 26
ActionLockTable ActionType = 27
ActionUnlockTable ActionType = 28
)
// AddIndexStr is a string related to the operation of "add index".
......@@ -88,6 +90,8 @@ var actionMap = map[ActionType]string{
ActionDropView: "drop view",
ActionRecoverTable: "recover table",
ActionModifySchemaCharsetAndCollate: "modify schema charset and collate",
ActionLockTable: "lock table",
ActionUnlockTable: "unlock table",
}
// String return current ddl action in string
......
......@@ -40,4 +40,6 @@ const (
FlagIgnoreZeroInDate = 1 << 7
// FlagDividedByZeroAsWarning indicates if DividedByZero should be returned as warning.
FlagDividedByZeroAsWarning = 1 << 8
// FlagInUnionStmt indicates if this is a UNION statement.
FlagInUnionStmt = 1 << 9
)
......@@ -15,6 +15,7 @@ package model
import (
"encoding/json"
"strconv"
"strings"
"time"
......@@ -230,11 +231,98 @@ type TableInfo struct {
Compression string `json:"compression"`
View *ViewInfo `json:"view"`
// Lock represent the table lock info.
Lock *TableLockInfo `json:"Lock"`
// Version means the version of the table info.
Version uint16 `json:"version"`
}
// TableLockInfo provides meta data describing a table lock.
type TableLockInfo struct {
Tp TableLockType
// Use array because there may be multiple sessions holding the same read lock.
Sessions []SessionInfo
State TableLockState
// TS is used to record the timestamp this table lock been locked.
TS uint64
}
// SessionInfo contain the session ID and the server ID.
type SessionInfo struct {
ServerID string
SessionID uint64
}
func (s SessionInfo) String() string {
return "server: " + s.ServerID + "_session: " + strconv.FormatUint(s.SessionID, 10)
}
// TableLockTpInfo is composed by schema ID, table ID and table lock type.
type TableLockTpInfo struct {
SchemaID int64
TableID int64
Tp TableLockType
}
// TableLockState is the state for table lock.
type TableLockState byte
const (
// TableLockStateNone means this table lock is absent.
TableLockStateNone TableLockState = iota
// TableLockStatePreLock means this table lock is pre-lock state. Other session doesn't hold this lock should't do corresponding operation according to the lock type.
TableLockStatePreLock
// TableLockStatePublic means this table lock is public state.
TableLockStatePublic
)
// String implements fmt.Stringer interface.
func (t TableLockState) String() string {
switch t {
case TableLockStatePreLock:
return "pre-lock"
case TableLockStatePublic:
return "public"
default:
return "none"
}
}
// TableLockType is the type of the table lock.
type TableLockType byte
const (
TableLockNone TableLockType = iota
// TableLockRead means the session with this lock can read the table (but not write it).
// Multiple sessions can acquire a READ lock for the table at the same time.
// Other sessions can read the table without explicitly acquiring a READ lock.
TableLockRead
// TableLockReadLocal is not supported.
TableLockReadLocal
// TableLockWrite means only the session with this lock has write/read permission.
// Only the session that holds the lock can access the table. No other session can access it until the lock is released.
TableLockWrite
// TableLockWriteLocal means the session with this lock has write/read permission, and the other session still has read permission.
TableLockWriteLocal
)
func (t TableLockType) String() string {
switch t {
case TableLockNone:
return "NONE"
case TableLockRead:
return "READ"
case TableLockReadLocal:
return "READ LOCAL"
case TableLockWriteLocal:
return "WRITE LOCAL"
case TableLockWrite:
return "WRITE"
}
return ""
}
// GetPartitionInfo returns the partition information.
func (t *TableInfo) GetPartitionInfo() *PartitionInfo {
if t.Partition != nil && t.Partition.Enable {
......@@ -345,6 +433,11 @@ func (t *TableInfo) FindIndexByName(idxName string) *IndexInfo {
return nil
}
// IsLocked checks whether the table was locked.
func (t *TableInfo) IsLocked() bool {
return t.Lock != nil && len(t.Lock.Sessions) > 0
}
// NewExtraHandleColInfo mocks a column info for extra handle column.
func NewExtraHandleColInfo() *ColumnInfo {
colInfo := &ColumnInfo{
......@@ -453,8 +546,10 @@ type PartitionType int
// Partition types.
const (
PartitionTypeRange PartitionType = 1
PartitionTypeHash PartitionType = 2
PartitionTypeList PartitionType = 3
PartitionTypeHash = 2
PartitionTypeList = 3
PartitionTypeKey = 4
PartitionTypeSystemTime = 5
)
func (p PartitionType) String() string {
......@@ -465,6 +560,10 @@ func (p PartitionType) String() string {
return "HASH"
case PartitionTypeList:
return "LIST"
case PartitionTypeKey:
return "KEY"
case PartitionTypeSystemTime:
return "SYSTEM_TIME"
default:
return ""
}
......
......@@ -882,6 +882,7 @@ const (
ErrMustChangePasswordLogin = 1862
ErrRowInWrongPartition = 1863
ErrErrorLast = 1863
ErrMaxExecTimeExceeded = 1907
ErrInvalidJSONData = 3069
ErrGeneratedColumnFunctionIsNotAllowed = 3102
ErrBadGeneratedColumn = 3105
......@@ -895,6 +896,7 @@ const (
ErrInvalidJSONPathWildcard = 3149
ErrInvalidJSONContainsPathType = 3150
ErrJSONUsedAsKey = 3152
ErrInvalidJSONPathArrayCell = 3165
ErrBadUser = 3162
ErrRoleNotGranted = 3530
ErrWindowNoSuchWindow = 3579
......@@ -919,6 +921,11 @@ const (
ErrWindowExplainJson = 3598
ErrWindowFunctionIgnoresFrame = 3599
// MariaDB errors.
ErrOnlyOneDefaultPartionAllowed = 4030
ErrWrongPartitionTypeExpectedSystemTime = 4113
ErrSystemVersioningWrongPartitions = 4128
// TiDB self-defined errors.
ErrMemExceedThreshold = 8001
ErrForUpdateCantRetry = 8002
......@@ -934,6 +941,7 @@ const (
ErrRequireVersionCheckFail = 8107
ErrUnsupportedReloadPlugin = 8018
ErrUnsupportedReloadPluginVar = 8019
ErrTableLocked = 8020
// TiKV/PD errors.
ErrPDServerTimeout = 9001
......
......@@ -892,6 +892,7 @@ var MySQLErrName = map[uint16]string{
ErrInvalidJSONPathWildcard: "In this situation, path expressions may not contain the * and ** tokens.",
ErrInvalidJSONContainsPathType: "The second argument can only be either 'one' or 'all'.",
ErrJSONUsedAsKey: "JSON column '%-.192s' cannot be used in key specification.",
ErrInvalidJSONPathArrayCell: "A path expression is not a path to a cell in an array.",
ErrWindowNoSuchWindow: "Window name '%s' is not defined.",
ErrWindowCircularityInWindowGraph: "There is a circularity in the window dependency graph.",
ErrWindowNoChildPartitioning: "A window which depends on another cannot define partitioning.",
......@@ -914,6 +915,12 @@ var MySQLErrName = map[uint16]string{
ErrWindowExplainJson: "To get information about window functions use EXPLAIN FORMAT=JSON",
ErrWindowFunctionIgnoresFrame: "Window function '%s' ignores the frame clause of window '%s' and aggregates over the whole partition",
ErrRoleNotGranted: "%s is is not granted to %s",
ErrMaxExecTimeExceeded: "Query execution was interrupted, max_execution_time exceeded.",
// MariaDB errors.
ErrOnlyOneDefaultPartionAllowed: "Only one DEFAULT partition allowed",
ErrWrongPartitionTypeExpectedSystemTime: "Wrong partitioning type, expected type: `SYSTEM_TIME`",
ErrSystemVersioningWrongPartitions: "Wrong Partitions: must have at least one HISTORY and exactly one last CURRENT",
// TiDB errors.
ErrMemExceedThreshold: "%s holds %dB memory, exceeds threshold %dB.%s",
......@@ -930,6 +937,7 @@ var MySQLErrName = map[uint16]string{
ErrRequireVersionCheckFail: "Plugin %s require %s be %v but got %v",
ErrUnsupportedReloadPlugin: "Plugin %s isn't loaded so cannot be reloaded",
ErrUnsupportedReloadPluginVar: "Reload plugin with different sysVar is unsupported %v",
ErrTableLocked: "Table '%s' was locked in %s by %v",
// TiKV/PD errors.
ErrPDServerTimeout: "PD server timeout",
......
......@@ -148,6 +148,11 @@ func (ec ErrClass) New(code ErrCode, message string) *Error {
}
}
// NewStd calls New using the standard message for the error code
func (ec ErrClass) NewStd(code ErrCode) *Error {
return ec.New(code, mysql.MySQLErrName[uint16(code)])
}
// Error implements error interface and adds integer Class and Code, so
// errors with different message can be compared.
type Error struct {
......
......@@ -201,8 +201,13 @@ func (ft *FieldType) String() string {
func (ft *FieldType) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord(TypeToStr(ft.Tp, ft.Charset))
precision := ft.Flen
scale := ft.Decimal
switch ft.Tp {
case mysql.TypeEnum, mysql.TypeSet:
precision = UnspecifiedLength
scale = UnspecifiedLength
ctx.WritePlain("(")
for i, e := range ft.Elems {
if i != 0 {
......@@ -212,21 +217,17 @@ func (ft *FieldType) Restore(ctx *format.RestoreCtx) error {
}
ctx.WritePlain(")")
case mysql.TypeTimestamp, mysql.TypeDatetime, mysql.TypeDuration:
if ft.Flen > 0 && ft.Decimal > 0 {
ctx.WritePlainf("(%d)", ft.Decimal)
precision = ft.Decimal
scale = UnspecifiedLength
}
case mysql.TypeDouble, mysql.TypeFloat:
if ft.Flen > 0 && ft.Decimal > 0 {
ctx.WritePlainf("(%d,%d)", ft.Flen, ft.Decimal)
}
case mysql.TypeNewDecimal:
if ft.Flen > 0 && ft.Decimal > 0 {
ctx.WritePlainf("(%d,%d)", ft.Flen, ft.Decimal)
}
case mysql.TypeBit, mysql.TypeShort, mysql.TypeTiny, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong, mysql.TypeVarchar, mysql.TypeString, mysql.TypeVarString, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeBlob, mysql.TypeLongBlob, mysql.TypeYear:
if ft.Flen > 0 {
ctx.WritePlainf("(%d)", ft.Flen)
if precision != UnspecifiedLength {
ctx.WritePlainf("(%d", precision)
if scale != UnspecifiedLength {
ctx.WritePlainf(",%d", scale)
}
ctx.WritePlain(")")
}
if mysql.HasUnsignedFlag(ft.Flag) {
......
......@@ -24,6 +24,7 @@ import (
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/util/execdetails"
"github.com/pingcap/tidb/util/memory"
"go.uber.org/zap"
)
const (
......@@ -54,6 +55,7 @@ type StatementContext struct {
InDeleteStmt bool
InSelectStmt bool
InLoadDataStmt bool
InExplainStmt bool
IgnoreTruncate bool
IgnoreZeroInDate bool
DupKeyAsWarning bool
......@@ -486,3 +488,21 @@ type CopTasksDetails struct {
MaxWaitAddress string
MaxWaitTime time.Duration
}
// ToZapFields wraps the CopTasksDetails as zap.Fileds.
func (d *CopTasksDetails) ToZapFields() (fields []zap.Field) {
if d.NumCopTasks == 0 {
return
}
fields = make([]zap.Field, 0, 10)
fields = append(fields, zap.Int("num_cop_tasks", d.NumCopTasks))
fields = append(fields, zap.String("process_avg_time", strconv.FormatFloat(d.AvgProcessTime.Seconds(), 'f', -1, 64)+"s"))
fields = append(fields, zap.String("process_p90_time", strconv.FormatFloat(d.P90ProcessTime.Seconds(), 'f', -1, 64)+"s"))
fields = append(fields, zap.String("process_max_time", strconv.FormatFloat(d.MaxProcessTime.Seconds(), 'f', -1, 64)+"s"))
fields = append(fields, zap.String("process_max_addr", d.MaxProcessAddress))
fields = append(fields, zap.String("wait_avg_time", strconv.FormatFloat(d.AvgWaitTime.Seconds(), 'f', -1, 64)+"s"))
fields = append(fields, zap.String("wait_p90_time", strconv.FormatFloat(d.P90WaitTime.Seconds(), 'f', -1, 64)+"s"))
fields = append(fields, zap.String("wait_max_time", strconv.FormatFloat(d.MaxWaitTime.Seconds(), 'f', -1, 64)+"s"))
fields = append(fields, zap.String("wait_max_addr", d.MaxWaitAddress))
return fields
}
......@@ -392,7 +392,12 @@ func ParseBinaryFromString(s string) (bj BinaryJSON, err error) {
err = ErrInvalidJSONText.GenWithStackByArgs("The document is empty")
return
}
if err = bj.UnmarshalJSON(hack.Slice(s)); err != nil {
data := hack.Slice(s)
if !json.Valid(data) {
err = ErrInvalidJSONText.GenWithStackByArgs("The document root must not be followed by other values.")
return
}
if err = bj.UnmarshalJSON(data); err != nil {
err = ErrInvalidJSONText.GenWithStackByArgs(err)
}
return
......
......@@ -23,6 +23,7 @@ import (
"time"
"github.com/pingcap/tipb/go-tipb"
"go.uber.org/zap"
)
// CommitDetailCtxKey presents CommitDetail info key in context.
......@@ -128,6 +129,65 @@ func (d ExecDetails) String() string {
return strings.Join(parts, " ")
}
// ToZapFields wraps the ExecDetails as zap.Fields.
func (d ExecDetails) ToZapFields() (fields []zap.Field) {
fields = make([]zap.Field, 0, 16)
if d.ProcessTime > 0 {
fields = append(fields, zap.String(strings.ToLower(ProcessTimeStr), strconv.FormatFloat(d.ProcessTime.Seconds(), 'f', -1, 64)+"s"))
}
if d.WaitTime > 0 {
fields = append(fields, zap.String(strings.ToLower(WaitTimeStr), strconv.FormatFloat(d.ProcessTime.Seconds(), 'f', -1, 64)+"s"))
}
if d.BackoffTime > 0 {
fields = append(fields, zap.String(strings.ToLower(BackoffTimeStr), strconv.FormatFloat(d.BackoffTime.Seconds(), 'f', -1, 64)+"s"))
}
if d.RequestCount > 0 {
fields = append(fields, zap.String(strings.ToLower(RequestCountStr), strconv.FormatInt(int64(d.RequestCount), 10)))
}
if d.TotalKeys > 0 {
fields = append(fields, zap.String(strings.ToLower(TotalKeysStr), strconv.FormatInt(d.TotalKeys, 10)))
}
if d.ProcessedKeys > 0 {
fields = append(fields, zap.String(strings.ToLower(ProcessKeysStr), strconv.FormatInt(d.ProcessedKeys, 10)))
}
commitDetails := d.CommitDetail
if commitDetails != nil {
if commitDetails.PrewriteTime > 0 {
fields = append(fields, zap.String("prewrite_time", fmt.Sprintf("%v", strconv.FormatFloat(commitDetails.PrewriteTime.Seconds(), 'f', -1, 64)+"s")))
}
if commitDetails.CommitTime > 0 {
fields = append(fields, zap.String("commit_time", fmt.Sprintf("%v", strconv.FormatFloat(commitDetails.CommitTime.Seconds(), 'f', -1, 64)+"s")))
}
if commitDetails.GetCommitTsTime > 0 {
fields = append(fields, zap.String("get_commit_ts_time", fmt.Sprintf("%v", strconv.FormatFloat(commitDetails.GetCommitTsTime.Seconds(), 'f', -1, 64)+"s")))
}
if commitDetails.TotalBackoffTime > 0 {
fields = append(fields, zap.String("total_backoff_time", fmt.Sprintf("%v", strconv.FormatFloat(commitDetails.TotalBackoffTime.Seconds(), 'f', -1, 64)+"s")))
}
resolveLockTime := atomic.LoadInt64(&commitDetails.ResolveLockTime)
if resolveLockTime > 0 {
fields = append(fields, zap.String("resolve_lock_time", fmt.Sprintf("%v", strconv.FormatFloat(time.Duration(resolveLockTime).Seconds(), 'f', -1, 64)+"s")))
}
if commitDetails.LocalLatchTime > 0 {
fields = append(fields, zap.String("local_latch_wait_time", fmt.Sprintf("%v", strconv.FormatFloat(commitDetails.LocalLatchTime.Seconds(), 'f', -1, 64)+"s")))
}
if commitDetails.WriteKeys > 0 {
fields = append(fields, zap.Int("write_keys", commitDetails.WriteKeys))
}
if commitDetails.WriteSize > 0 {
fields = append(fields, zap.Int("write_size", commitDetails.WriteSize))
}
prewriteRegionNum := atomic.LoadInt32(&commitDetails.PrewriteRegionNum)
if prewriteRegionNum > 0 {
fields = append(fields, zap.Int32("prewrite_region", prewriteRegionNum))
}
if commitDetails.TxnRetry > 0 {
fields = append(fields, zap.Int("txn_retry", commitDetails.TxnRetry))
}
}
return fields
}
// CopRuntimeStats collects cop tasks' execution info.
type CopRuntimeStats struct {
sync.Mutex
......@@ -257,8 +317,5 @@ func (e *RuntimeStats) SetRowNum(rowNum int64) {
}
func (e *RuntimeStats) String() string {
if e == nil {
return ""
}
return fmt.Sprintf("time:%v, loops:%d, rows:%d", time.Duration(e.consume), e.loop, e.rows)
}
......@@ -131,30 +131,9 @@ func stringToLogLevel(level string) log.Level {
return defaultLogLevel
}
// logTypeToColor converts the Level to a color string.
func logTypeToColor(level log.Level) string {
switch level {
case log.DebugLevel:
return "[0;37"
case log.InfoLevel:
return "[0;36"
case log.WarnLevel:
return "[0;33"
case log.ErrorLevel:
return "[0;31"
case log.FatalLevel:
return "[0;31"
case log.PanicLevel:
return "[0;31"
}
return "[0;37"
}
// textFormatter is for compatibility with ngaut/log
type textFormatter struct {
DisableTimestamp bool
EnableColors bool
EnableEntryOrder bool
}
......@@ -167,11 +146,6 @@ func (f *textFormatter) Format(entry *log.Entry) ([]byte, error) {
b = &bytes.Buffer{}
}
if f.EnableColors {
colorStr := logTypeToColor(entry.Level)
fmt.Fprintf(b, "\033%sm ", colorStr)
}
if !f.DisableTimestamp {
fmt.Fprintf(b, "%s ", entry.Time.Format(defaultLogTimeFormat))
}
......@@ -201,9 +175,6 @@ func (f *textFormatter) Format(entry *log.Entry) ([]byte, error) {
b.WriteByte('\n')
if f.EnableColors {
b.WriteString("\033[0m")
}
return b.Bytes(), nil
}
......@@ -235,22 +206,6 @@ func stringToLogFormatter(format string, disableTimestamp bool) log.Formatter {
return &textFormatter{
DisableTimestamp: disableTimestamp,
}
case "json":
return &log.JSONFormatter{
TimestampFormat: defaultLogTimeFormat,
DisableTimestamp: disableTimestamp,
}
case "console":
return &log.TextFormatter{
FullTimestamp: true,
TimestampFormat: defaultLogTimeFormat,
DisableTimestamp: disableTimestamp,
}
case "highlight":
return &textFormatter{
DisableTimestamp: disableTimestamp,
EnableColors: true,
}
default:
return &textFormatter{}
}
......
......@@ -45,6 +45,7 @@ func (a *LogOnExceed) Action(t *Tracker) {
a.acted = true
logutil.Logger(context.Background()).Warn("memory exceeds quota",
zap.Error(errMemExceedThreshold.GenWithStackByArgs(t.label, t.BytesConsumed(), t.bytesLimit, t.String())))
return
}
}
......
......@@ -182,9 +182,9 @@ func (t *Tracker) String() string {
func (t *Tracker) toString(indent string, buffer *bytes.Buffer) {
fmt.Fprintf(buffer, "%s\"%s\"{\n", indent, t.label)
if t.bytesLimit > 0 {
fmt.Fprintf(buffer, "%s \"quota\": %s\n", indent, t.bytesToString(t.bytesLimit))
fmt.Fprintf(buffer, "%s \"quota\": %s\n", indent, t.BytesToString(t.bytesLimit))
}
fmt.Fprintf(buffer, "%s \"consumed\": %s\n", indent, t.bytesToString(t.BytesConsumed()))
fmt.Fprintf(buffer, "%s \"consumed\": %s\n", indent, t.BytesToString(t.BytesConsumed()))
t.mu.Lock()
for i := range t.mu.children {
......@@ -196,7 +196,8 @@ func (t *Tracker) toString(indent string, buffer *bytes.Buffer) {
buffer.WriteString(indent + "}\n")
}
func (t *Tracker) bytesToString(numBytes int64) string {
// BytesToString converts the memory consumption to a readable string.
func (t *Tracker) BytesToString(numBytes int64) string {
GB := float64(numBytes) / float64(1<<30)
if GB > 1 {
return fmt.Sprintf("%v GB", GB)
......
......@@ -117,118 +117,118 @@
"revisionTime": "2019-03-07T07:54:52Z"
},
{
"checksumSHA1": "IB9wW2GmSlnLVDRkaUXcF3CJ15g=",
"checksumSHA1": "gkdPCV8bVezIdBd/w2RiZf7eXTU=",
"path": "github.com/pingcap/parser",
"revision": "89ae120307cc42a1cccc4daba2c589966db77055",
"revisionTime": "2019-05-23T11:32:41Z"
"revision": "3b36f86d9b7bba02fef99748e3a98069708a64f3",
"revisionTime": "2019-06-12T05:27:18Z"
},
{
"checksumSHA1": "qeft79GIpt7bP++Qlg1UNSdXL3E=",
"checksumSHA1": "/HUw+IEQjCkicSG7qSMWqRlmvz0=",
"path": "github.com/pingcap/parser/ast",
"revision": "89ae120307cc42a1cccc4daba2c589966db77055",
"revisionTime": "2019-05-23T11:32:41Z"
"revision": "3b36f86d9b7bba02fef99748e3a98069708a64f3",
"revisionTime": "2019-06-12T05:27:18Z"
},
{
"checksumSHA1": "xiv40YqnvHcbIhaEzJqjh5K7ehM=",
"path": "github.com/pingcap/parser/auth",
"revision": "89ae120307cc42a1cccc4daba2c589966db77055",
"revisionTime": "2019-05-23T11:32:41Z"
"revision": "3b36f86d9b7bba02fef99748e3a98069708a64f3",
"revisionTime": "2019-06-12T05:27:18Z"
},
{
"checksumSHA1": "EvDXpplklIXmKqLclzWzaN/uHKQ=",
"path": "github.com/pingcap/parser/charset",
"revision": "89ae120307cc42a1cccc4daba2c589966db77055",
"revisionTime": "2019-05-23T11:32:41Z"
"revision": "3b36f86d9b7bba02fef99748e3a98069708a64f3",
"revisionTime": "2019-06-12T05:27:18Z"
},
{
"checksumSHA1": "Aao6Mul/qqogOwPwM2arBKZkYZs=",
"path": "github.com/pingcap/parser/format",
"revision": "89ae120307cc42a1cccc4daba2c589966db77055",
"revisionTime": "2019-05-23T11:32:41Z"
"revision": "3b36f86d9b7bba02fef99748e3a98069708a64f3",
"revisionTime": "2019-06-12T05:27:18Z"
},
{
"checksumSHA1": "YN9BYMOMxEXjrUCPPYQREN90BC0=",
"checksumSHA1": "CvZtQeDgNfQUrGDi5mrv5osJ5F0=",
"path": "github.com/pingcap/parser/model",
"revision": "89ae120307cc42a1cccc4daba2c589966db77055",
"revisionTime": "2019-05-23T11:32:41Z"
"revision": "3b36f86d9b7bba02fef99748e3a98069708a64f3",
"revisionTime": "2019-06-12T05:27:18Z"
},
{
"checksumSHA1": "/qaOJqnSLO0dZbyQDnq75wUPiLo=",
"checksumSHA1": "02F5sAuKee53HMwsu6fx+iw5cnM=",
"path": "github.com/pingcap/parser/mysql",
"revision": "89ae120307cc42a1cccc4daba2c589966db77055",
"revisionTime": "2019-05-23T11:32:41Z"
"revision": "3b36f86d9b7bba02fef99748e3a98069708a64f3",
"revisionTime": "2019-06-12T05:27:18Z"
},
{
"checksumSHA1": "olapD16WCMBU9vrA5PtlERGFfXw=",
"path": "github.com/pingcap/parser/opcode",
"revision": "89ae120307cc42a1cccc4daba2c589966db77055",
"revisionTime": "2019-05-23T11:32:41Z"
"revision": "3b36f86d9b7bba02fef99748e3a98069708a64f3",
"revisionTime": "2019-06-12T05:27:18Z"
},
{
"checksumSHA1": "kNunWp0HfikkRiZlOzfD1bvHruM=",
"checksumSHA1": "L6rzy3sJU1RPf7AkJN+0zcwW/YY=",
"path": "github.com/pingcap/parser/terror",
"revision": "89ae120307cc42a1cccc4daba2c589966db77055",
"revisionTime": "2019-05-23T11:32:41Z"
"revision": "3b36f86d9b7bba02fef99748e3a98069708a64f3",
"revisionTime": "2019-06-12T05:27:18Z"
},
{
"checksumSHA1": "abJKAbu4Cro4oJZ2IeI+n+0R87A=",
"checksumSHA1": "EWbRvJs3Y1KLBaHnwaCHps3t0+4=",
"path": "github.com/pingcap/parser/types",
"revision": "89ae120307cc42a1cccc4daba2c589966db77055",
"revisionTime": "2019-05-23T11:32:41Z"
"revision": "3b36f86d9b7bba02fef99748e3a98069708a64f3",
"revisionTime": "2019-06-12T05:27:18Z"
},
{
"checksumSHA1": "t0O+34iPgOlRt020Cn36smUWhwQ=",
"checksumSHA1": "irgF5OsNQZiD589px9hV3scdp8U=",
"path": "github.com/pingcap/tidb/sessionctx/stmtctx",
"revision": "cc74145ffa9e48edcae0fb394618ada43b2776c0",
"revisionTime": "2019-05-24T06:40:04Z"
"revision": "7d27fa63d349b9d266682a3fff6e732c156cf1db",
"revisionTime": "2019-06-12T12:43:29Z"
},
{
"checksumSHA1": "1INT6BSMg5WA9x4ftRegJBhDJQg=",
"path": "github.com/pingcap/tidb/types",
"revision": "cc74145ffa9e48edcae0fb394618ada43b2776c0",
"revisionTime": "2019-05-24T06:40:04Z"
"revision": "7d27fa63d349b9d266682a3fff6e732c156cf1db",
"revisionTime": "2019-06-12T12:43:29Z"
},
{
"checksumSHA1": "PwXMuapqcWj1+hMEcRIJhLJ3NsY=",
"checksumSHA1": "HYVqavXulc59n0RyI/D1jZVKon4=",
"path": "github.com/pingcap/tidb/types/json",
"revision": "cc74145ffa9e48edcae0fb394618ada43b2776c0",
"revisionTime": "2019-05-24T06:40:04Z"
"revision": "7d27fa63d349b9d266682a3fff6e732c156cf1db",
"revisionTime": "2019-06-12T12:43:29Z"
},
{
"checksumSHA1": "45zWX5Q6D6aTEWtc4p/lbD9WD4o=",
"path": "github.com/pingcap/tidb/types/parser_driver",
"revision": "cc74145ffa9e48edcae0fb394618ada43b2776c0",
"revisionTime": "2019-05-24T06:40:04Z"
"revision": "7d27fa63d349b9d266682a3fff6e732c156cf1db",
"revisionTime": "2019-06-12T12:43:29Z"
},
{
"checksumSHA1": "za/7NvrgGTXpUf/A4/MCtgeNp+Y=",
"checksumSHA1": "dI3bZpUsujM1shEDvORNQj5FCN0=",
"path": "github.com/pingcap/tidb/util/execdetails",
"revision": "cc74145ffa9e48edcae0fb394618ada43b2776c0",
"revisionTime": "2019-05-24T06:40:04Z"
"revision": "7d27fa63d349b9d266682a3fff6e732c156cf1db",
"revisionTime": "2019-06-12T12:43:29Z"
},
{
"checksumSHA1": "RdbHgQWMHjRtKjqPcTX81k1V3sw=",
"path": "github.com/pingcap/tidb/util/hack",
"revision": "cc74145ffa9e48edcae0fb394618ada43b2776c0",
"revisionTime": "2019-05-24T06:40:04Z"
"revision": "7d27fa63d349b9d266682a3fff6e732c156cf1db",
"revisionTime": "2019-06-12T12:43:29Z"
},
{
"checksumSHA1": "JYbZwZe2uuqKVVV40ZU4G9zGEBE=",
"checksumSHA1": "16Cv4I5dFUSCuz0AufzUilN4IOI=",
"path": "github.com/pingcap/tidb/util/logutil",
"revision": "cc74145ffa9e48edcae0fb394618ada43b2776c0",
"revisionTime": "2019-05-24T06:40:04Z"
"revision": "7d27fa63d349b9d266682a3fff6e732c156cf1db",
"revisionTime": "2019-06-12T12:43:29Z"
},
{
"checksumSHA1": "OveQu0ABBJmMEwmmthqSRQC2Ef0=",
"path": "github.com/pingcap/tidb/util/math",
"revision": "cc74145ffa9e48edcae0fb394618ada43b2776c0",
"revisionTime": "2019-05-24T06:40:04Z"
"revision": "7d27fa63d349b9d266682a3fff6e732c156cf1db",
"revisionTime": "2019-06-12T12:43:29Z"
},
{
"checksumSHA1": "9q+/RZZoN4cq/FbCUCD0uVAyqeU=",
"checksumSHA1": "EoqVTAze03xNtGcKbsZT4eYx9bI=",
"path": "github.com/pingcap/tidb/util/memory",
"revision": "cc74145ffa9e48edcae0fb394618ada43b2776c0",
"revisionTime": "2019-05-24T06:40:04Z"
"revision": "7d27fa63d349b9d266682a3fff6e732c156cf1db",
"revisionTime": "2019-06-12T12:43:29Z"
},
{
"checksumSHA1": "QPIBwDNUFF5Whrnd41S3mkKa4gQ=",
......@@ -485,62 +485,68 @@
{
"checksumSHA1": "aKn1oKcY74N8TRLm3Ayt7Q4bbI4=",
"path": "vitess.io/vitess/go/bytes2",
"revision": "eb2d057927b37c5a6f144ab5baa762881cffae8d",
"revisionTime": "2019-05-23T12:28:24Z"
"revision": "22dbada8b16e2c969dd60c77f4e6a346c70d5952",
"revisionTime": "2019-06-11T03:26:25Z"
},
{
"checksumSHA1": "bhE6CGQgZTIgLPp9lnvlKW/47xc=",
"path": "vitess.io/vitess/go/hack",
"revision": "eb2d057927b37c5a6f144ab5baa762881cffae8d",
"revisionTime": "2019-05-23T12:28:24Z"
"revision": "22dbada8b16e2c969dd60c77f4e6a346c70d5952",
"revisionTime": "2019-06-11T03:26:25Z"
},
{
"checksumSHA1": "RERqgxOX48XzRIoe5fQzvWSJV0Y=",
"path": "vitess.io/vitess/go/sqltypes",
"revision": "eb2d057927b37c5a6f144ab5baa762881cffae8d",
"revisionTime": "2019-05-23T12:28:24Z"
"revision": "22dbada8b16e2c969dd60c77f4e6a346c70d5952",
"revisionTime": "2019-06-11T03:26:25Z"
},
{
"checksumSHA1": "vAIRxI6MHsq3x1hLQwIyw5AvqtI=",
"path": "vitess.io/vitess/go/vt/log",
"revision": "eb2d057927b37c5a6f144ab5baa762881cffae8d",
"revisionTime": "2019-05-23T12:28:24Z"
"revision": "22dbada8b16e2c969dd60c77f4e6a346c70d5952",
"revisionTime": "2019-06-11T03:26:25Z"
},
{
"checksumSHA1": "/0K9CBbInkAhioqKX9ocBrJ6AKE=",
"path": "vitess.io/vitess/go/vt/proto/binlogdata",
"revision": "22dbada8b16e2c969dd60c77f4e6a346c70d5952",
"revisionTime": "2019-06-11T03:26:25Z"
},
{
"checksumSHA1": "87Zndvk3Y+M+QxMx3uFa0iSbvWY=",
"path": "vitess.io/vitess/go/vt/proto/query",
"revision": "eb2d057927b37c5a6f144ab5baa762881cffae8d",
"revisionTime": "2019-05-23T12:28:24Z"
"revision": "22dbada8b16e2c969dd60c77f4e6a346c70d5952",
"revisionTime": "2019-06-11T03:26:25Z"
},
{
"checksumSHA1": "xpcb9NfXMEeHhEPStbJntIfa5GQ=",
"path": "vitess.io/vitess/go/vt/proto/topodata",
"revision": "eb2d057927b37c5a6f144ab5baa762881cffae8d",
"revisionTime": "2019-05-23T12:28:24Z"
"revision": "22dbada8b16e2c969dd60c77f4e6a346c70d5952",
"revisionTime": "2019-06-11T03:26:25Z"
},
{
"checksumSHA1": "l9fmSuOJyoq+EKM4QxfoSw8hLPY=",
"checksumSHA1": "Ie634JZ/Np9603mG+PQ0ZkUsaQI=",
"path": "vitess.io/vitess/go/vt/proto/vtgate",
"revision": "eb2d057927b37c5a6f144ab5baa762881cffae8d",
"revisionTime": "2019-05-23T12:28:24Z"
"revision": "22dbada8b16e2c969dd60c77f4e6a346c70d5952",
"revisionTime": "2019-06-11T03:26:25Z"
},
{
"checksumSHA1": "qz32abYdmm9NfKTc++K0l1EvXXM=",
"path": "vitess.io/vitess/go/vt/proto/vtrpc",
"revision": "eb2d057927b37c5a6f144ab5baa762881cffae8d",
"revisionTime": "2019-05-23T12:28:24Z"
"revision": "22dbada8b16e2c969dd60c77f4e6a346c70d5952",
"revisionTime": "2019-06-11T03:26:25Z"
},
{
"checksumSHA1": "/V79kL29yMBxAofQBL/XqxJv/GE=",
"path": "vitess.io/vitess/go/vt/sqlparser",
"revision": "eb2d057927b37c5a6f144ab5baa762881cffae8d",
"revisionTime": "2019-05-23T12:28:24Z"
"revision": "22dbada8b16e2c969dd60c77f4e6a346c70d5952",
"revisionTime": "2019-06-11T03:26:25Z"
},
{
"checksumSHA1": "qhGH2j3onpaSh+fbs1fKPoTxUcw=",
"checksumSHA1": "z9+F/lA1Xrl5S16LKssUH8VL6hs=",
"path": "vitess.io/vitess/go/vt/vterrors",
"revision": "eb2d057927b37c5a6f144ab5baa762881cffae8d",
"revisionTime": "2019-05-23T12:28:24Z"
"revision": "22dbada8b16e2c969dd60c77f4e6a346c70d5952",
"revisionTime": "2019-06-11T03:26:25Z"
}
],
"rootPath": "github.com/XiaoMi/soar"
......
......@@ -83,7 +83,7 @@ import (
var LogErrStacks bool
func init() {
flag.BoolVar(&LogErrStacks, "LogErrStacks", false, "log stack traces in errors")
flag.BoolVar(&LogErrStacks, "log_err_stacks", false, "log stack traces for errors")
}
// New returns an error with the supplied message.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册