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

raft-leases: Skip legacy leases with blank name/holder when upgrading #9724

Merged
merged 1 commit into from
Feb 11, 2019
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
4 changes: 4 additions & 0 deletions upgrades/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ func MigrateLegacyLeases(context Context) error {

// Populate the snapshot and the leaseholders collection.
for key, info := range legacyLeases {
if key.Lease == "" || info.Holder == "" {
logger.Debugf("not migrating blank lease %#v holder %q", key, info.Holder)
continue
}
entries[raftlease.SnapshotKey{
Namespace: key.Namespace,
ModelUUID: key.ModelUUID,
Expand Down
69 changes: 69 additions & 0 deletions upgrades/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,75 @@ func (s *raftSuite) TestMigrateLegacyLeases(c *gc.C) {

}

func (s *raftSuite) TestIgnoresBlankLeaseOrHolder(c *gc.C) {
dataDir := c.MkDir()
context := &mockContext{
agentConfig: &mockAgentConfig{
tag: names.NewMachineTag("23"),
dataDir: dataDir,
},
state: &mockState{
members: []replicaset.Member{{
Address: "somewhere.else:37012",
Tags: map[string]string{"juju-machine-id": "42"},
}},
info: state.StateServingInfo{APIPort: 1234},
},
}
err := upgrades.BootstrapRaft(context)
c.Assert(err, jc.ErrorIsNil)

var zero time.Time

// Now we migrate some leases...
config, err := controller.NewConfig(
coretesting.ControllerTag.Id(),
coretesting.CACert,
nil,
)
c.Assert(err, jc.ErrorIsNil)
var target mockTarget
context.state = &mockState{
config: config,
leases: map[lease.Key]lease.Info{
// Blank lease name.
{"nonagon", "m1", ""}: {
Holder: "knife",
Expiry: zero.Add(30 * time.Second),
},
// Blank lease holder.
{"reyne", "m2", "keening"}: {
Holder: "",
Expiry: zero.Add(45 * time.Second),
},
},
target: &target,
}

err = upgrades.MigrateLegacyLeases(context)
c.Assert(err, jc.ErrorIsNil)
target.assertClaimed(c, map[lease.Key]string{})

expectedLeases := make(map[lease.Key]lease.Info)

// Start up raft with the leases in the snapshot.
fsm := raftlease.NewFSM()
withRaft(c, dataDir, fsm, func(r *raft.Raft) {
// Once the snapshot is loaded the leases should be in the
// FSM.
var leases map[lease.Key]lease.Info
for a := coretesting.LongAttempt.Start(); a.Next(); {
leases = fsm.Leases(func() time.Time { return zero })
if reflect.DeepEqual(leases, expectedLeases) {
return
}
}
c.Assert(leases, gc.DeepEquals, expectedLeases,
gc.Commentf("waited %s but saw unexpected leases",
coretesting.LongAttempt.Total))
})
}

type mockState struct {
upgrades.StateBackend
stub testing.Stub
Expand Down