IMPALA-2378: check proc mem limit before preparing fragment
IMPALA-2378: check proc mem limit before preparing fragment

Preparing a query fragment for execution uses a significant amount of
untracked memory. Currently, if a query is admitted, it will consume
a significant amount of memory regardless of how much process memory
is available on each impalad. This is a problem since the untracked
memory is included in the Tcmalloc stats used towards thhe process
memory limit.

We saw stress tests get into a state where the vast majority of cluster
memory was taken up by this untracked memory, causing allocations of
tracked memory to fail.

This patch partially addresses the problem by checking whether the
process memory limit is exceeded before preparing a query fragment.
If there is no process memory available, fragment execution is
cancelled before any additional memory is consumed for LLVM code,
descriptors, execution nodes, and other untracked structures.
This gives already-running queries a better chance of succeeding and
does not waste resources preparing fragments that will immediately hit a
memory limit.

Testing: ran stress tests with the two TPCDS queries known to exhibit
this problem especially badly. The memory limit was not exceeded by more
than 0.1GB.

Change-Id: Ie7743834a57a044657f6fcac4623a609c2eb07dc
Reviewed-on: http://gerrit.cloudera.org:8080/1215
Reviewed-by: Dan Hecht <20ebd99959f0f6e5dcb0fc319b4d8ef53a16b5fb@cloudera.com>
Tested-by: Internal Jenkins

cloudera/recordservice,cloudera/recordservice,cloudera/recordservice,cloudera/recordservice,cloudera/recordservice,cloudera/recordservice,cloudera/recordservice