@ -194,8 +194,7 @@ class LogManager(logDirs: Array[File],
Some ( lock )
Some ( lock )
} catch {
} catch {
case e : IOException =>
case e : IOException =>
error ( s" Disk error while locking directory $dir " , e )
logDirFailureChannel . maybeAddOfflineLogDir ( dir . getAbsolutePath , s" Disk error while locking directory $dir " , e )
logDirFailureChannel . maybeAddLogFailureEvent ( dir . getAbsolutePath )
None
None
}
}
}
}
@ -214,9 +213,11 @@ class LogManager(logDirs: Array[File],
logStartOffset = logStartOffset ,
logStartOffset = logStartOffset ,
recoveryPoint = logRecoveryPoint ,
recoveryPoint = logRecoveryPoint ,
maxProducerIdExpirationMs = maxPidExpirationMs ,
maxProducerIdExpirationMs = maxPidExpirationMs ,
producerIdExpirationCheckIntervalMs = LogManager . ProducerIdExpirationCheckIntervalMs ,
scheduler = scheduler ,
scheduler = scheduler ,
time = time ,
time = time ,
brokerTopicStats = brokerTopicStats )
brokerTopicStats = brokerTopicStats ,
logDirFailureChannel = logDirFailureChannel )
if ( logDir . getName . endsWith ( Log . DeleteDirSuffix ) ) {
if ( logDir . getName . endsWith ( Log . DeleteDirSuffix ) ) {
this . logsToBeDeleted . add ( current )
this . logsToBeDeleted . add ( current )
@ -237,7 +238,7 @@ class LogManager(logDirs: Array[File],
info ( "Loading logs." )
info ( "Loading logs." )
val startMs = time . milliseconds
val startMs = time . milliseconds
val threadPools = ArrayBuffer . empty [ ExecutorService ]
val threadPools = ArrayBuffer . empty [ ExecutorService ]
val offlineDirs = ArrayBuffer . empty [ String ]
val offlineDirs = ArrayBuffer . empty [ ( String , IOException ) ]
val jobs = mutable . Map . empty [ File , Seq [ Future [ _ ] ] ]
val jobs = mutable . Map . empty [ File , Seq [ Future [ _ ] ] ]
for ( dir <- liveLogDirs ) {
for ( dir <- liveLogDirs ) {
@ -283,7 +284,7 @@ class LogManager(logDirs: Array[File],
loadLogs ( logDir , recoveryPoints , logStartOffsets )
loadLogs ( logDir , recoveryPoints , logStartOffsets )
} catch {
} catch {
case e : IOException =>
case e : IOException =>
offlineDirs . append ( dir . getAbsolutePath )
offlineDirs . append ( ( dir . getAbsolutePath , e ) )
error ( "Error while loading log dir " + dir . getAbsolutePath , e )
error ( "Error while loading log dir " + dir . getAbsolutePath , e )
}
}
}
}
@ -291,7 +292,7 @@ class LogManager(logDirs: Array[File],
jobs ( cleanShutdownFile ) = jobsForDir . map ( pool . submit )
jobs ( cleanShutdownFile ) = jobsForDir . map ( pool . submit )
} catch {
} catch {
case e : IOException =>
case e : IOException =>
offlineDirs . append ( dir . getAbsolutePath )
offlineDirs . append ( ( dir . getAbsolutePath , e ) )
error ( "Error while loading log dir " + dir . getAbsolutePath , e )
error ( "Error while loading log dir " + dir . getAbsolutePath , e )
}
}
}
}
@ -303,11 +304,13 @@ class LogManager(logDirs: Array[File],
cleanShutdownFile . delete ( )
cleanShutdownFile . delete ( )
} catch {
} catch {
case e : IOException =>
case e : IOException =>
offlineDirs . append ( cleanShutdownFile . getParent )
offlineDirs . append ( ( cleanShutdownFile . getParent , e ) )
error ( s" Error while deleting the clean shutdown file $cleanShutdownFile " , e )
error ( s" Error while deleting the clean shutdown file $cleanShutdownFile " , e )
}
}
}
}
offlineDirs . foreach ( logDirFailureChannel . maybeAddLogFailureEvent )
offlineDirs . foreach { case ( dir , e ) =>
logDirFailureChannel . maybeAddOfflineLogDir ( dir , s" Error while deleting the clean shutdown file in dir $dir " , e )
}
} catch {
} catch {
case e : ExecutionException => {
case e : ExecutionException => {
error ( "There was an error in one of the threads during logs loading: " + e . getCause )
error ( "There was an error in one of the threads during logs loading: " + e . getCause )
@ -500,8 +503,7 @@ class LogManager(logDirs: Array[File],
this . recoveryPointCheckpoints . get ( dir ) . foreach ( _ . write ( recoveryPoints . get . mapValues ( _ . recoveryPoint ) ) )
this . recoveryPointCheckpoints . get ( dir ) . foreach ( _ . write ( recoveryPoints . get . mapValues ( _ . recoveryPoint ) ) )
} catch {
} catch {
case e : IOException =>
case e : IOException =>
error ( s" Disk error while writing to recovery point file in directory $dir " , e )
logDirFailureChannel . maybeAddOfflineLogDir ( dir . getAbsolutePath , s" Disk error while writing to recovery point file in directory $dir " , e )
logDirFailureChannel . maybeAddLogFailureEvent ( dir . getAbsolutePath )
}
}
}
}
}
}
@ -518,8 +520,7 @@ class LogManager(logDirs: Array[File],
) )
) )
} catch {
} catch {
case e : IOException =>
case e : IOException =>
error ( s" Disk error while writing to logStartOffset file in directory $dir " , e )
logDirFailureChannel . maybeAddOfflineLogDir ( dir . getAbsolutePath , s" Disk error while writing to logStartOffset file in directory $dir " , e )
logDirFailureChannel . maybeAddLogFailureEvent ( dir . getAbsolutePath )
}
}
}
}
}
}
@ -555,9 +556,12 @@ class LogManager(logDirs: Array[File],
logStartOffset = 0L ,
logStartOffset = 0L ,
recoveryPoint = 0L ,
recoveryPoint = 0L ,
maxProducerIdExpirationMs = maxPidExpirationMs ,
maxProducerIdExpirationMs = maxPidExpirationMs ,
producerIdExpirationCheckIntervalMs = LogManager . ProducerIdExpirationCheckIntervalMs ,
scheduler = scheduler ,
scheduler = scheduler ,
time = time ,
time = time ,
brokerTopicStats = brokerTopicStats )
brokerTopicStats = brokerTopicStats ,
logDirFailureChannel = logDirFailureChannel )
logs . put ( topicPartition , log )
logs . put ( topicPartition , log )
info ( "Created log for partition [%s,%d] in %s with properties {%s}."
info ( "Created log for partition [%s,%d] in %s with properties {%s}."
@ -568,8 +572,9 @@ class LogManager(logDirs: Array[File],
log
log
} catch {
} catch {
case e : IOException =>
case e : IOException =>
logDirFailureChannel . maybeAddLogFailureEvent ( dataDir . getAbsolutePath )
val msg = s" Error while creating log for $topicPartition in dir ${ dataDir . getAbsolutePath } "
throw new KafkaStorageException ( s" Error while creating log for $topicPartition in dir ${ dataDir . getAbsolutePath } " , e )
logDirFailureChannel . maybeAddOfflineLogDir ( dataDir . getAbsolutePath , msg , e )
throw new KafkaStorageException ( msg , e )
}
}
}
}
}
}
@ -635,8 +640,9 @@ class LogManager(logDirs: Array[File],
}
}
} catch {
} catch {
case e : IOException =>
case e : IOException =>
logDirFailureChannel . maybeAddLogFailureEvent ( removedLog . dir . getParent )
val msg = s" Error while deleting $topicPartition in dir ${ removedLog . dir . getParent } . "
throw new KafkaStorageException ( s" Error while deleting $topicPartition in dir ${ removedLog . dir . getParent } . " , e )
logDirFailureChannel . maybeAddOfflineLogDir ( removedLog . dir . getParent , msg , e )
throw new KafkaStorageException ( msg , e )
}
}
} else if ( offlineLogDirs . nonEmpty ) {
} else if ( offlineLogDirs . nonEmpty ) {
throw new KafkaStorageException ( "Failed to delete log for " + topicPartition + " because it may be in one of the offline directories " + offlineLogDirs . mkString ( "," ) )
throw new KafkaStorageException ( "Failed to delete log for " + topicPartition + " because it may be in one of the offline directories " + offlineLogDirs . mkString ( "," ) )
@ -727,6 +733,9 @@ class LogManager(logDirs: Array[File],
}
}
object LogManager {
object LogManager {
val ProducerIdExpirationCheckIntervalMs = 10 * 60 * 1000
def apply ( config : KafkaConfig ,
def apply ( config : KafkaConfig ,
initialOfflineDirs : Seq [ String ] ,
initialOfflineDirs : Seq [ String ] ,
zkUtils : ZkUtils ,
zkUtils : ZkUtils ,