From 609e999c28f35dc4b2e7bef93ca8f3526c218200 Mon Sep 17 00:00:00 2001 From: Venkat Date: Tue, 24 Mar 2020 16:22:49 -0700 Subject: [PATCH] ringpop: add method to selfEvict from ring (#3132) --- common/membership/interfaces.go | 4 ++++ common/membership/interfaces_mock.go | 14 ++++++++++++++ common/membership/rpMonitor.go | 4 ++++ host/simpleMonitor.go | 4 ++++ 4 files changed, 26 insertions(+) diff --git a/common/membership/interfaces.go b/common/membership/interfaces.go index b4e2d6205ff..604f415bc34 100644 --- a/common/membership/interfaces.go +++ b/common/membership/interfaces.go @@ -53,6 +53,10 @@ type ( common.Daemon WhoAmI() (*HostInfo, error) + // EvictSelf evicts this member from the membership ring. After this method is + // called, other members will discover that this node is no longer part of the + // ring. This primitive is useful to carry out graceful host shutdown during deployments. + EvictSelf() error Lookup(service string, key string) (*HostInfo, error) GetResolver(service string) (ServiceResolver, error) // AddListener adds a listener for this service. diff --git a/common/membership/interfaces_mock.go b/common/membership/interfaces_mock.go index 44f99888c73..93e1874cf49 100644 --- a/common/membership/interfaces_mock.go +++ b/common/membership/interfaces_mock.go @@ -95,6 +95,20 @@ func (mr *MockMonitorMockRecorder) WhoAmI() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WhoAmI", reflect.TypeOf((*MockMonitor)(nil).WhoAmI)) } +// EvictSelf mocks base method +func (m *MockMonitor) EvictSelf() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "EvictSelf") + ret0, _ := ret[0].(error) + return ret0 +} + +// EvictSelf indicates an expected call of EvictSelf +func (mr *MockMonitorMockRecorder) EvictSelf() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EvictSelf", reflect.TypeOf((*MockMonitor)(nil).EvictSelf)) +} + // Lookup mocks base method func (m *MockMonitor) Lookup(service, key string) (*HostInfo, error) { m.ctrl.T.Helper() diff --git a/common/membership/rpMonitor.go b/common/membership/rpMonitor.go index ef30d50f4bb..72879138ed4 100644 --- a/common/membership/rpMonitor.go +++ b/common/membership/rpMonitor.go @@ -115,6 +115,10 @@ func (rpo *ringpopMonitor) WhoAmI() (*HostInfo, error) { return NewHostInfo(address, labels.AsMap()), nil } +func (rpo *ringpopMonitor) EvictSelf() error { + return rpo.rp.SelfEvict() +} + func (rpo *ringpopMonitor) GetResolver(service string) (ServiceResolver, error) { ring, found := rpo.rings[service] if !found { diff --git a/host/simpleMonitor.go b/host/simpleMonitor.go index 540617ff146..857105ed9ab 100644 --- a/host/simpleMonitor.go +++ b/host/simpleMonitor.go @@ -47,6 +47,10 @@ func (s *simpleMonitor) Start() { func (s *simpleMonitor) Stop() { } +func (s *simpleMonitor) EvictSelf() error { + return nil +} + func (s *simpleMonitor) WhoAmI() (*membership.HostInfo, error) { return s.hostInfo, nil }