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

    https://github.com/apache/spark/pull/2065#discussion_r16758798
  
    --- Diff: 
external/flume/src/main/scala/org/apache/spark/streaming/flume/FlumeBatchFetcher.scala
 ---
    @@ -0,0 +1,160 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.spark.streaming.flume
    +
    +import scala.collection.JavaConversions._
    +import scala.collection.mutable.ArrayBuffer
    +
    +import com.google.common.base.Throwables
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.streaming.flume.sink._
    +
    +private[flume] class FlumeBatchFetcher(receiver: FlumePollingReceiver) 
extends Runnable with
    +  Logging {
    +
    +  def run(): Unit = {
    +    while (!receiver.isStopped()) {
    +      val connection = receiver.getConnections.poll()
    +      val client = connection.client
    +      var batchReceived = false
    +      var seq: CharSequence = null
    +      try {
    +        getBatch(client) match {
    +          case Some(eventBatch) =>
    +            batchReceived = true
    +            seq = eventBatch.getSequenceNumber
    +            val events = toSparkFlumeEvents(eventBatch.getEvents)
    +            if (store(events)) {
    +              sendAck(client, seq)
    +            } else {
    +              sendNack(batchReceived, client, seq)
    +            }
    +          case None =>
    +        }
    +      } catch {
    +        case e: Exception =>
    +          Throwables.getRootCause(e) match {
    +            // If the cause was an InterruptedException, then check if the 
receiver is stopped -
    +            // if yes, just break out of the loop. Else send a Nack and 
log a warning.
    +            // In the unlikely case, the cause was not an Exception,
    +            // then just throw it out and exit.
    +            case interrupted: InterruptedException =>
    +              if (!receiver.isStopped()) {
    +                logWarning("Interrupted while receiving data from Flume", 
interrupted)
    +                sendNack(batchReceived, client, seq)
    +              }
    +            case exception: Exception =>
    +              logWarning("Error while receiving data from Flume", 
exception)
    +              sendNack(batchReceived, client, seq)
    +          }
    +      } finally {
    +        receiver.getConnections.add(connection)
    +      }
    +    }
    +  }
    +
    +  /**
    +   * Gets a batch of events from the specified client. This method does 
not handle any exceptions
    +   * which will be propogated to the caller.
    +   * @param client Client to get events from
    +   * @return [[Some]] which contains the event batch if Flume sent any 
events back, else [[None]]
    +   */
    +  private def getBatch(client: SparkFlumeProtocol.Callback): 
Option[EventBatch] = {
    +    val eventBatch = client.getEventBatch(receiver.getMaxBatchSize)
    +    if (!SparkSinkUtils.isErrorBatch(eventBatch)) {
    +      // No error, proceed with processing data
    +      logDebug("Received batch of " + eventBatch.getEvents.size + " events 
with sequence number: "
    --- End diff --
    
    nit: With so many clauses in the string, its better to use string 
interpolation.
    `logDebug(s"Received batch of ${eventBatch.getEvents.size} events with 
sequence number: ${eventBatch.getSequenceNumber}")`


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to