logs table migration: skip on corrupted json and fail later (#1856)

enhance  #1828
This commit is contained in:
6543 2023-06-13 11:50:11 +02:00 committed by GitHub
parent ff01a9ff1d
commit 6be61e6c9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -97,9 +97,13 @@ var migrateLogs2LogEntries = task{
return err return err
} }
hasJSONErrors := false
page := 0 page := 0
offset := 0
logs := make([]*oldLogs019, 0, perPage019) logs := make([]*oldLogs019, 0, perPage019)
logEntries := make([]*oldLogEntry019, 0, 50) logEntries := make([]*oldLogEntry019, 0, 50)
sigterm := abool.New() sigterm := abool.New()
ctx, cancelCtx := context.WithCancelCause(context.Background()) ctx, cancelCtx := context.WithCancelCause(context.Background())
defer cancelCtx(nil) defer cancelCtx(nil)
@ -120,7 +124,7 @@ var migrateLogs2LogEntries = task{
} }
logs = logs[:0] logs = logs[:0]
err := sess.Limit(perPage019).Find(&logs) err := sess.Limit(perPage019, offset).Find(&logs)
if err != nil { if err != nil {
return err return err
} }
@ -130,7 +134,9 @@ var migrateLogs2LogEntries = task{
for _, l := range logs { for _, l := range logs {
logEntries = logEntries[:0] logEntries = logEntries[:0]
if err := json.Unmarshal(l.Data, &logEntries); err != nil { if err := json.Unmarshal(l.Data, &logEntries); err != nil {
return err hasJSONErrors = true
offset++
continue
} }
time := int64(0) time := int64(0)
@ -170,6 +176,10 @@ var migrateLogs2LogEntries = task{
page++ page++
} }
if hasJSONErrors {
return fmt.Errorf("skipped some logs as json could not be deserialized for them")
}
return e.DropTables("logs") return e.DropTables("logs")
}, },
} }