Skip to content

Commit

Permalink
[MINOR] Fix inconsistency log level among delegation token providers
Browse files Browse the repository at this point in the history
There's some inconsistency for log level while logging error messages in
delegation token providers. (DEBUG, INFO, WARNING)

Given that failing to obtain token would often crash the query, I guess
it would be nice to set higher log level for error log messages.
  • Loading branch information
HeartSaVioR committed Dec 31, 2018
1 parent 240817b commit 0fc5b71
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private[security] class HBaseDelegationTokenProvider
creds.addToken(token.getService, token)
} catch {
case NonFatal(e) =>
logDebug(s"Failed to get token from service $serviceName", e)
logWarning(s"Failed to get token from service $serviceName", e)
}

None
Expand All @@ -71,7 +71,7 @@ private[security] class HBaseDelegationTokenProvider
confCreate.invoke(null, conf).asInstanceOf[Configuration]
} catch {
case NonFatal(e) =>
logDebug("Fail to invoke HBaseConfiguration", e)
logWarning("Fail to invoke HBaseConfiguration", e)
conf
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.apache.spark.deploy.security

import scala.collection.JavaConverters._
import scala.util.Try
import scala.util.control.NonFatal

import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.FileSystem
Expand All @@ -44,28 +45,34 @@ private[deploy] class HadoopFSDelegationTokenProvider(fileSystems: () => Set[Fil
hadoopConf: Configuration,
sparkConf: SparkConf,
creds: Credentials): Option[Long] = {
val fsToGetTokens = fileSystems()
val fetchCreds = fetchDelegationTokens(getTokenRenewer(hadoopConf), fsToGetTokens, creds)
try {
val fsToGetTokens = fileSystems()
val fetchCreds = fetchDelegationTokens(getTokenRenewer(hadoopConf), fsToGetTokens, creds)

// Get the token renewal interval if it is not set. It will only be called once.
if (tokenRenewalInterval == null) {
tokenRenewalInterval = getTokenRenewalInterval(hadoopConf, sparkConf, fsToGetTokens)
}
// Get the token renewal interval if it is not set. It will only be called once.
if (tokenRenewalInterval == null) {
tokenRenewalInterval = getTokenRenewalInterval(hadoopConf, sparkConf, fsToGetTokens)
}

// Get the time of next renewal.
val nextRenewalDate = tokenRenewalInterval.flatMap { interval =>
val nextRenewalDates = fetchCreds.getAllTokens.asScala
.filter(_.decodeIdentifier().isInstanceOf[AbstractDelegationTokenIdentifier])
.map { token =>
val identifier = token
.decodeIdentifier()
.asInstanceOf[AbstractDelegationTokenIdentifier]
identifier.getIssueDate + interval
}
if (nextRenewalDates.isEmpty) None else Some(nextRenewalDates.min)
}
// Get the time of next renewal.
val nextRenewalDate = tokenRenewalInterval.flatMap { interval =>
val nextRenewalDates = fetchCreds.getAllTokens.asScala
.filter(_.decodeIdentifier().isInstanceOf[AbstractDelegationTokenIdentifier])
.map { token =>
val identifier = token
.decodeIdentifier()
.asInstanceOf[AbstractDelegationTokenIdentifier]
identifier.getIssueDate + interval
}
if (nextRenewalDates.isEmpty) None else Some(nextRenewalDates.min)
}

nextRenewalDate
nextRenewalDate
} catch {
case NonFatal(e) =>
logWarning(s"Failed to get token from service $serviceName", e)
None
}
}

override def delegationTokensRequired(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private[spark] class HiveDelegationTokenProvider
new HiveConf(hadoopConf, classOf[HiveConf])
} catch {
case NonFatal(e) =>
logDebug("Fail to create Hive Configuration", e)
logWarning("Fail to create Hive Configuration", e)
hadoopConf
case e: NoClassDefFoundError =>
logWarning(classNotFoundErrorStr)
Expand Down Expand Up @@ -104,7 +104,7 @@ private[spark] class HiveDelegationTokenProvider
None
} catch {
case NonFatal(e) =>
logDebug(s"Failed to get token from service $serviceName", e)
logWarning(s"Failed to get token from service $serviceName", e)
None
case e: NoClassDefFoundError =>
logWarning(classNotFoundErrorStr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private[security] class KafkaDelegationTokenProvider
return Some(nextRenewalDate)
} catch {
case NonFatal(e) =>
logInfo(s"Failed to get token from service $serviceName", e)
logWarning(s"Failed to get token from service $serviceName", e)
}
None
}
Expand Down

0 comments on commit 0fc5b71

Please sign in to comment.