Skip to content

Commit

Permalink
[Config]: Fix handling of greenlet threads in ST
Browse files Browse the repository at this point in the history
Schema Transformer spawns greenlet threads for reading updates from
ifmap and calling process_networks() function. It's right now spwaning
multiple greenlets without killing the previous one. This provides the
fix for killing the greenlet that hasn't been switched or is dead.

Change-Id: I5bf6aeb408d46a0bfcd3c09eab6c75d1cf84198c
Closes-Bug: #1704197
  • Loading branch information
sahilsabharwal committed Jul 14, 2017
1 parent 03a0147 commit 5b86769
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/config/schema-transformer/to_bgp.py
Expand Up @@ -3846,28 +3846,32 @@ def reset():


def set_ifmap_search_done(transformer):
gevent.sleep(60)
while time.time() - gevent.getcurrent().poll_timestamp < 60:
gevent.sleep(60)
transformer.ifmap_search_done = True
transformer.current_network_set = set(VirtualNetworkST.keys())
transformer.process_networks()
transformer.process_stale_objects()
transformer.ifmap_search_done_greenlet = None
# end set_ifmap_search_done

def launch_arc(transformer, ssrc_mapc):
arc_mapc = arc_initialize(transformer._args, ssrc_mapc)
transformer.ifmap_search_done_greenlet = gevent.spawn(set_ifmap_search_done,
transformer)
transformer.ifmap_search_done_greenlet.poll_timestamp = sys.maxint
while True:
try:
# If not connected to zookeeper Pause the operations
if not _zookeeper_client.is_connected():
time.sleep(1)
continue

pollreq = PollRequest(arc_mapc.get_session_id())
glet = None
if not transformer.ifmap_search_done:
glet = gevent.spawn(set_ifmap_search_done, transformer)
result = arc_mapc.call('poll', pollreq)
if glet:
glet.kill()

if transformer.ifmap_search_done_greenlet is not None:
transformer.ifmap_search_done_greenlet.poll_timestamp = time.time()
transformer.process_poll_result(result)
except Exception as e:
if type(e) == socket.error:
Expand Down

0 comments on commit 5b86769

Please sign in to comment.