@@ -91,6 +91,9 @@ func InitEventScheduler(
9191
9292// Close closes the EventScheduler.
9393func (es * EventScheduler ) Close () {
94+ if es == nil {
95+ return
96+ }
9497 es .status = SchedulerOff
9598 es .executor .shutdown ()
9699}
@@ -99,6 +102,9 @@ func (es *EventScheduler) Close() {
99102// This function requires valid analyzer and sql context to evaluate all events in all databases
100103// to load enabled events to the EventScheduler.
101104func (es * EventScheduler ) TurnOnEventScheduler (a * analyzer.Analyzer ) error {
105+ if es == nil {
106+ return nil
107+ }
102108 if es .status == SchedulerDisabled {
103109 return ErrEventSchedulerDisabled
104110 } else if es .status == SchedulerOn {
@@ -120,6 +126,9 @@ func (es *EventScheduler) TurnOnEventScheduler(a *analyzer.Analyzer) error {
120126
121127// TurnOffEventScheduler is called when user sets --event-scheduler system variable to OFF or 0.
122128func (es * EventScheduler ) TurnOffEventScheduler () error {
129+ if es == nil {
130+ return nil
131+ }
123132 if es .status == SchedulerDisabled {
124133 return ErrEventSchedulerDisabled
125134 } else if es .status == SchedulerOff {
@@ -135,6 +144,9 @@ func (es *EventScheduler) TurnOffEventScheduler() error {
135144// loadEventsAndStartEventExecutor evaluates all events in all databases and evaluates the enabled events
136145// with valid schedule to load into the eventExecutor. Then, it starts the eventExecutor.
137146func (es * EventScheduler ) loadEventsAndStartEventExecutor (ctx * sql.Context , a * analyzer.Analyzer ) error {
147+ if es == nil {
148+ return nil
149+ }
138150 es .executor .catalog = a .Catalog
139151 es .executor .loadAllEvents (ctx )
140152 go es .executor .start ()
@@ -144,6 +156,9 @@ func (es *EventScheduler) loadEventsAndStartEventExecutor(ctx *sql.Context, a *a
144156// AddEvent implements sql.EventScheduler interface.
145157// This function is called when there is an event created at runtime.
146158func (es * EventScheduler ) AddEvent (ctx * sql.Context , edb sql.EventDatabase , details sql.EventDefinition ) {
159+ if es == nil {
160+ return
161+ }
147162 if es .status == SchedulerDisabled || es .status == SchedulerOff {
148163 return
149164 }
@@ -153,6 +168,9 @@ func (es *EventScheduler) AddEvent(ctx *sql.Context, edb sql.EventDatabase, deta
153168// UpdateEvent implements sql.EventScheduler interface.
154169// This function is called when there is an event altered at runtime.
155170func (es * EventScheduler ) UpdateEvent (ctx * sql.Context , edb sql.EventDatabase , orgEventName string , details sql.EventDefinition ) {
171+ if es == nil {
172+ return
173+ }
156174 if es .status == SchedulerDisabled || es .status == SchedulerOff {
157175 return
158176 }
@@ -163,6 +181,9 @@ func (es *EventScheduler) UpdateEvent(ctx *sql.Context, edb sql.EventDatabase, o
163181// This function is called when there is an event dropped at runtime. This function
164182// removes the given event if it exists in the enabled events list of the EventScheduler.
165183func (es * EventScheduler ) RemoveEvent (dbName , eventName string ) {
184+ if es == nil {
185+ return
186+ }
166187 if es .status == SchedulerDisabled || es .status == SchedulerOff {
167188 return
168189 }
@@ -173,6 +194,9 @@ func (es *EventScheduler) RemoveEvent(dbName, eventName string) {
173194// This function is called when there is a database dropped at runtime. This function
174195// removes all events of given database that exist in the enabled events list of the EventScheduler.
175196func (es * EventScheduler ) RemoveSchemaEvents (dbName string ) {
197+ if es == nil {
198+ return
199+ }
176200 if es .status == SchedulerDisabled || es .status == SchedulerOff {
177201 return
178202 }
0 commit comments