Skip to content

Commit 26608b4

Browse files
authored
Fixed race in ddl commands cleanup (#481)
* Fixed race in ddl commands cleanup * Call cleanup on error
1 parent 2364c13 commit 26608b4

File tree

6 files changed

+63
-56
lines changed

6 files changed

+63
-56
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package logadaptor
2+
3+
import (
4+
"github.com/lni/dragonboat/v3/logger"
5+
log "github.com/sirupsen/logrus"
6+
)
7+
8+
/*
9+
This adaptor allows us to plug the dragonboat logging into the logrus logger we use in Prana.
10+
*/
11+
12+
func init() {
13+
logger.SetLoggerFactory(logrusLogFactory)
14+
}
15+
16+
func logrusLogFactory(pkgName string) logger.ILogger {
17+
return &LogrusILogger{}
18+
}
19+
20+
type LogrusILogger struct {
21+
level logger.LogLevel
22+
}
23+
24+
func (l *LogrusILogger) SetLevel(level logger.LogLevel) {
25+
l.level = level
26+
}
27+
28+
func (l *LogrusILogger) Debugf(format string, args ...interface{}) {
29+
if l.level >= logger.DEBUG {
30+
log.Debugf(format, args...)
31+
}
32+
}
33+
34+
func (l *LogrusILogger) Infof(format string, args ...interface{}) {
35+
if l.level >= logger.INFO {
36+
log.Infof(format, args...)
37+
}
38+
}
39+
40+
func (l *LogrusILogger) Warningf(format string, args ...interface{}) {
41+
if l.level >= logger.WARNING {
42+
log.Warnf(format, args...)
43+
}
44+
}
45+
46+
func (l *LogrusILogger) Errorf(format string, args ...interface{}) {
47+
if l.level >= logger.ERROR {
48+
log.Errorf(format, args...)
49+
}
50+
}
51+
52+
func (l *LogrusILogger) Panicf(format string, args ...interface{}) {
53+
log.Fatalf(format, args...)
54+
}

cluster/dragon/logrus_adaptor.go

Lines changed: 0 additions & 56 deletions
This file was deleted.

command/create_index_command.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ func (c *CreateIndexCommand) AfterPhase(phase int32) error {
148148
}
149149

150150
func (c *CreateIndexCommand) Cleanup() {
151+
c.lock.Lock()
152+
defer c.lock.Unlock()
151153
if c.indexInfo == nil {
152154
return
153155
}

command/create_mv_command.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ func (c *CreateMVCommand) AfterPhase(phase int32) error {
218218
}
219219

220220
func (c *CreateMVCommand) Cleanup() {
221+
c.lock.Lock()
222+
defer c.lock.Unlock()
221223
if c.mv == nil {
222224
return
223225
}

command/create_source_command.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ func (c *CreateSourceCommand) AfterPhase(phase int32) error {
211211
}
212212

213213
func (c *CreateSourceCommand) Cleanup() {
214+
c.lock.Lock()
215+
defer c.lock.Unlock()
214216
if c.sourceInfo == nil {
215217
return
216218
}

command/ddl_runner.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ func (d *DDLCommandRunner) HandleDdlMessage(notification remoting.ClusterMessage
216216
return nil
217217
}
218218
err := com.OnPhase(phase)
219+
if err != nil {
220+
com.Cleanup()
221+
}
219222
if phase == int32(com.NumPhases()-1) {
220223
// Final phase so delete the command
221224
d.commands.Delete(skey)

0 commit comments

Comments
 (0)