Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Exactly-Once in Apache Flink

Buzzvil
January 05, 2022

Exactly-Once in Apache Flink

By Raf

Buzzvil

January 05, 2022
Tweet

More Decks by Buzzvil

Other Decks in Programming

Transcript

  1. Exactly-Once in Apache Flink 1
    Exactly-Once in Apache Flink
    ToC
    Flink
    exactly-once
    는 어떻게 달성할 수 있을까? w/ message queue
    Flink
    에서 exactly-once
    어떻게 보장하는가?
    Apache Flink
    Overview
    https://nightlies.apache.org/flink/flink-docs-release-1.14/docs/learn-flink/overview/
    MapReduce
    의 확장팩(Spark)
    의 확장팩
    Stateful stream processing
    MapReduce (2004)
    https://static.googleusercontent.com/media/research.google.com/ko//archive/mapreduce-osdi04.pdf
    MapReduce
    가 생긴 계기
    Over the past five years, the authors and many others at Google have implemented hundreds of
    special-purpose computations that process large amounts of raw data, such as crawled documents,
    web request logs, etc., to compute various kinds of derived data, such as inverted indices, various

    View Slide

  2. Exactly-Once in Apache Flink 2
    representations of the graph structure of web documents, summaries of the number of pages crawled
    per host, the set of most frequent queries in a given day, etc.
    Most such computations are conceptually straightforward.
    However, the input data is usually large and the computations have to be distributed across hundreds
    or thousands of machines in order to finish in a reasonable amount of time.
    The issues of how to parallelize the computation, distribute the data, and handle failures conspire to
    obscure the original simple computation with large amounts of complex code to deal with these issues.
    As a reaction to this complexity, we designed a new abstraction that allows us to express the simple
    computations we were trying to perform but hides the messy details of parallelization, fault-tolerance,
    data distribution and load balancing in a library.
    We realized that most of our computations involved applying a map operation to each logical “record”
    in our input in order to compute a set of intermediate key/value pairs, and then applying a reduce
    operation to all the values that shared the same key, in order to combine the derived data
    appropriately.
    Architecture
    https://nightlies.apache.org/flink/flink-docs-release-1.14/docs/concepts/flink-architecture/

    View Slide

  3. Exactly-Once in Apache Flink 3
    Realtime Exactly-Once Ad Event Processing at Uber
    https://eng.uber.com/real-time-exactly-once-ad-event-processing/
    광고주에게 정확한 광고 성과를 보여줘야 한다. data loss
    는 광고 성과를 낮게 보여준다
    event
    를 중복집계해서는 안된다.
    광고성과를 부풀려서 보여주게 된다
    attribution
    또한 100%
    정확해야 한다

    View Slide

  4. Exactly-Once in Apache Flink 4
    Flink
    는 exactly-once
    를 지원하고, consumer service

    read_commited message
    만 읽으면 end-to-end exactly-once
    완성
    attribution
    을 넣으려면 data enrichment
    가 필요하므로 외부 db
    에서 읽는 경우도 있음
    Exactly-Once
    https://www.confluent.io/blog/exactly-once-semantics-are-possible-heres-how-apache-kafka-does-it/
    Exactly-Once
    고려사항
    Broker(Kafka) Failure
    N replication
    을 지원하고, replication protocol
    이 exactly-once
    를 지원하므로, N-1 failure
    에서도 durable
    하다
    failed put
    network failure
    로인해 broker
    가 message
    를 못받았거나, publisher
    가 ack
    를 못받았을경우 retry
    로 인해 문제가 발생할 수 있다
    client(producer/consumer) failure
    producer
    의 failure
    는 message
    가 날아갈수밖에없지만, client
    는 save point
    에서 다시 시작할 수 있어야 한다.
    Exactly-Once in Kafka
    Idempotence: exactly-once in order semantics per partition
    producer send operation
    을 idempotent
    하게 만들었음. message
    에 sequence number
    를 남겨 idempotency
    보장

    View Slide

  5. Exactly-Once in Apache Flink 5
    Transactions: Atomic writes across multiple partitions
    transaction
    을 통해 atomicity
    지원
    Exactly-once stream processing - consumer ?????????? Flink
    kafka streams API
    에서 stream processing
    을 하면 exactly-once
    를 지원한다 - java
    하지만 go/python
    에서 streams API
    는 없음
    Exactly-Once Processing in Flink
    checkpoint barrier
    를 datasource channel
    에 주입
    task
    들은 barrier
    를 받을때마다 state backend
    에 현재 snapshot
    을 저장
    sink task
    는 Kafka
    에 pre-commit

    View Slide

  6. Exactly-Once in Apache Flink 6
    모든 pre-commit
    이 완료되면 jobmanager
    는 모든 task
    에게 pre-commit
    이 완료되었음을 전달
    sink task
    는 commit
    을 호출
    그 다음의 consumer
    는 commit
    된 message
    를 읽어갈 수 있음
    Chandy-Lamport’s global snapshot algorithm
    http://composition.al/blog/2019/04/26/an-example-run-of-the-chandy-lamport-snapshot-algorithm/
    distributed system
    에서 asynchronous global snapshot
    을 만드는 알고리즘
    snapshot
    을 생성하는동안 program
    이 멈춰있지 않아도 됨 (asynchronous)
    master node
    가 없음 - spof
    에서 자유로워진다
    1. :
    독립적으로 실행되는 프로세스
    2. dot:
    이벤트 발생
    3.
    화살표: process
    간 이벤트 전달
    4. :
    에서 로 이벤트를 전달하는 채널
    Pi
    Cji
    Pj
    Pi

    View Slide

  7. Exactly-Once in Apache Flink 7
    에서 B
    이벤트가 끝난 직후 스냅샷을 생성하라고 요청
    barrier(marker message)
    를 다른 process
    에게 전달 (
    주황점선), barrier
    는 speical event
    로, snapshot
    에 찍히는 이벤트의 대상은 아
    니다
    incoming channel ,
    에 대해 레코딩 시작
    P1
    P1
    P1
    C21
    C31
    P3

    View Slide

  8. Exactly-Once in Apache Flink 8
    은 로부터 barrier
    를 받아서 snapshot
    을 캡처
    이 했던것과 비슷 한일을하지만,
    에서 barrier
    를 받았으므로 채널을 레코딩할 필요없이 empty
    로 저장
    에게서 barrier
    를 받음
    채널 레코딩 끝내고 상태 저장
    P3
    P1
    P1
    P1
    C13
    P1
    P3
    C31
    P2

    View Slide

  9. Exactly-Once in Apache Flink 9
    에게서 barrier
    받음
    에서 barrier
    받음
    에서 barrier
    받음
    채널에 들어온 이벤트
    [H->D]
    가 있으므로 이 상태를 저장
    P3
    P2
    P1
    P1
    P2
    C21

    View Slide

  10. Exactly-Once in Apache Flink 10
    에서 barrier
    받음
    final state
    스냅샷을 찍은 시점 기준으로 happened before event
    가 snapshot
    에 포함되는것을 보장함
    causal consistency
    eventual consistency << causal consistency << sequential consistency
    P3
    P2

    View Slide

  11. Exactly-Once in Apache Flink 11
    Flink’s checkpointing algorithm
    Lightweight Asynchronous Snapshots for Distributed Dataflows
    https://arxiv.org/abs/1506.08603
    Flink
    의 dataflow
    와 chandy-lamport algorithm
    의 constraint
    와 다른점
    dataflow
    는 directed graph
    형태, chandy-lamport
    는 모든 Process
    간 자유롭게 통신 가능하다
    바뀌는 제약조건
    source
    가 되는 task
    들에게 barrier
    를 주입해줘야 한다, chandy-lamport
    는 어떤 process
    에서부터 주입해도 문제 없음
    dataflow
    가 directed acyclic graph
    인 경우,
    채널이 단방향이 되므로 채널 레코딩이 필요없어진다
    cycle
    이 생기는경우에 대한것도 위 링크에 있긴함

    View Slide

  12. Exactly-Once in Apache Flink 12
    요약
    Flink
    MapReduce - Spark
    의 다음 세대 (native event stream processing)
    MapReduce:
    많은 데이터 프로세싱에 대해 infrastructure
    를 떼어내고 library
    를 제공해주어 쉽게 scale-out
    이 가능한 시스템
    Spark: Mapreduce
    가 disk IO
    를 바탕으로 돌아가는 것을 개선하여 in-memory
    로 처리
    Flink: Spark
    가 stream processing
    이지만 micro batch
    인 결점을 보완하여 실제로 event
    단위로 동작하도록 만든 real-time event
    processing framework
    Exacty-Once guarantee
    유저에게 정확한 성과를 보여주기 위해선 exactly-once
    가 필수
    정상 상황에선 문제 없다, network failure
    에서도 idempotent operation
    을 만들면 문제없다,
    하지만 failure
    상황에서 시스템이 어떻게
    동작하냐에 따라서 보장여부가 결정된다
    Flink
    의 Exactly-Once
    two-phase commit
    으로 동작
    chandy-lamport snapshot based algorithm

    View Slide