Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRILL-3732: Drill leaks memory if external sort hits out of disk spac…
…e exception - ExternalSort.mergeAndSpill() cleans all it's data in case an errors occurs while it's spilling to disk - made BatchGroup AutoCloseable so it can easily be closed with AutoCloseables.close() if an error occurs - added injection site while External sort is spilling to disk - added unit test that forces a 2 batch query to spill to disk and injects an exception while it does so this closes #147
- Loading branch information
Showing
5 changed files
with
161 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...c/src/test/java/org/apache/drill/exec/physical/impl/xsort/TestSortSpillWithException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,79 @@ | |||
/** | |||
* Licensed to the Apache Software Foundation (ASF) under one | |||
* or more contributor license agreements. See the NOTICE file | |||
* distributed with this work for additional information | |||
* regarding copyright ownership. The ASF licenses this file | |||
* to you under the Apache License, Version 2.0 (the | |||
* "License"); you may not use this file except in compliance | |||
* with the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package org.apache.drill.exec.physical.impl.xsort; | |||
|
|||
import org.apache.drill.BaseTestQuery; | |||
import org.apache.drill.common.config.DrillConfig; | |||
import org.apache.drill.common.exceptions.UserRemoteException; | |||
import org.apache.drill.common.util.TestTools; | |||
import org.apache.drill.exec.ExecConstants; | |||
import org.apache.drill.exec.proto.UserBitShared.DrillPBError.ErrorType; | |||
import org.apache.drill.exec.testing.Controls; | |||
import org.apache.drill.exec.testing.ControlsInjectionUtil; | |||
import org.junit.BeforeClass; | |||
import org.junit.Test; | |||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.fail; | |||
|
|||
import java.io.IOException; | |||
import java.util.Properties; | |||
|
|||
/** | |||
* Testing External Sort's spilling to disk. | |||
* <br> | |||
* This class changes the following Drill property to force external sort to spill after the 2nd batch: | |||
* {@link ExecConstants#EXTERNAL_SORT_SPILL_THRESHOLD} = 1 | |||
* <br> | |||
* {@link ExecConstants#EXTERNAL_SORT_SPILL_GROUP_SIZE} = 1 | |||
*/ | |||
public class TestSortSpillWithException extends BaseTestQuery { | |||
private static final String TEST_RES_PATH = TestTools.getWorkingPath() + "/src/test/resources"; | |||
|
|||
@BeforeClass | |||
public static void initCluster() { | |||
// make sure memory sorter outputs 20 rows per batch | |||
final Properties props = cloneDefaultTestConfigProperties(); | |||
props.put(ExecConstants.EXTERNAL_SORT_SPILL_THRESHOLD, "1"); | |||
props.put(ExecConstants.EXTERNAL_SORT_SPILL_GROUP_SIZE, "1"); | |||
|
|||
updateTestCluster(1, DrillConfig.create(props)); | |||
} | |||
|
|||
@Test | |||
public void testSpilLeak() throws Exception { | |||
// inject exception in sort while spilling | |||
final String controls = Controls.newBuilder() | |||
.addExceptionOnBit( | |||
ExternalSortBatch.class, | |||
ExternalSortBatch.INTERRUPTION_WHILE_SPILLING, | |||
IOException.class, | |||
bits[0].getContext().getEndpoint()) | |||
.build(); | |||
ControlsInjectionUtil.setControls(client, controls); | |||
// run a simple order by query | |||
try { | |||
test("select employee_id from dfs_test.`%s/xsort/2batches` order by employee_id", TEST_RES_PATH); | |||
fail("Query should have failed!"); | |||
} catch (UserRemoteException e) { | |||
assertEquals(ErrorType.RESOURCE, e.getErrorType()); | |||
assertTrue("Incorrect error message", | |||
e.getMessage().contains("External Sort encountered an error while spilling to disk")); | |||
} | |||
} | |||
} |
20 changes: 20 additions & 0 deletions
20
exec/java-exec/src/test/resources/xsort/2batches/0.data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
{ "employee_id":24 } | |||
{ "employee_id":36 } | |||
{ "employee_id":11 } | |||
{ "employee_id":27 } | |||
{ "employee_id":23 } | |||
{ "employee_id":25 } | |||
{ "employee_id":8 } | |||
{ "employee_id":12 } | |||
{ "employee_id":29 } | |||
{ "employee_id":33 } | |||
{ "employee_id":19 } | |||
{ "employee_id":22 } | |||
{ "employee_id":31 } | |||
{ "employee_id":30 } | |||
{ "employee_id":35 } | |||
{ "employee_id":5 } | |||
{ "employee_id":4 } | |||
{ "employee_id":16 } | |||
{ "employee_id":13 } | |||
{ "employee_id":9 } |
20 changes: 20 additions & 0 deletions
20
exec/java-exec/src/test/resources/xsort/2batches/1.data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
{ "employee_id":20 } | |||
{ "employee_id":7 } | |||
{ "employee_id":38 } | |||
{ "employee_id":3 } | |||
{ "employee_id":15 } | |||
{ "employee_id":2 } | |||
{ "employee_id":39 } | |||
{ "employee_id":37 } | |||
{ "employee_id":10 } | |||
{ "employee_id":18 } | |||
{ "employee_id":17 } | |||
{ "employee_id":32 } | |||
{ "employee_id":34 } | |||
{ "employee_id":1 } | |||
{ "employee_id":21 } | |||
{ "employee_id":14 } | |||
{ "employee_id":6 } | |||
{ "employee_id":26 } | |||
{ "employee_id":0 } | |||
{ "employee_id":28 } |