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

storage: Always gossip system config after lease changes hands #17285

Merged
merged 1 commit into from
Jul 28, 2017
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
10 changes: 10 additions & 0 deletions pkg/gossip/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,16 @@ func (g *Gossip) GetInfoProto(key string, msg proto.Message) error {
return proto.Unmarshal(bytes, msg)
}

// InfoOriginatedHere returns true iff the latest info for the provided key
// originated on this node. This is useful for ensuring that the system config
// is regossiped as soon as possible when its lease changes hands.
func (g *Gossip) InfoOriginatedHere(key string) bool {
g.mu.Lock()
info := g.mu.is.getInfo(key)
g.mu.Unlock()
return info != nil && info.NodeID == g.NodeID.Get()
}

// GetInfoStatus returns the a copy of the contents of the infostore.
func (g *Gossip) GetInfoStatus() InfoStatus {
g.mu.Lock()
Expand Down
41 changes: 41 additions & 0 deletions pkg/storage/client_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,44 @@ func TestStoreGossipSystemData(t *testing.T) {
return nil
})
}

// TestGossipSystemConfigOnLeaseChange verifies that the system-config gets
// re-gossiped on lease transfer even if it hasn't changed. This helps prevent
// situations where a previous leaseholder can restart and not receive the
// system config because it was the original source of it within the gossip
// network.
func TestGossipSystemConfigOnLeaseChange(t *testing.T) {
defer leaktest.AfterTest(t)()
sc := storage.TestStoreConfig(nil)
sc.TestingKnobs.DisableReplicateQueue = true
mtc := &multiTestContext{storeConfig: &sc}
defer mtc.Stop()
const numStores = 3
mtc.Start(t, numStores)

rangeID := mtc.stores[0].LookupReplica(roachpb.RKey(keys.SystemConfigSpan.Key), nil).RangeID
mtc.replicateRange(rangeID, 1, 2)

initialStoreIdx := -1
for i := range mtc.stores {
if mtc.stores[i].Gossip().InfoOriginatedHere(gossip.KeySystemConfig) {
initialStoreIdx = i
}
}
if initialStoreIdx == -1 {
t.Fatalf("no store has gossiped system config; gossip contents: %+v", mtc.stores[0].Gossip().GetInfoStatus())
}

newStoreIdx := (initialStoreIdx + 1) % numStores
mtc.transferLease(context.TODO(), rangeID, initialStoreIdx, newStoreIdx)

testutils.SucceedsSoon(t, func() error {
if mtc.stores[initialStoreIdx].Gossip().InfoOriginatedHere(gossip.KeySystemConfig) {
return errors.New("system config still most recently gossiped by original leaseholder")
}
if !mtc.stores[newStoreIdx].Gossip().InfoOriginatedHere(gossip.KeySystemConfig) {
return errors.New("system config not most recently gossiped by new leaseholder")
}
return nil
})
}
3 changes: 2 additions & 1 deletion pkg/storage/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -5012,7 +5012,8 @@ func (r *Replica) maybeGossipSystemConfig(ctx context.Context) error {
return errors.Wrap(err, "could not load SystemConfig span")
}

if gossipedCfg, ok := r.store.Gossip().GetSystemConfig(); ok && gossipedCfg.Equal(loadedCfg) {
if gossipedCfg, ok := r.store.Gossip().GetSystemConfig(); ok && gossipedCfg.Equal(loadedCfg) &&
r.store.Gossip().InfoOriginatedHere(gossip.KeySystemConfig) {
log.VEventf(ctx, 2, "not gossiping unchanged system config")
return nil
}
Expand Down