Github user vanzin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/4688#discussion_r25978621
  
    --- Diff: 
yarn/src/main/scala/org/apache/spark/deploy/yarn/YarnSparkHadoopUtil.scala ---
    @@ -82,6 +100,179 @@ class YarnSparkHadoopUtil extends SparkHadoopUtil {
         if (credentials != null) credentials.getSecretKey(new Text(key)) else 
null
       }
     
    +  private[spark] override def scheduleLoginFromKeytab(): Unit = {
    +    sparkConf.getOption("spark.yarn.principal").foreach { principal =>
    +      val keytab = sparkConf.get("spark.yarn.keytab")
    +      val delegationTokenRenewerRunnable =
    +        new Runnable {
    +          override def run(): Unit = {
    +            renewCredentials(principal, keytab)
    +            delegationTokenRenewer.schedule(
    +              this, (0.75 * (getLatestValidity - 
System.currentTimeMillis())).toLong,
    +              TimeUnit.MILLISECONDS)
    +          }
    +        }
    +      val timeToRenewal = (0.75 * (getLatestValidity - 
System.currentTimeMillis())).toLong
    +      delegationTokenRenewer.schedule(
    +        delegationTokenRenewerRunnable, timeToRenewal, 
TimeUnit.MILLISECONDS)
    +    }
    +  }
    +
    +  private def renewCredentials(principal: String, keytab: String): Unit = {
    +    if (!loggedInViaKeytab) {
    +      // Keytab is copied by YARN to the working directory of the AM, so 
full path is
    +      // not needed.
    +      loggedInUGI = UserGroupInformation.loginUserFromKeytabAndReturnUGI(
    +        principal, keytab)
    +      loggedInViaKeytab = true
    +    }
    +    val nns = getNameNodesToAccess(sparkConf)
    +    val newCredentials = loggedInUGI.getCredentials
    +    obtainTokensForNamenodes(nns, conf, newCredentials)
    +    val remoteFs = FileSystem.get(conf)
    +    val nextSuffix = lastCredentialsFileSuffix + 1
    +    val tokenPathStr =
    +      sparkConf.get("spark.yarn.credentials.file") + "-" + nextSuffix
    +    val tokenPath = new Path(tokenPathStr)
    +    val tempTokenPath = new Path(tokenPathStr + ".tmp")
    +    val stream = Option(remoteFs.create(tempTokenPath, true))
    +    try {
    +      stream.foreach { s =>
    +        newCredentials.writeTokenStorageToStream(s)
    +        s.hflush()
    +        s.close()
    +        remoteFs.rename(tempTokenPath, tokenPath)
    +      }
    +    } catch {
    +      case e: Exception =>
    --- End diff --
    
    Do you really want to ignore the exception? If so, add a comment explaining 
why, and at least log it so the info is not lost.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to