Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Aug 22, 2024
1 parent 3195f98 commit 6d8061f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 21 deletions.
21 changes: 9 additions & 12 deletions go/vt/events/eventer/eventer.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package eventer

import (
"sync"

"github.com/spf13/pflag"

"vitess.io/vitess/go/vt/log"
topoevents "vitess.io/vitess/go/vt/topotools/events"
)

var (
eventers map[string]Eventer
eventersMu sync.Mutex
eventerName string = "log"
)

Expand All @@ -29,33 +31,28 @@ type Eventer interface {
}

func New() Eventer {
eventersMu.Lock()
defer eventersMu.Unlock()
if ev, ok := eventers[eventerName]; ok {
return ev
}
return nil
}

type LogEventer struct{}

func NewLogEventer() Eventer { return &LogEventer{} }

func (le *LogEventer) EmergencyReparentShard(src Source, ev *topoevents.Reparent, err error) error {
log.Infof("Received EmergencyReparentShardEvent: source=%s, err=%v, event=%v", src, err, ev)

func EmergencyReparentShard(evr Eventer, ev *topoevents.Reparent) error {
return nil
}

func (le *LogEventer) PlannedReparentShard(src Source, ev *topoevents.Reparent, err error) error {
log.Infof("Received PlannedReparentShardEvent: source=%s, err=%v, event=%v", src, err, ev)

func PlannedReparentShard(evr Eventer, ev *topoevents.Reparent) error {
return nil
}

func RegisterEventer(name string, e Eventer) {
eventersMu.Lock()
defer eventersMu.Unlock()
eventers[name] = e
}

func init() {
eventers = make(map[string]Eventer, 0)
RegisterEventer("log", NewLogEventer())
}
26 changes: 26 additions & 0 deletions go/vt/events/eventer/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package eventer

import (
"vitess.io/vitess/go/vt/log"
topoevents "vitess.io/vitess/go/vt/topotools/events"
)

type LogEventer struct{}

func NewLogEventer() Eventer { return &LogEventer{} }

func (le *LogEventer) EmergencyReparentShard(src Source, ev *topoevents.Reparent, err error) error {
log.Infof("Received EmergencyReparentShardEvent: source=%s, err=%v, event=%v", src, err, ev)

return nil
}

func (le *LogEventer) PlannedReparentShard(src Source, ev *topoevents.Reparent, err error) error {
log.Infof("Received PlannedReparentShardEvent: source=%s, err=%v, event=%v", src, err, ev)

return nil
}

func init() {
RegisterEventer("log", NewLogEventer())
}
18 changes: 9 additions & 9 deletions go/vt/vtctl/reparentutil/planned_reparenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ import (

// PlannedReparenter performs PlannedReparentShard operations.
type PlannedReparenter struct {
ts *topo.Server
tmc tmclient.TabletManagerClient
logger logutil.Logger
eventer eventer.Eventer
ts *topo.Server
tmc tmclient.TabletManagerClient
logger logutil.Logger
evr eventer.Eventer
}

// PlannedReparentOptions provides optional parameters to PlannedReparentShard
Expand All @@ -69,12 +69,12 @@ type PlannedReparentOptions struct {
// TabletManagerClient, and logger.
//
// Providing a nil logger instance is allowed.
func NewPlannedReparenter(ts *topo.Server, tmc tmclient.TabletManagerClient, logger logutil.Logger, eventer eventer.Eventer) *PlannedReparenter {
func NewPlannedReparenter(ts *topo.Server, tmc tmclient.TabletManagerClient, logger logutil.Logger, evr eventer.Eventer) *PlannedReparenter {
pr := PlannedReparenter{
ts: ts,
tmc: tmc,
logger: logger,
eventer: eventer,
ts: ts,
tmc: tmc,
logger: logger,
evr: evr,
}

if pr.logger == nil {
Expand Down

0 comments on commit 6d8061f

Please sign in to comment.