SlideShare una empresa de Scribd logo
1 de 16
Descargar para leer sin conexión
© 2019 Ververica
Automatic State Cleanup in Apache Flink
Deep Dive into State Time-To-Live (TTL)
Andrey Zagrebin, Software Engineer and Apache Flink Committer
Flink Forward Europe 2019
© 2019 Ververica
Agenda for the talk
• Assumptions about the audience
2
• State TTL feature
─ Why?
─ What is it?
─ How to use it?
• Tech deep dive
─ General idea: State Wrappers
─ Background Cleanup
• Concurrent background process
• Incremental Heap Backend cleanup
• TTL Compaction filter for RocksDB
• Future roadmap & Useful links
© 2019 Ververica
Assumptions about the audience
• Familiar with Apache Flink and its Keyed Stateful Processing
3
• OR think of the Flink State as a local KV store with a single-threaded
access
• Two types of Flink State storage backed by
─ in-memory Java object map (heap, non-serialized)
─ RocksDB embedded KV store (native memory + local drive, serialized)
© 2019 Ververica
State TTL feature
(since Flink 1.6, improved 1.8)
© 2019 Ververica
State TTL feature: Motivation
5
• Save space:
do not store what is not used
Implement some cleanup
on the Application level
OR …
Make Flink
take care about cleanup
under the hood
• Data privacy:
access for limited amount of time
e.g. using Flink Timers
which are separate state
Trade off: storage size implications!
Clean
up?
© 2019 Ververica
State TTL feature: Workflow
6
KEY VALUE Flink
State
Start
TTL timer
KEY VALUE
Read value
Time
Read value
Flink
State
Key/Value
Unexpired
… Use State ...
Expires Expired
… Forget State ...
Flink purges
the state
/ Update
Re-
Create
© 2019 Ververica
StateTtlConfig ttlConfig = StateTtlConfig
7
State TTL feature: Example
// Configure state TTL
// Set TTL
// When to restart TTL? OnCreateAndWrite or OnWriteAndRead
// Get expired state if still there?
// YES for cached, NO for GDPR
// Create state as usual
.newBuilder(Time.days(1))
.setUpdateType(UpdateType.OnCreateAndWrite )
.setStateVisibility (NeverReturnExpired )
.build();
ValueStateDescriptor <Long> lastLogin =
new
ValueStateDescriptor <>("login",Long.class); // Enable TTL
// Use unexpired
// Oops.. expired, not there anymore
lastUserLogin.enableTimeToLive (ttlConfig);
lastUserLogin.update(value); // Create/update for key
// do something during the day
lastUserLogin.get(); // -> value
// do nothing for more than a day
lastUserLogin.get(); // -> null
* For collections (List or Map), TTL applies per entry level
.cleanupIncrementally (10, false) // Activate automatic background cleanup
© 2019 Ververica
Tech Deep Dive
© 2019 Ververica
9
General idea: State Wrappers
KEY
USER
VALUE
Flink
State
Works with
TTL
State
Wrapper
TTL
State
Serializer
User
State
Serializer
TS
KEY
TTL STATE
USER
VALUE
TS
User State TTL Wrapper Normal Flink State
© 2019 Ververica
10
Background Cleanup
TTL
State
Single-Threaded
Check
Expired?
Drop
Needs synchronization!
● Complicated
● Performance implications
Clean
up?
© 2019 Ververica
11
Incremental Heap Backend cleanup (since Flink 1.8)
Single-Threaded
Check
Expired?
Drop
Clean up
...
….
...
Heap State
Global State Iterator
Global State Iterator
KEY VALUE
KEY VALUE
KEY VALUE
Global State Iterator
KEY VALUE
Global State Iterator
KEY VALUE
All state entries are periodically
cleaned up
IF the state is being accessed
© 2019 Ververica
RocksDB
TTL Compaction filter for RocksDB (since Flink 1.8)
Memtable
Immutable
SSTable 1
Flush to disk
Immutable
SSTable 2
Compacted
SSTable
Compaction
Updates
Flink TTL
Compaction
Filter
state
state
...
Iterates
Applied
per
entry
JVM Native C++
JNI
Ask for
current time
Configures
Clean up
FRocksDB
Check
Expired?
Drop
12
© 2019 Ververica
Future roadmap
• Event time support: FLINK-12005
• Support queryable state with TTL
• Flink Timer-based cleanup strategy
• FRocksDB -> RocksDB + Flink extensions (WIP)
13
© 2019 Ververica
Useful links
• The latest blogpost about the feature up to Flink 1.8
• FLIP-25: TTL design discussion
• JIRA Issue FLINK-3089
14
• User documentation for the State TTL
© 2019 Ververica
THANK YOU!
QUESTIONS?
© 2019 Ververica
www.ververica.com @VervericaDatainfo@ververica.com

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Unified Stream and Batch Processing with Apache Flink
Unified Stream and Batch Processing with Apache FlinkUnified Stream and Batch Processing with Apache Flink
Unified Stream and Batch Processing with Apache Flink
 
