Skip to content

Commit

Permalink
drop TouchRegistrations and s/TouchRegistration/TouchProducer
Browse files Browse the repository at this point in the history
  • Loading branch information
mreiferson committed Aug 11, 2014
1 parent 9e5be83 commit 7f8fe64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
2 changes: 1 addition & 1 deletion nsqd/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (n *NSQD) gossipHandleCreateEvent(operation byte,
if n.rdb.AddProducer(r, producer) {
n.logf("DB: member(%s) REGISTER %s", gev.Name, r)
}
if operation == '=' && n.rdb.TouchRegistration(r.Category, r.Key, r.SubKey, producer.ID) {
if operation == '=' && n.rdb.TouchProducer(r, producer.ID) {
n.logf("DB: member(%s) TOUCH %s", gev.Name, r)
}
}
Expand Down
30 changes: 8 additions & 22 deletions util/registrationdb/registrationdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,32 +193,18 @@ func (r *RegistrationDB) LookupRegistrations(id string) Registrations {
return results
}

func (r *RegistrationDB) TouchRegistrations(id string) {
func (r *RegistrationDB) TouchProducer(k Registration, id string) bool {
r.mtx.RLock()
defer r.mtx.RUnlock()
now := time.Now()
for _, producers := range r.data {
for _, p := range producers {
if p.ID == id {
atomic.StoreInt64(&p.LastUpdate, now.UnixNano())
}
}
producers, ok := r.data[k]
if !ok {
return false
}
}

func (r *RegistrationDB) TouchRegistration(category string, key string, subkey string, id string) bool {
r.mtx.RLock()
defer r.mtx.RUnlock()
now := time.Now()
for k, producers := range r.data {
if !k.IsMatch(category, key, subkey) {
continue
}
for _, p := range producers {
if p.ID == id {
atomic.StoreInt64(&p.LastUpdate, now.UnixNano())
return true
}
for _, p := range producers {
if p.ID == id {
atomic.StoreInt64(&p.LastUpdate, now.UnixNano())
return true
}
}
return false
Expand Down

0 comments on commit 7f8fe64

Please sign in to comment.