Paul Rogers created DRILL-7560:
----------------------------------

             Summary: Free leaked memory after failed unit tests
                 Key: DRILL-7560
                 URL: https://issues.apache.org/jira/browse/DRILL-7560
             Project: Apache Drill
          Issue Type: Improvement
    Affects Versions: 1.17.0
            Reporter: Paul Rogers


Many unit tests work directly with vectors or record batches returned from 
queries. As a result, tests are responsible for correctly freeing memory held 
by vectors. Simple example:

{code:java}
  public void testDummyReader() throws Exception {
    RowSet results = client.queryBuilder()
        .sql("SELECT a, b, c from dummy.myTable")
        .rowSet();
    assertEquals(3, results.rowCount());
    results.clear();
  }
{code}

If the test fails, memory will be leaked and the test will report a failure on 
shut-down.

Now, in most cases, the test has already failed; there is no real harm in 
leaking memory because the problem will go away once the test is fixed and 
works and the assert passes.

Still, one could argue that the above is messy. Perhaps a cleaner solution is:

{code:java}
  public void testDummyReader() throws Exception {
    RowSet results = null;
    try {
      results = client.queryBuilder()
          .sql("SELECT a, b, c from dummy.myTable")
          .rowSet();
      assertEquals(3, results.rowCount());
    } finally {
      if (results != null) { results.clear(); }
  }
{code}

Obviously, however, this is tedious and error-prone. Since these are tests, 
failure could occur anywhere, maybe even before the row set is returned to the 
test.

So, a more general solution is to walk the allocator tree and free any 
remaining resources. Call this when we shut down the test cluster, which JUnit 
will do whether the test succeeds or fails.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to