Tame the small files problem and optimize data layout for streaming ingestion...
Tame the small files problem and optimize data layout for streaming ingestion...Tame the small files problem and optimize data layout for streaming ingestion...
Tame the small files problem and optimize data layout for streaming ingestion...
 
Apache Traffic Server
Apache Traffic ServerApache Traffic Server
Apache Traffic Server
 
Towards Flink 2.0: Unified Batch & Stream Processing - Aljoscha Krettek, Verv...
Towards Flink 2.0: Unified Batch & Stream Processing - Aljoscha Krettek, Verv...Towards Flink 2.0: Unified Batch & Stream Processing - Aljoscha Krettek, Verv...
Towards Flink 2.0: Unified Batch & Stream Processing - Aljoscha Krettek, Verv...
 
Introduction to Kafka Streams
Introduction to Kafka StreamsIntroduction to Kafka Streams
Introduction to Kafka Streams
 
Envoy and Kafka
Envoy and KafkaEnvoy and Kafka
Envoy and Kafka
 
Evening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in FlinkEvening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in Flink
 
Presto query optimizer: pursuit of performance
Presto query optimizer: pursuit of performancePresto query optimizer: pursuit of performance
Presto query optimizer: pursuit of performance
 
Do flink on web with flow - Dongwon Kim & Haemee park, SK Telecom)
Do flink on web with flow - Dongwon Kim & Haemee park, SK Telecom)Do flink on web with flow - Dongwon Kim & Haemee park, SK Telecom)
Do flink on web with flow - Dongwon Kim & Haemee park, SK Telecom)
 
Introduction to Apache Flink - Fast and reliable big data processing
Introduction to Apache Flink - Fast and reliable big data processingIntroduction to Apache Flink - Fast and reliable big data processing
Introduction to Apache Flink - Fast and reliable big data processing
 
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
Exactly-Once Financial Data Processing at Scale with Flink and PinotExactly-Once Financial Data Processing at Scale with Flink and Pinot
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
 
Apache Kafka Best Practices
Apache Kafka Best PracticesApache Kafka Best Practices
Apache Kafka Best Practices
 
Stream processing using Kafka
Stream processing using KafkaStream processing using Kafka
Stream processing using Kafka
 
Where is my bottleneck? Performance troubleshooting in Flink
Where is my bottleneck? Performance troubleshooting in FlinkWhere is my bottleneck? Performance troubleshooting in Flink
Where is my bottleneck? Performance troubleshooting in Flink
 
Spark shuffle introduction
Spark shuffle introductionSpark shuffle introduction
Spark shuffle introduction
 
The top 3 challenges running multi-tenant Flink at scale
The top 3 challenges running multi-tenant Flink at scaleThe top 3 challenges running multi-tenant Flink at scale
The top 3 challenges running multi-tenant Flink at scale
 
Introducing the Apache Flink Kubernetes Operator
Introducing the Apache Flink Kubernetes OperatorIntroducing the Apache Flink Kubernetes Operator
Introducing the Apache Flink Kubernetes Operator
 
Understanding Memory Management In Spark For Fun And Profit
Understanding Memory Management In Spark For Fun And ProfitUnderstanding Memory Management In Spark For Fun And Profit
Understanding Memory Management In Spark For Fun And Profit
 
From Zero to Hero with Kafka Connect
From Zero to Hero with Kafka ConnectFrom Zero to Hero with Kafka Connect
From Zero to Hero with Kafka Connect
 
Streaming SQL with Apache Calcite
Streaming SQL with Apache CalciteStreaming SQL with Apache Calcite
Streaming SQL with Apache Calcite
 

Similar a Time to-live: How to Perform Automatic State Cleanup in Apache Flink - Andrey Zagrebin, Ververica

