MCPcopy Create free account
hub / github.com/apache/impala / QueryToKill

Class QueryToKill

tests/util/cancel_util.py:33–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31
32
33class QueryToKill:
34 def __init__(self, test_suite, protocol, check_on_exit=True, user=None, nth_impalad=0):
35 self.client = test_suite.create_client_for_nth_impalad(nth_impalad, protocol)
36 self.sql = 'SELECT sleep(1000)'
37 self.check_on_exit = check_on_exit
38 self.user = user
39
40 def poll(self):
41 while True:
42 try:
43 results = self.client.fetch(self.sql, self.handle)
44 if len(results.data) > 0:
45 raise Exception("Failed to kill query within time limit.")
46 except Exception as e:
47 self.exc = e
48 return
49
50 def __enter__(self):
51 self.handle = self.client.execute_async(self.sql, user=self.user)
52 self.poll_thread = threading.Thread(target=lambda: self.poll())
53 self.poll_thread.start()
54 return self.client.handle_id(self.handle)
55
56 def __exit__(self, exc_type, exc_value, traceback): # noqa: U100
57 self.poll_thread.join()
58 if not self.check_on_exit:
59 self.client.close()
60 return
61 # If ImpalaServer::UnregisterQuery() happens before the last polling, the error
62 # message will be "Invalid or unknown query handle". Otherwise, the error message
63 # will be "Cancelled".
64 assert error_msg_startswith(
65 str(self.exc),
66 ["Invalid or unknown query handle", "Cancelled"],
67 self.client.handle_id(self.handle),
68 )
69 try:
70 self.client.fetch(self.sql, self.handle)
71 except Exception as ex:
72 assert "Invalid or unknown query handle" in str(ex) or "Cancelled" in str(ex)
73 finally:
74 self.client.close()
75
76
77def assert_kill_ok(client, query_id, user=None):

Calls

no outgoing calls