Returns the number of outstanding cache requests. Due to race conditions in the way cache requests are added/dropped/reported (see IMPALA-3040), this function tries to return a stable result by making several attempts to stabilize it within a reasonable timeout.
()
| 327 | |
| 328 | |
| 329 | def get_num_cache_requests(): |
| 330 | """Returns the number of outstanding cache requests. Due to race conditions in the |
| 331 | way cache requests are added/dropped/reported (see IMPALA-3040), this function tries |
| 332 | to return a stable result by making several attempts to stabilize it within a |
| 333 | reasonable timeout.""" |
| 334 | def get_num_cache_requests_util(): |
| 335 | rc, stdout, stderr = exec_process("hdfs cacheadmin -listDirectives -stats") |
| 336 | assert rc == 0, 'Error executing hdfs cacheadmin: %s %s' % (stdout, stderr) |
| 337 | # remove blank new lines from output count |
| 338 | lines = [line for line in stdout.split('\n') if line.strip()] |
| 339 | count = None |
| 340 | for line in lines: |
| 341 | if line.startswith("Found "): |
| 342 | # the line should say "Found <int> entries" |
| 343 | # if we find this line we parse the number of entries |
| 344 | # from this line. |
| 345 | count = int(re.search(r'\d+', line).group()) |
| 346 | break |
| 347 | # if count is available we return it else we just |
| 348 | # return the total number of lines |
| 349 | if count is not None: |
| 350 | return count |
| 351 | else: |
| 352 | return len(stdout.split('\n')) |
| 353 | |
| 354 | # IMPALA-3040: This can take time, especially under slow builds like ASAN. |
| 355 | wait_time_in_sec = build_flavor_timeout(5, slow_build_timeout=20) |
| 356 | num_stabilization_attempts = 0 |
| 357 | max_num_stabilization_attempts = 10 |
| 358 | num_requests = None |
| 359 | LOG.info("{0} Entered get_num_cache_requests()".format(time.time())) |
| 360 | while num_stabilization_attempts < max_num_stabilization_attempts: |
| 361 | new_requests = get_num_cache_requests_util() |
| 362 | if new_requests == num_requests: break |
| 363 | LOG.info("{0} Waiting to stabilise: num_requests={1} new_requests={2}".format( |
| 364 | time.time(), num_requests, new_requests)) |
| 365 | num_requests = new_requests |
| 366 | num_stabilization_attempts = num_stabilization_attempts + 1 |
| 367 | time.sleep(wait_time_in_sec) |
| 368 | LOG.info("{0} Final num requests: {1}".format(time.time(), num_requests)) |
| 369 | return num_requests |
no test coverage detected