Fltk S60 Introduction
Fltk S60 IntroductionFltk S60 Introduction
Fltk S60 Introduction
guest5c161
 

Similar a Time to-live: How to Perform Automatic State Cleanup in Apache Flink - Andrey Zagrebin, Ververica (20)

[KubeCon EU 2020] containerd Deep Dive
[KubeCon EU 2020] containerd Deep Dive[KubeCon EU 2020] containerd Deep Dive
[KubeCon EU 2020] containerd Deep Dive
 
It's Time To Stop Using Lambda Architecture | Yaroslav Tkachenko, Shopify
It's Time To Stop Using Lambda Architecture | Yaroslav Tkachenko, ShopifyIt's Time To Stop Using Lambda Architecture | Yaroslav Tkachenko, Shopify
It's Time To Stop Using Lambda Architecture | Yaroslav Tkachenko, Shopify
 
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
 
Fltk S60 Introduction
Fltk S60 IntroductionFltk S60 Introduction
Fltk S60 Introduction
 
Get you Java application ready for Kubernetes !
Get you Java application ready for Kubernetes !Get you Java application ready for Kubernetes !
Get you Java application ready for Kubernetes !
 
Kubernetes Node Deep Dive
Kubernetes Node Deep DiveKubernetes Node Deep Dive
Kubernetes Node Deep Dive
 
Functioning incessantly of Data Science Platform with Kubeflow - Albert Lewan...
Functioning incessantly of Data Science Platform with Kubeflow - Albert Lewan...Functioning incessantly of Data Science Platform with Kubeflow - Albert Lewan...
Functioning incessantly of Data Science Platform with Kubeflow - Albert Lewan...
 
BigQuery case study in Groovenauts & Dive into the DataflowJavaSDK
BigQuery case study in Groovenauts & Dive into the DataflowJavaSDKBigQuery case study in Groovenauts & Dive into the DataflowJavaSDK
BigQuery case study in Groovenauts & Dive into the DataflowJavaSDK
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Pharos
PharosPharos
Pharos
 
Rapid JCR Applications Development with Sling
Rapid JCR Applications Development with SlingRapid JCR Applications Development with Sling
Rapid JCR Applications Development with Sling
 
It's Time To Stop Using Lambda Architecture
It's Time To Stop Using Lambda ArchitectureIt's Time To Stop Using Lambda Architecture
It's Time To Stop Using Lambda Architecture
 
How to build a tool for operating Flink on Kubernetes
How to build a tool for operating Flink on KubernetesHow to build a tool for operating Flink on Kubernetes
How to build a tool for operating Flink on Kubernetes
 
Docker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationDocker and Puppet for Continuous Integration
Docker and Puppet for Continuous Integration
 
Containerd Project Update: FOSDEM 2018
Containerd Project Update: FOSDEM 2018Containerd Project Update: FOSDEM 2018
Containerd Project Update: FOSDEM 2018
 
Virtual Flink Forward 2020: Integrate Flink with Kubernetes natively - Yang Wang
Virtual Flink Forward 2020: Integrate Flink with Kubernetes natively - Yang WangVirtual Flink Forward 2020: Integrate Flink with Kubernetes natively - Yang Wang
Virtual Flink Forward 2020: Integrate Flink with Kubernetes natively - Yang Wang
 
Fullstack workshop
Fullstack workshopFullstack workshop
Fullstack workshop
 
The Future of Apache Storm
The Future of Apache StormThe Future of Apache Storm
The Future of Apache Storm
 
DevopsItalia2015 - DHCP at Facebook - Evolution of an infrastructure
DevopsItalia2015 - DHCP at Facebook - Evolution of an infrastructureDevopsItalia2015 - DHCP at Facebook - Evolution of an infrastructure
DevopsItalia2015 - DHCP at Facebook - Evolution of an infrastructure
 
Build and Run Containers With Lazy Pulling - Adoption status of containerd St...
Build and Run Containers With Lazy Pulling - Adoption status of containerd St...Build and Run Containers With Lazy Pulling - Adoption status of containerd St...
Build and Run Containers With Lazy Pulling - Adoption status of containerd St...
 

Más de Flink Forward

Más de Flink Forward (20)

“Alexa, be quiet!”: End-to-end near-real time model building and evaluation i...
“Alexa, be quiet!”: End-to-end near-real time model building and evaluation i...“Alexa, be quiet!”: End-to-end near-real time model building and evaluation i...
“Alexa, be quiet!”: End-to-end near-real time model building and evaluation i...
 
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
 
