etcdserver: fix data race in cluster

The data race happens when etcd updates member attributes and fetches
member info in http handler at the same time.
This commit is contained in:
Yicheng Qin
2014-11-07 16:04:09 -08:00
parent 2fc47034ee
commit 014ef0f52d
4 changed files with 52 additions and 8 deletions

View File

@ -618,13 +618,11 @@ func (s *EtcdServer) applyRequest(r pb.Request) Response {
default:
if storeMemberAttributeRegexp.MatchString(r.Path) {
id := mustParseMemberIDFromKey(path.Dir(r.Path))
m := s.Cluster.Member(id)
if m == nil {
log.Panicf("fetch member %s should never fail", id)
}
if err := json.Unmarshal([]byte(r.Val), &m.Attributes); err != nil {
var attr Attributes
if err := json.Unmarshal([]byte(r.Val), &attr); err != nil {
log.Panicf("unmarshal %s should never fail: %v", r.Val, err)
}
s.Cluster.UpdateMemberAttributes(id, attr)
}
return f(s.store.Set(r.Path, r.Dir, r.Val, expr))
}