mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-02-27 02:00:57 +08:00
Refactoring: migrate translations to singleton
It was using maps in each context, which would be merged between contexts, then injected each time we needed a message to display. It had a limitation on complicated operator setups: historical information would be overriden by newer associations. (e.g, that IP was for node0 yesterday, now it's node1, so associations have been overwritten and incorrect) It also introduced complexity, such as forcing to define closures too many times, merging maps, it would be harder to debug, and every files were starting from empty translation maps. Moreover, iterating on maps is guaranteed to be random so it could create hard-to-debug output variations on complex cases. Now it is a singleton in translate package, still using maps but now it associates an array of "units" storing the timestamp with each piece of information. It is protected by rwmutex, because map are not threadsafe. (there's no parallel processing for now) No regressions, and it passes "operator_ambiguous_ips_list_all_no_color" where the old system failed. It nows also can be used as an easy to read source of information in itself
This commit is contained in:
committed by
Sveta Smirnova
parent
e56fc45a05
commit
2091c1a1f0
@@ -2,6 +2,7 @@ package regex
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/percona/percona-toolkit/src/go/pt-galera-log-explainer/types"
|
||||
"github.com/percona/percona-toolkit/src/go/pt-galera-log-explainer/utils"
|
||||
@@ -12,7 +13,7 @@ func init() {
|
||||
}
|
||||
|
||||
var (
|
||||
shiftFunc = func(submatches map[string]string, ctx types.LogCtx, log string) (types.LogCtx, types.LogDisplayer) {
|
||||
shiftFunc = func(submatches map[string]string, ctx types.LogCtx, log string, date time.Time) (types.LogCtx, types.LogDisplayer) {
|
||||
|
||||
newState := submatches["state2"]
|
||||
ctx.SetState(newState)
|
||||
@@ -41,9 +42,9 @@ var StatesMap = types.RegexMap{
|
||||
"RegexRestoredState": &types.LogRegex{
|
||||
Regex: regexp.MustCompile("Restored state"),
|
||||
InternalRegex: shiftRegex,
|
||||
Handler: func(submatches map[string]string, ctx types.LogCtx, log string) (types.LogCtx, types.LogDisplayer) {
|
||||
Handler: func(submatches map[string]string, ctx types.LogCtx, log string, date time.Time) (types.LogCtx, types.LogDisplayer) {
|
||||
var displayer types.LogDisplayer
|
||||
ctx, displayer = shiftFunc(submatches, ctx, log)
|
||||
ctx, displayer = shiftFunc(submatches, ctx, log, date)
|
||||
|
||||
return ctx, types.SimpleDisplayer("(restored)" + displayer(ctx))
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user