Dynamically Scaling Data Streams across Multiple Kafka Clusters with Zero Fli...
Dynamically Scaling Data Streams across Multiple Kafka Clusters with Zero Fli...Dynamically Scaling Data Streams across Multiple Kafka Clusters with Zero Fli...
Dynamically Scaling Data Streams across Multiple Kafka Clusters with Zero Fli...
 
One sink to rule them all: Introducing the new Async Sink
One sink to rule them all: Introducing the new Async SinkOne sink to rule them all: Introducing the new Async Sink
One sink to rule them all: Introducing the new Async Sink
 
Tuning Apache Kafka Connectors for Flink.pptx
Tuning Apache Kafka Connectors for Flink.pptxTuning Apache Kafka Connectors for Flink.pptx
Tuning Apache Kafka Connectors for Flink.pptx
 
Flink powered stream processing platform at Pinterest
Flink powered stream processing platform at PinterestFlink powered stream processing platform at Pinterest
Flink powered stream processing platform at Pinterest
 
Using the New Apache Flink Kubernetes Operator in a Production Deployment
Using the New Apache Flink Kubernetes Operator in a Production DeploymentUsing the New Apache Flink Kubernetes Operator in a Production Deployment
Using the New Apache Flink Kubernetes Operator in a Production Deployment
 
The Current State of Table API in 2022
The Current State of Table API in 2022The Current State of Table API in 2022
The Current State of Table API in 2022
 
Flink SQL on Pulsar made easy
Flink SQL on Pulsar made easyFlink SQL on Pulsar made easy
Flink SQL on Pulsar made easy
 
Dynamic Rule-based Real-time Market Data Alerts
Dynamic Rule-based Real-time Market Data AlertsDynamic Rule-based Real-time Market Data Alerts
Dynamic Rule-based Real-time Market Data Alerts
 
Processing Semantically-Ordered Streams in Financial Services
Processing Semantically-Ordered Streams in Financial ServicesProcessing Semantically-Ordered Streams in Financial Services
Processing Semantically-Ordered Streams in Financial Services
 
Batch Processing at Scale with Flink & Iceberg
Batch Processing at Scale with Flink & IcebergBatch Processing at Scale with Flink & Iceberg
Batch Processing at Scale with Flink & Iceberg
 
Welcome to the Flink Community!
Welcome to the Flink Community!Welcome to the Flink Community!
Welcome to the Flink Community!
 
Extending Flink SQL for stream processing use cases
Extending Flink SQL for stream processing use casesExtending Flink SQL for stream processing use cases
Extending Flink SQL for stream processing use cases
 
Using Queryable State for Fun and Profit
Using Queryable State for Fun and ProfitUsing Queryable State for Fun and Profit
Using Queryable State for Fun and Profit
 
Changelog Stream Processing with Apache Flink
Changelog Stream Processing with Apache FlinkChangelog Stream Processing with Apache Flink
Changelog Stream Processing with Apache Flink
 
Large Scale Real Time Fraudulent Web Behavior Detection
Large Scale Real Time Fraudulent Web Behavior DetectionLarge Scale Real Time Fraudulent Web Behavior Detection
Large Scale Real Time Fraudulent Web Behavior Detection
 
Squirreling Away $640 Billion: How Stripe Leverages Flink for Change Data Cap...
Squirreling Away $640 Billion: How Stripe Leverages Flink for Change Data Cap...Squirreling Away $640 Billion: How Stripe Leverages Flink for Change Data Cap...
Squirreling Away $640 Billion: How Stripe Leverages Flink for Change Data Cap...
 
Building Reliable Lakehouses with Apache Flink and Delta Lake
Building Reliable Lakehouses with Apache Flink and Delta LakeBuilding Reliable Lakehouses with Apache Flink and Delta Lake
Building Reliable Lakehouses with Apache Flink and Delta Lake
 
Near real-time statistical modeling and anomaly detection using Flink!
Near real-time statistical modeling and anomaly detection using Flink!Near real-time statistical modeling and anomaly detection using Flink!
Near real-time statistical modeling and anomaly detection using Flink!
 

Último

