Skip to content

Commit

Permalink
Add the ability to provide priority/sort to PluginInitializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Johnson committed Jan 16, 2025
1 parent 7090c52 commit 16b47a1
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions go/vt/vtgate/plugin_mysql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"os/signal"
"regexp"
"sort"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -503,10 +504,16 @@ func initMySQLProtocol(vtgate *VTGate) *mysqlServer {
}

// Initialize registered AuthServer implementations (or other plugins)
for _, initFn := range pluginInitializers {
initFn()
// sort pluginInitializers by priority
sort.Slice(pluginInitializers, func(i, j int) bool {
return pluginInitializers[i].priority < pluginInitializers[j].priority
})
log.Infof("mysql plugins to initialize: %v", pluginInitializers)
for _, pluginInitializer := range pluginInitializers {
pluginInitializer.initializer()
}
authServer := mysql.GetAuthServer(mysqlAuthServerImpl)
log.Infof("using mysql auth server implementation: %s", mysqlAuthServerImpl)

// Check mysql_default_workload
var ok bool
Expand Down Expand Up @@ -725,9 +732,18 @@ func init() {
servenv.OnParseFor("vtcombo", registerPluginFlags)
}

var pluginInitializers []func()
type pluginInitializer struct {
priority int
initializer func()
}

var pluginInitializers []pluginInitializer

// RegisterPluginInitializer lets plugins register themselves to be init'ed at servenv.OnRun-time
func RegisterPluginInitializer(initializer func()) {
pluginInitializers = append(pluginInitializers, initializer)
RegisterPluginInitializerWithPriority(0, initializer)
}

func RegisterPluginInitializerWithPriority(initPriority int, initializer func()) {
pluginInitializers = append(pluginInitializers, pluginInitializer{initPriority, initializer})
}

0 comments on commit 16b47a1

Please sign in to comment.