Skip to content

Commit

Permalink
Merge multi backend servers draining status, for remove duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
sharego committed Feb 6, 2021
1 parent 7bcd0ea commit 240318d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions marathon_lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class MarathonService(object):
def __init__(self, appId, servicePort, healthCheck, strictMode):
self.appId = appId
self.servicePort = servicePort
self.backends = set()
self.backends = {}
self.hostname = None
self.proxypath = None
self.revproxypath = None
Expand Down Expand Up @@ -156,7 +156,21 @@ def __init__(self, appId, servicePort, healthCheck, strictMode):
self.mode = 'http'

def add_backend(self, host, ip, port, draining):
self.backends.add(MarathonBackend(host, ip, port, draining))
"""
A backend server is unique by host, ip and port, not include draining
property. When backend servers repeated, the draining property should
be true if any server is draining.
"""
backend = MarathonBackend(host, ip, port, draining)
if backend in self.backends:
oldBackend = self.backends[backend]
msg_fmt = ("backend server(%s, %s, %d, %s) duplicated, exists"
"draining status is: %s")
logger.warning(msg_fmt, host, ip, port, draining,
oldBackend.draining)
oldBackend.draining = oldBackend.draining or draining
else:
self.backends[backend] = backend

def __hash__(self):
return hash(self.servicePort)
Expand Down

0 comments on commit 240318d

Please sign in to comment.