fix: verify server snapshots and recover whole migration sessions (#3)
This commit is contained in:
1 parent
3d4101ecc0
commit
8569871a17
29 files changed
+1923
-133
No files matched your search
@@ -0,0 +1,43 @@
|
||||
package mariadb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Recovery covers the selected schema, so external trigger effects are refused.
|
||||
func validateSnapshotTriggerReferences(trigger snapshotTrigger, schema string) error {
|
||||
body := trigger.Body
|
||||
quoted := `'(?:''|\\.|[^'\\])*'`
|
||||
if strings.Contains(trigger.SQLMode, "NO_BACKSLASH_ESCAPES") {
|
||||
quoted = `'(?:''|[^'])*'`
|
||||
}
|
||||
body = regexp.MustCompile(quoted).ReplaceAllString(body, " ")
|
||||
if !strings.Contains(trigger.SQLMode, "ANSI_QUOTES") {
|
||||
double := `"(?:""|\\.|[^"\\])*"`
|
||||
if strings.Contains(trigger.SQLMode, "NO_BACKSLASH_ESCAPES") {
|
||||
double = `"(?:""|[^"])*"`
|
||||
}
|
||||
body = regexp.MustCompile(double).ReplaceAllString(body, " ")
|
||||
}
|
||||
if strings.Contains(body, "/*!") || strings.Contains(body, "/*M!") {
|
||||
return fmt.Errorf("trigger %s has unsupported executable comments", trigger.Name)
|
||||
}
|
||||
body = regexp.MustCompile(`(?s)/\*.*?\*/|--[\t ][^\n]*|#[^\n]*`).ReplaceAllString(body, " ")
|
||||
if regexp.MustCompile(`(?i)\bCALL\s+`).MatchString(body) {
|
||||
return fmt.Errorf("trigger %s calls a routine outside supported recovery", trigger.Name)
|
||||
}
|
||||
identifier := "(?:`(?:``|[^`])+`|\"(?:\"\"|[^\"])+\"|[\\pL_$][\\pL\\pN_$]*)"
|
||||
for _, pattern := range []string{
|
||||
"(?i)\\b(?:FROM|JOIN|UPDATE|INTO)\\s+(?:(?:LOW_PRIORITY|HIGH_PRIORITY|DELAYED|IGNORE)\\s+)*(" + identifier + ")\\s*\\.",
|
||||
"(?i)(" + identifier + ")\\s*\\.\\s*" + identifier + "\\s*\\(",
|
||||
} {
|
||||
for _, match := range regexp.MustCompile(pattern).FindAllStringSubmatch(body, -1) {
|
||||
if !strings.EqualFold(strings.Trim(match[1], "`\""), schema) {
|
||||
return fmt.Errorf("trigger %s references another schema outside supported recovery", trigger.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user