mirror of https://github.com/hashicorp/consul
Backport of Fix snapshot creation issue. into release/1.15.x (#18788)
backport of commit fe581326aa
Co-authored-by: Derek Menteer <derek.menteer@hashicorp.com>
backport/16955-transfer-leader/safely-positive-bobcat
parent
e0fa7742f6
commit
d69b9c6286
|
@ -13,6 +13,8 @@ import (
|
||||||
"github.com/hashicorp/raft"
|
"github.com/hashicorp/raft"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var cePersister, entPersister persister
|
||||||
|
|
||||||
var SnapshotSummaries = []prometheus.SummaryDefinition{
|
var SnapshotSummaries = []prometheus.SummaryDefinition{
|
||||||
{
|
{
|
||||||
Name: []string{"fsm", "persist"},
|
Name: []string{"fsm", "persist"},
|
||||||
|
@ -38,15 +40,6 @@ type SnapshotHeader struct {
|
||||||
// persister is a function used to help snapshot the FSM state.
|
// persister is a function used to help snapshot the FSM state.
|
||||||
type persister func(s *snapshot, sink raft.SnapshotSink, encoder *codec.Encoder) error
|
type persister func(s *snapshot, sink raft.SnapshotSink, encoder *codec.Encoder) error
|
||||||
|
|
||||||
// persisters is a list of snapshot functions.
|
|
||||||
var persisters []persister
|
|
||||||
|
|
||||||
// registerPersister adds a new helper. This should be called at package
|
|
||||||
// init() time.
|
|
||||||
func registerPersister(fn persister) {
|
|
||||||
persisters = append(persisters, fn)
|
|
||||||
}
|
|
||||||
|
|
||||||
// restorer is a function used to load back a snapshot of the FSM state.
|
// restorer is a function used to load back a snapshot of the FSM state.
|
||||||
type restorer func(header *SnapshotHeader, restore *state.Restore, decoder *codec.Decoder) error
|
type restorer func(header *SnapshotHeader, restore *state.Restore, decoder *codec.Decoder) error
|
||||||
|
|
||||||
|
@ -80,7 +73,16 @@ func (s *snapshot) Persist(sink raft.SnapshotSink) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run all the persisters to write the FSM state.
|
// Run all the persisters to write the FSM state.
|
||||||
for _, fn := range persisters {
|
for _, fn := range []persister{
|
||||||
|
// The enterprise version MUST be executed first, otherwise the snapshot will
|
||||||
|
// not properly function during restore due to missing tenancy objects.
|
||||||
|
entPersister,
|
||||||
|
cePersister,
|
||||||
|
} {
|
||||||
|
// Check for nil, since the enterprise version may not exist in CE.
|
||||||
|
if fn == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err := fn(s, sink, encoder); err != nil {
|
if err := fn(s, sink, encoder); err != nil {
|
||||||
sink.Cancel()
|
sink.Cancel()
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -14,8 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerPersister(persistCE)
|
cePersister = persistCE
|
||||||
|
|
||||||
registerRestorer(structs.RegisterRequestType, restoreRegistration)
|
registerRestorer(structs.RegisterRequestType, restoreRegistration)
|
||||||
registerRestorer(structs.KVSRequestType, restoreKV)
|
registerRestorer(structs.KVSRequestType, restoreKV)
|
||||||
registerRestorer(structs.TombstoneRequestType, restoreTombstone)
|
registerRestorer(structs.TombstoneRequestType, restoreTombstone)
|
||||||
|
|
Loading…
Reference in New Issue