-
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 1 commit
d92fac8
c1a162a
ba7e33a
1673bd5
79fe8d0
943012a
293ce63
61d8249
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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 exeucted. | ||
*/ | ||
@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,26 @@ | ||
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 |
---|---|---|
|
@@ -71,6 +71,7 @@ | |
import org.apache.tez.Utils; | ||
import org.apache.tez.client.CallerContext; | ||
import org.apache.tez.client.TezClientUtils; | ||
import org.apache.tez.common.ReflectionUtils; | ||
import org.apache.tez.common.TezUtils; | ||
import org.apache.tez.dag.api.NamedEntityDescriptor; | ||
import org.apache.tez.dag.api.SessionNotRunning; | ||
|
@@ -187,7 +188,7 @@ | |
import org.apache.tez.dag.utils.Simple2LevelVersionComparator; | ||
import org.apache.tez.hadoop.shim.HadoopShim; | ||
import org.apache.tez.hadoop.shim.HadoopShimsLoader; | ||
import org.apache.tez.runtime.TezThreadDumpHelper; | ||
import org.apache.tez.runtime.hook.TezDAGHook; | ||
import org.apache.tez.util.LoggingUtils; | ||
import org.apache.tez.util.TezMxBeanResourceCalculator; | ||
import org.codehaus.jettison.json.JSONException; | ||
|
@@ -343,7 +344,7 @@ public class DAGAppMaster extends AbstractService { | |
Map<Service, ServiceWithDependency> services = | ||
new LinkedHashMap<Service, ServiceWithDependency>(); | ||
private ThreadLocalMap mdcContext; | ||
private TezThreadDumpHelper tezThreadDumpHelper = TezThreadDumpHelper.NOOP_TEZ_THREAD_DUMP_HELPER; | ||
private TezDAGHook[] hooks = {}; | ||
|
||
public DAGAppMaster(ApplicationAttemptId applicationAttemptId, | ||
ContainerId containerId, String nmHost, int nmPort, int nmHttpPort, | ||
|
@@ -770,7 +771,9 @@ protected synchronized void handle(DAGAppMasterEvent event) { | |
"DAGAppMaster Internal Error occurred"); | ||
break; | ||
case DAG_FINISHED: | ||
tezThreadDumpHelper.stop(); | ||
for (TezDAGHook hook : hooks) { | ||
hook.stop(); | ||
} | ||
DAGAppMasterEventDAGFinished finishEvt = | ||
(DAGAppMasterEventDAGFinished) event; | ||
String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()); | ||
|
@@ -2227,7 +2230,9 @@ public Void run() throws Exception { | |
} | ||
|
||
// Check if the thread dump service is up in any case, if yes attempt a shutdown | ||
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. remove thread dump helper related comment, and change to a more generic one that tells we're about to stop hooks if they are running in any case 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. Done |
||
tezThreadDumpHelper.stop(); | ||
for (TezDAGHook hook : hooks) { | ||
hook.stop(); | ||
} | ||
|
||
super.serviceStop(); | ||
} | ||
|
@@ -2599,7 +2604,13 @@ private void countHeldContainers(DAG newDAG) { | |
private void startDAGExecution(DAG dag, final Map<String, LocalResource> additionalAmResources) | ||
throws TezException { | ||
currentDAG = dag; | ||
tezThreadDumpHelper = TezThreadDumpHelper.getInstance(dag.getConf()).start(dag.getID().toString()); | ||
final Configuration conf = dag.getConf(); | ||
final String[] hookClasses = conf.getStrings(TezConfiguration.TEZ_AM_HOOKS, new String[0]); | ||
final TezDAGHook[] hooks = new TezDAGHook[hookClasses.length]; | ||
for (int i = 0; i < hooks.length; i++) { | ||
hooks[i] = ReflectionUtils.createClazzInstance(hookClasses[i]); | ||
hooks[i].start(dag.getID(), conf); | ||
} | ||
|
||
// Try localizing the actual resources. | ||
List<URL> additionalUrlsForClasspath; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.apache.tez.runtime.task; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.tez.dag.records.TezTaskAttemptID; | ||
import org.apache.tez.runtime.TezThreadDumpHelper; | ||
import org.apache.tez.runtime.hook.TezTaskAttemptHook; | ||
|
||
/** | ||
* A task attempt hook which dumps thread information periodically. | ||
*/ | ||
public class ThreadDumpTaskAttemptHook implements TezTaskAttemptHook { | ||
private TezThreadDumpHelper helper; | ||
|
||
@Override | ||
public void start(TezTaskAttemptID id, Configuration conf) { | ||
helper = TezThreadDumpHelper.getInstance(conf).start(id.toString()); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
helper.stop(); | ||
} | ||
} |
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.
If we introduce pluggable hooks, I think we can change the default value. We may remove NOOP_TEZ_THREAD_DUMP_HELPER, too.
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.
makes sense
I think for package clarity's sake, all the hook related configs can go a namespace that implies they're hooks:
also:
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.
I think you can remove the NoopTezThreadDumpHelper
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.
Done.