Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Process not destroy in DiskUtils df function #34387

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ public static Df df(String dir) {
return df;
}

Process process;
Process process = null;
BufferedReader reader = null;
InputStream inputStream = null;
try {
process = Runtime.getRuntime().exec("df -k " + dir);
InputStream inputStream = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
inputStream = process.getInputStream();
reader = new BufferedReader(new InputStreamReader(inputStream));
Df df = new Df();
// Filesystem 1K-blocks Used Available Use% Mounted on
// /dev/sdc 5814186096 5814169712 0 100% /home/spy-sd/sdc
Expand All @@ -67,6 +69,18 @@ public static Df df(String dir) {
} catch (IOException e) {
log.info("failed to obtain disk information", e);
return new Df();
} finally {
if (process != null) {
process.destroy();
}
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
log.info("failed to obtain disk information", e);
return new Df();
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,34 @@
public class DiskUtilsTest {
@Test
public void testSiseFormat() {
long [] keys = new long[]{
1L,
1L * 1024,
1L * 1024 * 1024,
1L * 1024 * 1024 * 1024,
1L * 1024 * 1024 * 1024 * 1024,
1L * 1024 * 1024 * 1024 * 1024 * 1024,
1L * 1024 * 1024 * 1024 * 1024 * 1024 * 1024,
long[] keys = new long[] {
1L,
1L * 1024,
1L * 1024 * 1024,
1L * 1024 * 1024 * 1024,
1L * 1024 * 1024 * 1024 * 1024,
1L * 1024 * 1024 * 1024 * 1024 * 1024,
1L * 1024 * 1024 * 1024 * 1024 * 1024 * 1024,
};

String[] values = new String[]{
"1",
"1K",
"1M",
"1G",
"1T",
"1P",
"1024P",
String[] values = new String[] {
"1",
"1K",
"1M",
"1G",
"1T",
"1P",
"1024P",
};

for (int i = 0; i < values.length; i++) {
Assert.assertEquals(values[i], DiskUtils.sizeFormat(keys[i]));
}
}

@Test
public void testDf() {
DiskUtils.Df d = DiskUtils.df("/proc");
Assert.assertTrue(d.fileSystem.length() != 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,10 @@ public EtlSubmitResult submitEtlJob(long jobId, String loadLabel, String cluster
List<String> hadoopRunCmdList = Util.shellSplit(hadoopRunCmd);
String[] hadoopRunCmds = hadoopRunCmdList.toArray(new String[0]);
BufferedReader errorReader = null;
Process p = null;
long startTime = System.currentTimeMillis();
try {
Process p = Runtime.getRuntime().exec(hadoopRunCmds);
p = Runtime.getRuntime().exec(hadoopRunCmds);
errorReader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
for (int i = 0; i < 1000; i++) {
outputLine = errorReader.readLine();
Expand All @@ -226,7 +227,6 @@ public EtlSubmitResult submitEtlJob(long jobId, String loadLabel, String cluster
if (outputLine.indexOf("Running job") != -1) {
String[] arr = outputLine.split(":");
etlJobId = arr[arr.length - 1].trim();
p.destroy();
break;
}
}
Expand All @@ -239,6 +239,9 @@ public EtlSubmitResult submitEtlJob(long jobId, String loadLabel, String cluster
Util.deleteDirectory(configDir);
long endTime = System.currentTimeMillis();
LOG.info("finished submit hadoop job: {}. cost: {} ms", jobId, endTime - startTime);
if (p != null) {
p.destroy();
}
if (errorReader != null) {
try {
errorReader.close();
Expand Down
7 changes: 6 additions & 1 deletion fe/fe-core/src/main/java/org/apache/doris/plsql/Exec.java
Original file line number Diff line number Diff line change
Expand Up @@ -1944,11 +1944,12 @@ public Integer visitHost_stmt(Host_stmtContext ctx) {
}

public void execHost(ParserRuleContext ctx, String cmd) {
Process p = null;
try {
if (trace) {
trace(ctx, "HOST Command: " + cmd);
}
Process p = Runtime.getRuntime().exec(cmd);
p = Runtime.getRuntime().exec(cmd);
new StreamGobbler(p.getInputStream(), console).start();
new StreamGobbler(p.getErrorStream(), console).start();
int rc = p.waitFor();
Expand All @@ -1959,6 +1960,10 @@ public void execHost(ParserRuleContext ctx, String cmd) {
} catch (Exception e) {
setHostCode(1);
signal(Signal.Type.SQLEXCEPTION);
} finally {
if (p != null) {
p.destroy();
}
}
}

Expand Down