Don't panic on unknown raft ops (#17732)
* Don't panic on unknown raft ops * avoid excessive logging * track at the struct level, not the function level * add changelog
This commit is contained in:
parent
5b731699a1
commit
e75633eddc
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:bug
|
||||||
|
storage/raft: Don't panic on unknown raft ops
|
||||||
|
```
|
|
@ -104,6 +104,7 @@ type FSM struct {
|
||||||
|
|
||||||
localID string
|
localID string
|
||||||
desiredSuffrage string
|
desiredSuffrage string
|
||||||
|
unknownOpTypes sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFSM constructs a FSM using the given directory
|
// NewFSM constructs a FSM using the given directory
|
||||||
|
@ -593,19 +594,19 @@ func (f *FSM) ApplyBatch(logs []*raft.Log) []interface{} {
|
||||||
// Do the unmarshalling first so we don't hold locks
|
// Do the unmarshalling first so we don't hold locks
|
||||||
var latestConfiguration *ConfigurationValue
|
var latestConfiguration *ConfigurationValue
|
||||||
commands := make([]interface{}, 0, numLogs)
|
commands := make([]interface{}, 0, numLogs)
|
||||||
for _, log := range logs {
|
for _, l := range logs {
|
||||||
switch log.Type {
|
switch l.Type {
|
||||||
case raft.LogCommand:
|
case raft.LogCommand:
|
||||||
command := &LogData{}
|
command := &LogData{}
|
||||||
err := proto.Unmarshal(log.Data, command)
|
err := proto.Unmarshal(l.Data, command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.logger.Error("error proto unmarshaling log data", "error", err)
|
f.logger.Error("error proto unmarshaling log data", "error", err)
|
||||||
panic("error proto unmarshaling log data")
|
panic("error proto unmarshaling log data")
|
||||||
}
|
}
|
||||||
commands = append(commands, command)
|
commands = append(commands, command)
|
||||||
case raft.LogConfiguration:
|
case raft.LogConfiguration:
|
||||||
configuration := raft.DecodeConfiguration(log.Data)
|
configuration := raft.DecodeConfiguration(l.Data)
|
||||||
config := raftConfigurationToProtoConfiguration(log.Index, configuration)
|
config := raftConfigurationToProtoConfiguration(l.Index, configuration)
|
||||||
|
|
||||||
commands = append(commands, config)
|
commands = append(commands, config)
|
||||||
|
|
||||||
|
@ -614,7 +615,7 @@ func (f *FSM) ApplyBatch(logs []*raft.Log) []interface{} {
|
||||||
latestConfiguration = config
|
latestConfiguration = config
|
||||||
|
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("got unexpected log type: %d", log.Type))
|
panic(fmt.Sprintf("got unexpected log type: %d", l.Type))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -672,7 +673,10 @@ func (f *FSM) ApplyBatch(logs []*raft.Log) []interface{} {
|
||||||
go f.restoreCb(context.Background())
|
go f.restoreCb(context.Background())
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("%q is not a supported transaction operation", op.OpType)
|
if _, ok := f.unknownOpTypes.Load(op.OpType); !ok {
|
||||||
|
f.logger.Error("unsupported transaction operation", "op", op.OpType)
|
||||||
|
f.unknownOpTypes.Store(op.OpType, struct{}{})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue