Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NET-5608] Fix snapshot creation issue. #18783

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions agent/consul/fsm/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
raftstorage "github.com/hashicorp/consul/internal/storage/raft"
)

var cePersister, entPersister persister

var SnapshotSummaries = []prometheus.SummaryDefinition{
{
Name: []string{"fsm", "persist"},
Expand All @@ -44,15 +46,6 @@ type SnapshotHeader struct {
// persister is a function used to help snapshot the FSM state.
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.
type restorer func(header *SnapshotHeader, restore *state.Restore, decoder *codec.Decoder) error

Expand Down Expand Up @@ -86,7 +79,16 @@ func (s *snapshot) Persist(sink raft.SnapshotSink) error {
}

// 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 {
sink.Cancel()
return err
Expand Down
3 changes: 1 addition & 2 deletions agent/consul/fsm/snapshot_ce.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import (
)

func init() {
registerPersister(persistCE)

cePersister = persistCE
registerRestorer(structs.RegisterRequestType, restoreRegistration)
registerRestorer(structs.KVSRequestType, restoreKV)
registerRestorer(structs.TombstoneRequestType, restoreTombstone)
Expand Down
Loading