You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@s2graph.apache.org by "Chanwoo Yoon (Jira)" <ji...@apache.org> on 2019/11/15 09:06:00 UTC

[jira] [Created] (S2GRAPH-255) Enable incremental processing of s2jobs

Chanwoo Yoon created S2GRAPH-255:
------------------------------------

             Summary: Enable incremental processing of s2jobs
                 Key: S2GRAPH-255
                 URL: https://issues.apache.org/jira/browse/S2GRAPH-255
             Project: S2Graph
          Issue Type: Improvement
          Components: s2jobs
            Reporter: Chanwoo Yoon


h2. Background

S2jobs, in many use cases are batch processing multiple sources each time, reading every source every time when the job launches. But considering that each source has different update intervals, such processing has following disadvantages.
 - Waste of resource: Source that hasn't been updated also gets processed
 - Waiting between the time interval: Updated source should wait the fixed schedule to get processed.
 - Error vulnerable: Specifying time partitions such as
{code:java}
path/date_id=yyyy-mm-dd{code}
as path of each sources was the common way to construct data pipeline using s2jobs. Leaving the possibility of broken pipeline when such path hasn't been created or updated.

Somehow *decoupling job schedule from sources update interval* and *incrementally processing each sources* can be an solution to these problems
h2. Idea

Having assumption that each jobs name has global uniqueness and each jobs sources can be identified by its name, (and also considering each source can have multiple paths) we can form an unique unit of transaction with the form as following.
{code:java}
 job_name, source_name, path (or an hive table) {code}
This unit in implementation is named *TxId*(transaction id).

With TxId, we can specify each paths the job need to read and record some offset following it with the form below.
{code:java}
 job_name, source_name, path (or an hive table), commit_id {code}
This form in implementation is named *TxLog* and we record the offset of each TxId at field commit_id.

Having TxLog,
 - Step 1) program can specify which paths should be read at current interval by comparing the given path(or its subdirectory/partition) with corresponding TxLog
 - Step 2) Then the program can rephrase each sources to read only the soucres/paths updated.
 - Step 3) After job gets finished, the program should finally write TxLog of each TxId.

h2. Implementation: TransactionUtil
h3. TxId and TxLog
{code:java}
case class TxId(jobName: String,
                appName: String,
                sourceName: String,
                path: String)

case class TxLog(id: Long,
                 txId: TxId,
                 commitType: CommitType,
                 commitId: String,
                 lastModifiedAt: Long,
                 enabled: Option[Boolean])               
{code}
h3. TransactionUtil Interface
{code:java}
trait TransactionUtil {

  val config: Config
  /**
    * read last committed transaction using context provided from spark session.
    *
    * @param txId
    * @return
    */
  def readTx(txId: TxId): Option[TxLog]

  /**
    * write latest target as last committed transaction
    *
    * @param txId
    * @param latestTarget
    */
  def writeTx(txLog: TxLog): Unit
}
{code}
h3. Usage

org.apache.s2graph.s2jobs.JobLauncher.scala
{code:java}
  def main(args: Array[String]): Unit = {

    val options = parseArguments(args)
    logger.info(s"Job Options : ${options}")

    val jobDescription = JobDescription(getConfig(options))

    val ss = SparkSession
      .builder()
      .appName(s"${jobDescription.name}")
      .config("spark.driver.maxResultSize", "20g")
      .enableHiveSupport()
      .getOrCreate()

    ...

    if (options.incremental) {
      val config = ConfigFactory.load()
      val txUtil = DBTransactionUtil(config)

      TransactionUtil.withTx(ss, options.name, jobDescription, txUtil)(_.run())
    } else {
      val job = new Job(ss, jobDescription)

      job.run()
    }
  }
{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)