Skip to content

Commit 0f32738

Browse files
authored
executor: Fix the parse problematic slow log panic issue due to empty value string (#58258) (#58271)
close #58147
1 parent 858ba74 commit 0f32738

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
@@ -599,6 +599,10 @@ func splitByColon(line string) (fields []string, values []string) {
599599
fields = append(fields, line[start:current])
600600
parseKey = false
601601
current += 2 // bypass ": "
602+
if current >= lineLength {
603+
// last empty value
604+
values = append(values, "")
605+
}
602606
} else {
603607
start = current
604608
if current < lineLength && (line[current] == '{' || line[current] == '[') {
@@ -612,6 +616,13 @@ func splitByColon(line string) (fields []string, values []string) {
612616
for current < lineLength && line[current] != ' ' {
613617
current++
614618
}
619+
// Meet empty value cases: "Key: Key:"
620+
if current > 0 && line[current-1] == ':' {
621+
values = append(values, "")
622+
current = start
623+
parseKey = true
624+
continue
625+
}
615626
}
616627
values = append(values, line[start:mathutil.Min(current, len(line))])
617628
parseKey = true
@@ -621,6 +632,10 @@ func splitByColon(line string) (fields []string, values []string) {
621632
logutil.BgLogger().Warn("slow query parse slow log error", zap.String("Error", errMsg), zap.String("Log", line))
622633
return nil, nil
623634
}
635+
if len(fields) != len(values) {
636+
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))
637+
return nil, nil
638+
}
624639
return fields, values
625640
}
626641

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)