Skip to content

Commit

Permalink
[LI-HOTFIX] Be ultra lazy in loading lazy indices during index deleti…
Browse files Browse the repository at this point in the history
…on. (#68)

TICKET =
LI_DESCRIPTION = Avoid initialization of logSegment indices during deleteIfExists in case the logSegment indices have not been initialized before. This helps with overall resource usage of Kafka server, as well as prevents flaky errors while deleting log segments due to java.io.IOException: No such file or directory.

EXIT_CRITERIA = MANUAL [""]
  • Loading branch information
efeg authored Jan 7, 2020
1 parent 40065ac commit da84506
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions core/src/main/scala/kafka/log/LazyIndex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class LazyIndex[T <: AbstractIndex] private (@volatile private var indexWrapper:

/**
* Delete the index file that backs this index if exists.
* This method ensures that if the index file has already been closed, it will not be recreated as a side effect.
* This method ensures that if the index file has already been closed or in case it has not been created before,
* it will not be recreated as a side effect.
*
* @throws IOException if deletion fails due to an I/O error
* @return `true` if the file was deleted by this method; `false` if the file could not be deleted because it did
Expand All @@ -98,8 +99,14 @@ class LazyIndex[T <: AbstractIndex] private (@volatile private var indexWrapper:
def deleteIfExists(): Boolean = {
if (isClosed)
Files.deleteIfExists(file.toPath)
else
get.deleteIfExists()
else {
inLock(lock) {
indexWrapper match {
case indexValue: IndexValue[T] => indexValue.index.deleteIfExists()
case _: IndexFile => Files.deleteIfExists(file.toPath)
}
}
}
}

/**
Expand Down

0 comments on commit da84506

Please sign in to comment.