use of org.apache.hadoop.hive.ql.plan.BaseWork in project hive by apache.
the class TezTask method execute.
@Override
public int execute(DriverContext driverContext) {
int rc = 1;
boolean cleanContext = false;
Context ctx = null;
Ref<TezSessionState> sessionRef = Ref.from(null);
try {
// Get or create Context object. If we create it we have to clean it later as well.
ctx = driverContext.getCtx();
if (ctx == null) {
ctx = new Context(conf);
cleanContext = true;
// some DDL task that directly executes a TezTask does not setup Context and hence TriggerContext.
// Setting queryId is messed up. Some DDL tasks have executionId instead of proper queryId.
String queryId = HiveConf.getVar(conf, HiveConf.ConfVars.HIVEQUERYID);
WmContext wmContext = new WmContext(System.currentTimeMillis(), queryId);
ctx.setWmContext(wmContext);
}
// Need to remove this static hack. But this is the way currently to get a session.
SessionState ss = SessionState.get();
// Note: given that we return pool sessions to the pool in the finally block below, and that
// we need to set the global to null to do that, this "reuse" may be pointless.
TezSessionState session = sessionRef.value = ss.getTezSession();
if (session != null && !session.isOpen()) {
LOG.warn("The session: " + session + " has not been opened");
}
// We only need a username for UGI to use for groups; getGroups will fetch the groups
// based on Hadoop configuration, as documented at
// https://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-common/GroupsMapping.html
String userName = ss.getUserName();
List<String> groups = null;
if (userName == null) {
userName = "anonymous";
} else {
groups = UserGroupInformation.createRemoteUser(ss.getUserName()).getGroups();
}
MappingInput mi = new MappingInput(userName, groups, ss.getHiveVariables().get("wmpool"), ss.getHiveVariables().get("wmapp"));
WmContext wmContext = ctx.getWmContext();
// jobConf will hold all the configuration for hadoop, tez, and hive
JobConf jobConf = utils.createConfiguration(conf);
// Get all user jars from work (e.g. input format stuff).
String[] allNonConfFiles = work.configureJobConfAndExtractJars(jobConf);
// DAG scratch dir. We get a session from the pool so it may be different from Tez one.
// TODO: we could perhaps reuse the same directory for HiveResources?
Path scratchDir = utils.createTezDir(ctx.getMRScratchDir(), conf);
CallerContext callerContext = CallerContext.create("HIVE", queryPlan.getQueryId(), "HIVE_QUERY_ID", queryPlan.getQueryStr());
perfLogger.PerfLogBegin(CLASS_NAME, PerfLogger.TEZ_GET_SESSION);
session = sessionRef.value = WorkloadManagerFederation.getSession(sessionRef.value, conf, mi, getWork().getLlapMode(), wmContext);
perfLogger.PerfLogEnd(CLASS_NAME, PerfLogger.TEZ_GET_SESSION);
try {
ss.setTezSession(session);
LOG.info("Subscribed to counters: {} for queryId: {}", wmContext.getSubscribedCounters(), wmContext.getQueryId());
// Ensure the session is open and has the necessary local resources.
// This would refresh any conf resources and also local resources.
ensureSessionHasResources(session, allNonConfFiles);
// This is a combination of the jar stuff from conf, and not from conf.
List<LocalResource> allNonAppResources = session.getLocalizedResources();
logResources(allNonAppResources);
Map<String, LocalResource> allResources = DagUtils.createTezLrMap(session.getAppJarLr(), allNonAppResources);
// next we translate the TezWork to a Tez DAG
DAG dag = build(jobConf, work, scratchDir, ctx, allResources);
dag.setCallerContext(callerContext);
// Check isShutdown opportunistically; it's never unset.
if (this.isShutdown) {
throw new HiveException("Operation cancelled");
}
DAGClient dagClient = submit(jobConf, dag, sessionRef);
session = sessionRef.value;
boolean wasShutdown = false;
synchronized (dagClientLock) {
assert this.dagClient == null;
wasShutdown = this.isShutdown;
if (!wasShutdown) {
this.dagClient = dagClient;
}
}
if (wasShutdown) {
closeDagClientOnCancellation(dagClient);
throw new HiveException("Operation cancelled");
}
// finally monitor will print progress until the job is done
TezJobMonitor monitor = new TezJobMonitor(work.getAllWork(), dagClient, conf, dag, ctx);
rc = monitor.monitorExecution();
if (rc != 0) {
this.setException(new HiveException(monitor.getDiagnostics()));
}
// fetch the counters
try {
Set<StatusGetOpts> statusGetOpts = EnumSet.of(StatusGetOpts.GET_COUNTERS);
counters = dagClient.getDAGStatus(statusGetOpts).getDAGCounters();
} catch (Exception err) {
// Don't fail execution due to counters - just don't print summary info
LOG.warn("Failed to get counters. Ignoring, summary info will be incomplete. " + err, err);
counters = null;
}
} finally {
// Note: due to TEZ-3846, the session may actually be invalid in case of some errors.
// Currently, reopen on an attempted reuse will take care of that; we cannot tell
// if the session is usable until we try.
// We return this to the pool even if it's unusable; reopen is supposed to handle this.
wmContext = ctx.getWmContext();
try {
if (sessionRef.value != null) {
sessionRef.value.returnToSessionManager();
}
} catch (Exception e) {
LOG.error("Failed to return session: {} to pool", session, e);
throw e;
}
if (!conf.getVar(HiveConf.ConfVars.TEZ_SESSION_EVENTS_SUMMARY).equalsIgnoreCase("none") && wmContext != null) {
if (conf.getVar(HiveConf.ConfVars.TEZ_SESSION_EVENTS_SUMMARY).equalsIgnoreCase("json")) {
wmContext.printJson(console);
} else if (conf.getVar(HiveConf.ConfVars.TEZ_SESSION_EVENTS_SUMMARY).equalsIgnoreCase("text")) {
wmContext.print(console);
}
}
}
if (LOG.isInfoEnabled() && counters != null && (HiveConf.getBoolVar(conf, HiveConf.ConfVars.TEZ_EXEC_SUMMARY) || Utilities.isPerfOrAboveLogging(conf))) {
for (CounterGroup group : counters) {
LOG.info(group.getDisplayName() + ":");
for (TezCounter counter : group) {
LOG.info(" " + counter.getDisplayName() + ": " + counter.getValue());
}
}
}
} catch (Exception e) {
LOG.error("Failed to execute tez graph.", e);
// rc will be 1 at this point indicating failure.
} finally {
Utilities.clearWork(conf);
// Clear gWorkMap
for (BaseWork w : work.getAllWork()) {
JobConf workCfg = workToConf.get(w);
if (workCfg != null) {
Utilities.clearWorkMapForConf(workCfg);
}
}
if (cleanContext) {
try {
ctx.clear();
} catch (Exception e) {
/*best effort*/
LOG.warn("Failed to clean up after tez job", e);
}
}
// need to either move tmp files or remove them
DAGClient dagClient = null;
synchronized (dagClientLock) {
dagClient = this.dagClient;
this.dagClient = null;
}
// DagClient as such should have no bearing on jobClose.
if (dagClient != null) {
// rc will only be overwritten if close errors out
rc = close(work, rc, dagClient);
}
}
return rc;
}
use of org.apache.hadoop.hive.ql.plan.BaseWork in project hive by apache.
the class TezProgressMonitor method rows.
public List<List<String>> rows() {
try {
List<List<String>> results = new ArrayList<>();
for (BaseWork baseWork : topSortedWork) {
String vertexName = baseWork.getName();
VertexProgress progress = progressCountsMap.get(vertexName);
if (progress != null) {
// Map 1 .......... container SUCCEEDED 7 7 0 0 0 0
results.add(Arrays.asList(getNameWithProgress(vertexName, progress.succeededTaskCount, progress.totalTaskCount), getMode(baseWork), progress.vertexStatus(vertexStatusMap.get(vertexName)), progress.total(), progress.completed(), progress.running(), progress.pending(), progress.failed(), progress.killed()));
}
}
return results;
} catch (Exception e) {
console.printInfo("Getting Progress Bar table rows failed: " + e.getMessage() + " stack trace: " + Arrays.toString(e.getStackTrace()));
}
return Collections.emptyList();
}
use of org.apache.hadoop.hive.ql.plan.BaseWork in project hive by apache.
the class OperatorStatsReaderHook method run.
@Override
public void run(HookContext hookContext) throws Exception {
if (hookContext.getHookType() == HookType.PRE_EXEC_HOOK) {
return;
}
if (hookContext.getHookType() == HookType.POST_EXEC_HOOK && !isCollectOnSuccess()) {
return;
}
HiveConf conf = hookContext.getConf();
QueryPlan plan = hookContext.getQueryPlan();
List<TezTask> rootTasks = Utilities.getTezTasks(plan.getRootTasks());
for (TezTask tezTask : rootTasks) {
List<BaseWork> baseWorks = tezTask.getWork().getAllWork();
for (BaseWork baseWork : baseWorks) {
String vertexName = baseWork.getName();
LOG.debug("Reading runtime statistics for tez vertex task: {}", vertexName);
TezCounters counters = tezTask.getTezCounters();
if (counters != null) {
String groupName = HiveConf.getVar(conf, HiveConf.ConfVars.HIVECOUNTERGROUP);
for (Operator<? extends OperatorDesc> op : baseWork.getAllOperators()) {
String operatorId = op.getOperatorId();
OperatorStats operatorStats = null;
String counterName = Operator.Counter.RECORDS_OUT_OPERATOR.toString() + "_" + operatorId;
TezCounter tezCounter = counters.getGroup(groupName).findCounter(counterName, false);
if (tezCounter != null) {
if (operatorStats == null) {
operatorStats = new OperatorStats(operatorId);
}
operatorStats.setOutputRecords(tezCounter.getValue());
}
if (operatorStats != null) {
((PrivateHookContext) hookContext).getContext().getPlanMapper().link(op, operatorStats);
} else {
LOG.debug("Unable to get statistics for vertex: {} opId: {} groupName: {}", vertexName, operatorId, groupName);
}
}
}
}
}
}
use of org.apache.hadoop.hive.ql.plan.BaseWork in project hive by apache.
the class TestTezTask method testBuildDag.
@Test
public void testBuildDag() throws IllegalArgumentException, IOException, Exception {
DAG dag = task.build(conf, work, path, new Context(conf), DagUtils.createTezLrMap(appLr, null));
for (BaseWork w : work.getAllWork()) {
Vertex v = dag.getVertex(w.getName());
assertNotNull(v);
List<Vertex> outs = v.getOutputVertices();
for (BaseWork x : work.getChildren(w)) {
boolean found = false;
for (Vertex u : outs) {
if (u.getName().equals(x.getName())) {
found = true;
break;
}
}
assertTrue(found);
}
}
}
use of org.apache.hadoop.hive.ql.plan.BaseWork in project hive by apache.
the class LlapRecordReader method findMapWork.
private static MapWork findMapWork(JobConf job) throws HiveException {
String inputName = job.get(Utilities.INPUT_NAME, null);
if (LOG.isDebugEnabled()) {
LOG.debug("Initializing for input " + inputName);
}
String prefixes = job.get(DagUtils.TEZ_MERGE_WORK_FILE_PREFIXES);
if (prefixes != null && !StringUtils.isBlank(prefixes)) {
// So, we don't use the below code that would get the correct MapWork. See HIVE-16985.
return null;
}
BaseWork work = null;
// HIVE-16985: try to find the fake merge work for SMB join, that is really another MapWork.
if (inputName != null) {
if (prefixes == null || !Lists.newArrayList(prefixes.split(",")).contains(inputName)) {
inputName = null;
}
}
if (inputName != null) {
work = Utilities.getMergeWork(job, inputName);
}
if (work == null || !(work instanceof MapWork)) {
work = Utilities.getMapWork(job);
}
return (MapWork) work;
}
Aggregations