-
Notifications
You must be signed in to change notification settings - Fork 425
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
TEZ-4527: Add generic and pluggable hooks for DAGs and task attempts #324
Changes from 6 commits
d92fac8
c1a162a
ba7e33a
1673bd5
79fe8d0
943012a
293ce63
61d8249
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* 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.tez.runtime.hook; | ||
|
||
import org.apache.hadoop.classification.InterfaceAudience; | ||
import org.apache.hadoop.classification.InterfaceStability; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.tez.dag.records.TezDAGID; | ||
|
||
/** | ||
* A hook which is instantiated and triggered before and after a DAG is executed. | ||
*/ | ||
@InterfaceAudience.Public | ||
@InterfaceStability.Evolving | ||
public interface TezDAGHook { | ||
/** | ||
* Invoked before the DAG starts. | ||
* | ||
* @param id the DAG id | ||
* @param conf the conf | ||
*/ | ||
void start(TezDAGID id, Configuration conf); | ||
|
||
/** | ||
* Invoked after the DAG finishes. | ||
*/ | ||
void stop(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* 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.tez.runtime.hook; | ||
|
||
import org.apache.hadoop.classification.InterfaceAudience; | ||
import org.apache.hadoop.classification.InterfaceStability; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.tez.dag.records.TezTaskAttemptID; | ||
|
||
/** | ||
* A hook which is instantiated and triggered before and after a task attempt is executed. | ||
*/ | ||
@InterfaceAudience.Public | ||
@InterfaceStability.Evolving | ||
public interface TezTaskAttemptHook { | ||
/** | ||
* Invoked before the task attempt starts. | ||
* | ||
* @param id the task attempt id | ||
* @param conf the conf | ||
*/ | ||
void start(TezTaskAttemptID id, Configuration conf); | ||
|
||
/** | ||
* Invoked after the task attempt finishes. | ||
*/ | ||
void stop(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
@Private | ||
package org.apache.tez.runtime.hook; | ||
|
||
import org.apache.hadoop.classification.InterfaceAudience.Private; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* 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.tez.dag.app; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.tez.dag.records.TezDAGID; | ||
import org.apache.tez.runtime.TezThreadDumpHelper; | ||
import org.apache.tez.runtime.hook.TezDAGHook; | ||
|
||
/** | ||
* A DAG hook which dumps thread information periodically. | ||
*/ | ||
public class ThreadDumpDAGHook implements TezDAGHook { | ||
private TezThreadDumpHelper helper; | ||
|
||
@Override | ||
public void start(TezDAGID id, Configuration conf) { | ||
helper = TezThreadDumpHelper.getInstance(conf).start(id.toString()); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
helper.stop(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -24,8 +24,10 @@ | |||||||||||||||||||||||||||
import org.apache.hadoop.fs.FileSystem; | ||||||||||||||||||||||||||||
import org.apache.hadoop.fs.Path; | ||||||||||||||||||||||||||||
import org.apache.log4j.Appender; | ||||||||||||||||||||||||||||
import org.apache.tez.common.Preconditions; | ||||||||||||||||||||||||||||
import org.apache.tez.common.TezContainerLogAppender; | ||||||||||||||||||||||||||||
import org.apache.tez.dag.api.TezConstants; | ||||||||||||||||||||||||||||
import org.apache.tez.dag.api.TezUncheckedException; | ||||||||||||||||||||||||||||
import org.slf4j.Logger; | ||||||||||||||||||||||||||||
import org.slf4j.LoggerFactory; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
@@ -40,12 +42,11 @@ | |||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
import static org.apache.hadoop.yarn.conf.YarnConfiguration.DEFAULT_NM_REMOTE_APP_LOG_DIR; | ||||||||||||||||||||||||||||
import static org.apache.hadoop.yarn.conf.YarnConfiguration.NM_REMOTE_APP_LOG_DIR; | ||||||||||||||||||||||||||||
import static org.apache.tez.dag.api.TezConfiguration.TEZ_THREAD_DUMP_INTERVAL; | ||||||||||||||||||||||||||||
import static org.apache.tez.dag.api.TezConfiguration.TEZ_THREAD_DUMP_INTERVAL_DEFAULT; | ||||||||||||||||||||||||||||
import static org.apache.tez.dag.api.TezConfiguration.TEZ_HOOK_THREAD_DUMP_INTERVAL; | ||||||||||||||||||||||||||||
import static org.apache.tez.dag.api.TezConfiguration.TEZ_HOOK_THREAD_DUMP_INTERVAL_DEFAULT; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
public class TezThreadDumpHelper { | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
public static final NoopTezThreadDumpHelper NOOP_TEZ_THREAD_DUMP_HELPER = new NoopTezThreadDumpHelper(); | ||||||||||||||||||||||||||||
private long duration = 0L; | ||||||||||||||||||||||||||||
private Path basePath = null; | ||||||||||||||||||||||||||||
private FileSystem fs = null; | ||||||||||||||||||||||||||||
|
@@ -70,21 +71,17 @@ private TezThreadDumpHelper(long duration, Configuration conf) throws IOExceptio | |||||||||||||||||||||||||||
"path: {}", duration, basePath); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
public TezThreadDumpHelper() { | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm, cannot recall what the purpose was of this constructor, does reflection work without this explicitly defined? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is originally needed to instantiate tez/tez-runtime-internals/src/main/java/org/apache/tez/runtime/TezThreadDumpHelper.java Lines 182 to 194 in ca15119
I think the class is not constructed in a reflective way, or it doesn't assume it's reflectively operated. I slightly updated the modifiers to make sure it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, I was wrong, the hooks are created by reflection, but the TezThreadDumpHelper is not
|
||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
public static TezThreadDumpHelper getInstance(Configuration conf) { | ||||||||||||||||||||||||||||
long periodicThreadDumpFrequency = | ||||||||||||||||||||||||||||
conf.getTimeDuration(TEZ_THREAD_DUMP_INTERVAL, TEZ_THREAD_DUMP_INTERVAL_DEFAULT, TimeUnit.MILLISECONDS); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
if (periodicThreadDumpFrequency > 0) { | ||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||
return new TezThreadDumpHelper(periodicThreadDumpFrequency, conf); | ||||||||||||||||||||||||||||
} catch (IOException e) { | ||||||||||||||||||||||||||||
LOG.warn("Can not initialize periodic thread dump service", e); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
long periodicThreadDumpFrequency = conf.getTimeDuration(TEZ_HOOK_THREAD_DUMP_INTERVAL, | ||||||||||||||||||||||||||||
TEZ_HOOK_THREAD_DUMP_INTERVAL_DEFAULT, TimeUnit.MILLISECONDS); | ||||||||||||||||||||||||||||
Preconditions.checkArgument(periodicThreadDumpFrequency > 0, "%s must be positive duration", | ||||||||||||||||||||||||||||
TEZ_HOOK_THREAD_DUMP_INTERVAL); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||
return new TezThreadDumpHelper(periodicThreadDumpFrequency, conf); | ||||||||||||||||||||||||||||
} catch (IOException e) { | ||||||||||||||||||||||||||||
throw new TezUncheckedException("Can not initialize periodic thread dump service", e); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
return NOOP_TEZ_THREAD_DUMP_HELPER; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
public TezThreadDumpHelper start(String name) { | ||||||||||||||||||||||||||||
|
@@ -178,18 +175,4 @@ private String getTaskName(long id, String taskName) { | |||||||||||||||||||||||||||
return id + " (" + taskName + ")"; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
private static class NoopTezThreadDumpHelper extends TezThreadDumpHelper { | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||
public TezThreadDumpHelper start(String name) { | ||||||||||||||||||||||||||||
// Do Nothing | ||||||||||||||||||||||||||||
return this; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||
public void stop() { | ||||||||||||||||||||||||||||
// Do Nothing | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@okumin : I'm terribly sorry, I just realized that changing this causes more problems than benefits (changing config opts from one release to another), the class name also doesn't have "hook" in it, so it's fine to have this as "tez.thread.dump.interval", are you fine with changing back? TEZ_THREAD_DUMP_INTERVAL was also fine from this point of view
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np. I renamed them back
293ce63