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

server/balancer: guarantee replicas are safe if possible #473

Merged
merged 6 commits into from
Jan 21, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 14 additions & 5 deletions server/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,24 @@ func (c *RaftCluster) putStore(store *metapb.Store) error {
}
}

// Store exists, update store meta.
if s := cluster.getStore(store.GetId()); s != nil {
s := cluster.getStore(store.GetId())
if s == nil {
// Add a new store.
s = newStoreInfo(store)
} else {
// Update an existed store.
s.Address = store.Address
s.Labels = store.Labels
return cluster.putStore(s)
}

// Store does not exist, add a new store.
return cluster.putStore(newStoreInfo(store))
// Check location labels.
for _, k := range c.s.cfg.Replication.LocationLabels {
if v := s.getLabelValue(k); len(v) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should check before update the store info?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's ok, it is a clone.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

return errors.Errorf("missing location label %q in store %v", k, s)
}
}

return cluster.putStore(s)
}

// RemoveStore marks a store as offline in cluster.
Expand Down
2 changes: 1 addition & 1 deletion server/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (s *storeInfo) getLocationID(keys []string) string {
if len(v) == 0 {
return ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to consider the latter key which value is not empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should support missing label cases, it's error prone and hard to explain the behavior.
If we want to update the configurations or labels, we can just turn off the balance temporarily.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we should forbid the missing label in TiKV, and if TiKV reports the label without a value, we should log an error and don't add this label too.

}
id += s.getLabelValue(k)
id += v
}
return id
}
Expand Down