Skip to content

Commit

Permalink
decrease service put frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Nov 9, 2020
1 parent 35bd9fc commit dc13f79
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 1 addition & 3 deletions discovery/helium/helium.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@ func (h *Helium) start(ctx context.Context) {
Addresses: addresses,
Interval: h.config.ServiceDiscoveryPushInterval * 2,
}
h.dispatch(latestStatus)

case <-timer.C:
h.dispatch(latestStatus)
}
h.dispatch(latestStatus)
timer.Stop()
timer.Reset(h.config.ServiceDiscoveryPushInterval)
}
Expand Down
18 changes: 16 additions & 2 deletions store/etcdv3/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,22 @@ func (m *Mercury) RegisterService(ctx context.Context, serviceAddress string, ex
if err != nil {
return err
}

_, err = m.Put(ctx, key, "", clientv3.WithLease(lease.ID))
tr, err := m.cliv3.Txn(ctx).
If(clientv3.Compare(clientv3.Version(key), "!=", 0)).
Then(clientv3.OpGet(key)).
Else(clientv3.OpPut(key, "", clientv3.WithLease(lease.ID))).
Commit()
if err != nil {
return err
}
if !tr.Succeeded {
return nil
}
oldLeaseID := clientv3.LeaseID(tr.Responses[0].GetResponseRange().Kvs[0].Lease)
if _, err = m.cliv3.Revoke(ctx, lease.ID); err != nil {
log.Warnf("[RegisterService] revoke lease failed %v", err)
}
_, err = m.cliv3.KeepAliveOnce(ctx, oldLeaseID)
return err
}

Expand Down

0 comments on commit dc13f79

Please sign in to comment.