M18: cache DB-dump validation; skip re-validate on unchanged dumps
ListDumpFiles ran ValidateDump (line-by-line scan) for every dump on every ~5-min RefreshCache cycle — wasted I/O+CPU on large customer dumps. ListDumpFiles now takes an optional cached(name,size,mod) lookup; on a (size+modtime) match it reuses the prior result and skips ValidateDump. settings.DBValidationCache gains Size+ModTime; listAllDumpFiles builds the lookup from the persisted cache and writes back only fresh validations (cache miss), so an unchanged dump triggers neither a re-validation nor a settings.json write each cycle. nil cached = legacy validate-always (back-compat). Tests: cache-hit skips validate (sentinel), cache-miss validates, nil validates.
This commit is contained in:
@@ -432,7 +432,12 @@ func ValidateDump(filePath string, dbType DBType) DumpValidation {
|
||||
}
|
||||
|
||||
// ListDumpFiles returns info about SQL dump files on disk.
|
||||
func ListDumpFiles(dumpDir string) ([]DumpFileInfo, error) {
|
||||
//
|
||||
// M18: ValidateDump scans the dump line-by-line; on a customer with hundreds-of-MB dumps that is wasted
|
||||
// disk I/O + CPU on every ~5-min scheduler cycle. `cached` is an optional lookup that returns a
|
||||
// previously-computed DumpValidation for a file whose (name, size, modtime) match — when it returns ok,
|
||||
// the expensive ValidateDump is skipped. Pass nil to always validate (legacy fast path / other callers).
|
||||
func ListDumpFiles(dumpDir string, cached func(name string, size int64, mod time.Time) (DumpValidation, bool)) ([]DumpFileInfo, error) {
|
||||
entries, err := os.ReadDir(dumpDir)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
@@ -474,7 +479,14 @@ func ListDumpFiles(dumpDir string) ([]DumpFileInfo, error) {
|
||||
f.StackName = base
|
||||
}
|
||||
|
||||
// Run validation on the file
|
||||
// M18: reuse a cached validation when the file is unchanged (name+size+modtime), else validate.
|
||||
if cached != nil {
|
||||
if v, ok := cached(e.Name(), info.Size(), info.ModTime()); ok {
|
||||
f.Validation = v
|
||||
files = append(files, f)
|
||||
continue
|
||||
}
|
||||
}
|
||||
fullPath := filepath.Join(dumpDir, e.Name())
|
||||
f.Validation = ValidateDump(fullPath, f.DBType)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user