Último (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Time to-live: How to Perform Automatic State Cleanup in Apache Flink - Andrey Zagrebin, Ververica

  • 1. © 2019 Ververica Automatic State Cleanup in Apache Flink Deep Dive into State Time-To-Live (TTL) Andrey Zagrebin, Software Engineer and Apache Flink Committer Flink Forward Europe 2019
  • 2. © 2019 Ververica Agenda for the talk • Assumptions about the audience 2 • State TTL feature ─ Why? ─ What is it? ─ How to use it? • Tech deep dive ─ General idea: State Wrappers ─ Background Cleanup • Concurrent background process • Incremental Heap Backend cleanup • TTL Compaction filter for RocksDB • Future roadmap & Useful links
  • 3. © 2019 Ververica Assumptions about the audience • Familiar with Apache Flink and its Keyed Stateful Processing 3 • OR think of the Flink State as a local KV store with a single-threaded access • Two types of Flink State storage backed by ─ in-memory Java object map (heap, non-serialized) ─ RocksDB embedded KV store (native memory + local drive, serialized)
  • 4. © 2019 Ververica State TTL feature (since Flink 1.6, improved 1.8)
  • 5. © 2019 Ververica State TTL feature: Motivation 5 • Save space: do not store what is not used Implement some cleanup on the Application level OR … Make Flink take care about cleanup under the hood • Data privacy: access for limited amount of time e.g. using Flink Timers which are separate state Trade off: storage size implications! Clean up?
  • 6. © 2019 Ververica State TTL feature: Workflow 6 KEY VALUE Flink State Start TTL timer KEY VALUE Read value Time Read value Flink State Key/Value Unexpired … Use State ... Expires Expired … Forget State ... Flink purges the state / Update Re- Create
  • 7. © 2019 Ververica StateTtlConfig ttlConfig = StateTtlConfig 7 State TTL feature: Example // Configure state TTL // Set TTL // When to restart TTL? OnCreateAndWrite or OnWriteAndRead // Get expired state if still there? // YES for cached, NO for GDPR // Create state as usual .newBuilder(Time.days(1)) .setUpdateType(UpdateType.OnCreateAndWrite ) .setStateVisibility (NeverReturnExpired ) .build(); ValueStateDescriptor <Long> lastLogin = new ValueStateDescriptor <>("login",Long.class); // Enable TTL // Use unexpired // Oops.. expired, not there anymore lastUserLogin.enableTimeToLive (ttlConfig); lastUserLogin.update(value); // Create/update for key // do something during the day lastUserLogin.get(); // -> value // do nothing for more than a day lastUserLogin.get(); // -> null * For collections (List or Map), TTL applies per entry level .cleanupIncrementally (10, false) // Activate automatic background cleanup
  • 9. © 2019 Ververica 9 General idea: State Wrappers KEY USER VALUE Flink State Works with TTL State Wrapper TTL State Serializer User State Serializer TS KEY TTL STATE USER VALUE TS User State TTL Wrapper Normal Flink State
  • 10. © 2019 Ververica 10 Background Cleanup TTL State Single-Threaded Check Expired? Drop Needs synchronization! ● Complicated ● Performance implications Clean up?
  • 11. © 2019 Ververica 11 Incremental Heap Backend cleanup (since Flink 1.8) Single-Threaded Check Expired? Drop Clean up ... …. ... Heap State Global State Iterator Global State Iterator KEY VALUE KEY VALUE KEY VALUE Global State Iterator KEY VALUE Global State Iterator KEY VALUE All state entries are periodically cleaned up IF the state is being accessed
  • 12. © 2019 Ververica RocksDB TTL Compaction filter for RocksDB (since Flink 1.8) Memtable Immutable SSTable 1 Flush to disk Immutable SSTable 2 Compacted SSTable Compaction Updates Flink TTL Compaction Filter state state ... Iterates Applied per entry JVM Native C++ JNI Ask for current time Configures Clean up FRocksDB Check Expired? Drop 12
  • 13. © 2019 Ververica Future roadmap • Event time support: FLINK-12005 • Support queryable state with TTL • Flink Timer-based cleanup strategy • FRocksDB -> RocksDB + Flink extensions (WIP) 13
  • 14. © 2019 Ververica Useful links • The latest blogpost about the feature up to Flink 1.8 • FLIP-25: TTL design discussion • JIRA Issue FLINK-3089 14 • User documentation for the State TTL
  • 15. © 2019 Ververica THANK YOU! QUESTIONS?
  • 16. © 2019 Ververica www.ververica.com @VervericaDatainfo@ververica.com