rabbah commented on a change in pull request #2878: Streamingly read user-logs.
URL:
https://github.com/apache/incubator-openwhisk/pull/2878#discussion_r152796572
##########
File path:
core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerClientWithFileAccess.scala
##########
@@ -135,62 +139,32 @@ class DockerClientWithFileAccess(
.map(_.fields("State").asJsObject.fields("OOMKilled").convertTo[Boolean])
.recover { case _ => false }
- // See extended trait for description
- def rawContainerLogs(containerId: ContainerId, fromPos: Long):
Future[ByteBuffer] = Future {
- blocking { // Needed due to synchronous file operations
- var fis: FileInputStream = null
- try {
- val file = containerLogFile(containerId)
- val size = file.length
-
- fis = new FileInputStream(file)
- val channel = fis.getChannel().position(fromPos)
-
- // Buffer allocation may fail if the log file is too large to hold in
memory or
- // too few space is left on the heap, respectively.
- var remainingBytes = (size - fromPos).toInt
- val readBuffer = ByteBuffer.allocate(remainingBytes)
-
- while (remainingBytes > 0) {
- val readBytes = channel.read(readBuffer)
- if (readBytes > 0) {
- remainingBytes -= readBytes
- } else if (readBytes < 0) {
- remainingBytes = 0
- }
- }
-
- readBuffer
- } catch {
- case e: Exception =>
- throw new IOException(s"rawContainerLogs failed on ${containerId}",
e)
- } finally {
- if (fis != null) fis.close()
+ override def rawContainerLogs(containerId: ContainerId,
+ fromPos: Long,
+ pollInterval: Option[FiniteDuration]):
AkkaSource[ByteString, Any] =
+ try {
+ // If there is no waiting interval, we can end the stream early by
reading just what is there from file.
+ pollInterval match {
+ case Some(interval) =>
FileTailSource(containerLogFile(containerId).toPath, 8192, fromPos, interval)
+ case None =>
FileIO.fromPath(containerLogFile(containerId).toPath, 8192, fromPos)
Review comment:
lift 8K chunk size to a field const?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services