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

    https://github.com/apache/spark/pull/4688#discussion_r25971108
  
    --- 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))
    --- End diff --
    
    The reason I am being null-safe is that we have seen this happen where the 
create method sometimes does not throw, but returns null. I believe this may 
have been a Hadoop bug, best to avoid it.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to