Skip to content

Commit 8ce140d

Browse files
authored
executor: Fix the parse problematic slow log panic issue due to empty value string (#58258) (#58272)
close #58147
1 parent ba38cc1 commit 8ce140d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

executor/slow_query.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,10 @@ func splitByColon(line string) (fields []string, values []string) {
598598
fields = append(fields, line[start:current])
599599
parseKey = false
600600
current += 2 // bypass ": "
601+
if current >= lineLength {
602+
// last empty value
603+
values = append(values, "")
604+
}
601605
} else {
602606
start = current
603607
if current < lineLength && (line[current] == '{' || line[current] == '[') {
@@ -611,6 +615,13 @@ func splitByColon(line string) (fields []string, values []string) {
611615
for current < lineLength && line[current] != ' ' {
612616
current++
613617
}
618+
// Meet empty value cases: "Key: Key:"
619+
if current > 0 && line[current-1] == ':' {
620+
values = append(values, "")
621+
current = start
622+
parseKey = true
623+
continue
624+
}
614625
}
615626
values = append(values, line[start:mathutil.Min(current, len(line))])
616627
parseKey = true
@@ -620,6 +631,10 @@ func splitByColon(line string) (fields []string, values []string) {
620631
logutil.BgLogger().Warn("slow query parse slow log error", zap.String("Error", errMsg), zap.String("Log", line))
621632
return nil, nil
622633
}
634+
if len(fields) != len(values) {
635+
logutil.BgLogger().Warn("slow query parse slow log error", zap.Int("field_count", len(fields)), zap.Int("value_count", len(values)), zap.String("Log", line))
636+
return nil, nil
637+
}
623638
return fields, values
624639
}
625640

executor/slow_query_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ func TestSplitbyColon(t *testing.T) {
499499
{
500500
"123a",
501501
[]string{"123a"},
502-
[]string{},
502+
[]string{""},
503503
},
504504
{
505505
"1a: 2b",
@@ -552,9 +552,16 @@ func TestSplitbyColon(t *testing.T) {
552552
[]string{"Time"},
553553
[]string{"2021-09-08T14:39:54.506967433+08:00"},
554554
},
555+
{
556+
557+
"Cop_proc_avg: 0 Cop_proc_addr: Cop_proc_max: Cop_proc_min: ",
558+
[]string{"Cop_proc_avg", "Cop_proc_addr", "Cop_proc_max", "Cop_proc_min"},
559+
[]string{"0", "", "", ""},
560+
},
555561
}
556562
for _, c := range cases {
557563
resFields, resValues := splitByColon(c.line)
564+
logutil.BgLogger().Info(c.line)
558565
require.Equal(t, c.fields, resFields)
559566
require.Equal(t, c.values, resValues)
560567
}

0 commit comments

Comments
 (0)