<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=RocksDB_state_store</id>
	<title>RocksDB state store - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=RocksDB_state_store"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=RocksDB_state_store&amp;action=history"/>
	<updated>2026-12-06T00:29:47Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://openlakehouse.io/w/index.php?title=RocksDB_state_store&amp;diff=173&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@7c9abaa</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=RocksDB_state_store&amp;diff=173&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:49Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@7c9abaa&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox concept&lt;br /&gt;
| name            = RocksDB state store&lt;br /&gt;
| also_known_as   = &amp;lt;code&amp;gt;RocksDBStateStoreProvider&amp;lt;/code&amp;gt;&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| introduced      = Apache Spark 3.2&lt;br /&gt;
| key_parts       = One RocksDB instance per operator partition, local disk, uploaded SST files and &amp;lt;code&amp;gt;.zip&amp;lt;/code&amp;gt; version files, optional changelog checkpointing, optional bounded memory&lt;br /&gt;
| implementations = [[Structured Streaming]] in [[Apache Spark]]; a separate provider on Databricks&lt;br /&gt;
| related         = [[State store]], [[Streaming checkpoint]], [[transformWithState]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 4.3.0 Structured Streaming programming guide (RocksDB state store implementation, memory management, changelog checkpointing), &amp;lt;code&amp;gt;SQLConf.scala&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RocksDB.scala&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RocksDBFileManager.scala&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pom.xml&amp;lt;/code&amp;gt; at tag v4.3.0 of apache/spark, SPARK-43421, and the Databricks RocksDB state store page}}&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;RocksDB state store&amp;#039;&amp;#039;&amp;#039; is a [[state store]] implementation for [[Apache Spark]] [[Structured Streaming]] that keeps the state of stateful operators in RocksDB, an embedded key-value database, in native memory and on the executor&amp;#039;s local disk, and uploads its files to the [[streaming checkpoint]] for fault tolerance. It was added in Spark 3.2 for queries with large state, such as millions of keys, where the default HDFS-backed state store causes long JVM garbage collection pauses.&amp;lt;ref name=&amp;quot;ss-rocks&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#rocksdb-state-store-implementation |title=Structured Streaming: RocksDB state store implementation (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; It is the only built-in provider that supports [[transformWithState]].&lt;br /&gt;
&lt;br /&gt;
== How is the RocksDB state store enabled? ==&lt;br /&gt;
The provider is chosen with &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.providerClass&amp;lt;/code&amp;gt;. In Apache Spark, set it to &amp;lt;code&amp;gt;org.apache.spark.sql.execution.streaming.state.RocksDBStateStoreProvider&amp;lt;/code&amp;gt; before a query first starts; the provider cannot be changed between restarts from the same checkpoint.&amp;lt;ref name=&amp;quot;ss-rocks&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
spark.conf.set(&lt;br /&gt;
    &amp;quot;spark.sql.streaming.stateStore.providerClass&amp;quot;,&lt;br /&gt;
    &amp;quot;org.apache.spark.sql.execution.streaming.state.RocksDBStateStoreProvider&amp;quot;,&lt;br /&gt;
)&lt;br /&gt;
spark.conf.set(&lt;br /&gt;
    &amp;quot;spark.sql.streaming.stateStore.rocksdb.changelogCheckpointing.enabled&amp;quot;, &amp;quot;true&amp;quot;&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On Databricks, RocksDB is the default state store provider in Databricks Runtime 17.3 LTS and above. Older runtimes enable it with the provider class &amp;lt;code&amp;gt;com.databricks.sql.streaming.state.RocksDBStateStoreProvider&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;db&amp;quot;&amp;gt;{{Cite web |url=https://docs.databricks.com/aws/en/structured-streaming/rocksdb-state-store |title=Configure RocksDB state store on Databricks |publisher=Databricks |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark 4.3.0 is built against version 9.8.4 of the &amp;lt;code&amp;gt;rocksdbjni&amp;lt;/code&amp;gt; library.&amp;lt;ref name=&amp;quot;pom&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/pom.xml |title=pom.xml (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.rocksdb.formatVersion&amp;lt;/code&amp;gt; (default 5) is stored in the checkpoint when a query starts and used for its whole lifetime.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does it checkpoint state? ==&lt;br /&gt;
By default the RocksDB state store uses &amp;#039;&amp;#039;&amp;#039;incremental snapshot checkpointing&amp;#039;&amp;#039;&amp;#039;. At each commit it uploads the RocksDB manifest files and the SST data files that are new since the previous version.&amp;lt;ref name=&amp;quot;ss-cl&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#rocksdb-state-store-changelog-checkpointing |title=Structured Streaming: RocksDB State Store Changelog Checkpointing (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; In the checkpoint, SST and log files get unique names in shared directories, and each version is described by a &amp;lt;code&amp;gt;&amp;#039;&amp;#039;version&amp;#039;&amp;#039;.zip&amp;lt;/code&amp;gt; file with the metadata that maps local file names to the uploaded files. Unlike the HDFS-backed store, which has to replay earlier &amp;lt;code&amp;gt;.delta&amp;lt;/code&amp;gt; files, each &amp;lt;code&amp;gt;.zip&amp;lt;/code&amp;gt; is a complete description of one version.&amp;lt;ref name=&amp;quot;rocksfm&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala |title=RocksDBFileManager.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is changelog checkpointing? ===&lt;br /&gt;
With &amp;#039;&amp;#039;&amp;#039;changelog checkpointing&amp;#039;&amp;#039;&amp;#039;, each commit uploads only the changes made to the state since the last checkpoint, in a &amp;lt;code&amp;gt;.changelog&amp;lt;/code&amp;gt; file, instead of a snapshot. Snapshots are still written periodically in the background, to bound recovery time and allow old changelogs to be removed. The Spark guide states that this avoids the cost of capturing and uploading snapshots and reduces streaming query latency.&amp;lt;ref name=&amp;quot;ss-cl&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;rocksfm&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Changelog checkpointing was added in Spark 3.5.0 (SPARK-43421).&amp;lt;ref name=&amp;quot;jira&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-43421 |title=SPARK-43421: Implement changelog checkpointing for RocksDB state store |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; In Apache Spark it is off by default and is turned on with &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.rocksdb.changelogCheckpointing.enabled=true&amp;lt;/code&amp;gt;. It is compatible in both directions with snapshot checkpointing: an existing query can switch to changelog checkpointing, or back, on restart without discarding its state.&amp;lt;ref name=&amp;quot;ss-cl&amp;quot; /&amp;gt; Snapshots are created after &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.minDeltasForSnapshot&amp;lt;/code&amp;gt; (default 10) changelog versions.&amp;lt;ref name=&amp;quot;rocksdbsrc&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDB.scala |title=RocksDB.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On Databricks, changelog checkpointing is available in Databricks Runtime 13.3 LTS and above and enabled by default in 17.3 LTS and above; Databricks recommends it for all stateful Structured Streaming queries.&amp;lt;ref name=&amp;quot;db&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How is RocksDB memory controlled? ==&lt;br /&gt;
RocksDB allocates memory for memtables (write buffers), the block cache and filter and index blocks. Left unbounded, the instances on one executor can together use enough memory to cause out-of-memory errors.&amp;lt;ref name=&amp;quot;ss-mem&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#rocksdb-state-store-memory-management |title=Structured Streaming: RocksDB State Store Memory Management (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Setting &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.rocksdb.boundedMemoryUsage=true&amp;lt;/code&amp;gt; caps the total memory of all RocksDB instances on a node at &amp;lt;code&amp;gt;maxMemoryUsageMB&amp;lt;/code&amp;gt; (default 500), through RocksDB&amp;#039;s write buffer manager. The cap is a soft limit: usage can briefly exceed it. Per-instance limits are set with &amp;lt;code&amp;gt;writeBufferSizeMB&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;maxWriteBufferNumber&amp;lt;/code&amp;gt;, which by default use RocksDB&amp;#039;s own defaults.&amp;lt;ref name=&amp;quot;ss-mem&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
All keys start with &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.rocksdb.&amp;lt;/code&amp;gt;. Defaults are those of Spark 4.3.0.&amp;lt;ref name=&amp;quot;ss-rocks&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Key suffix !! Default !! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;changelogCheckpointing.enabled&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; || Upload changelogs instead of snapshots at commit&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;compactOnCommit&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; || Run a range compaction at each commit&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;blockSizeKB&amp;lt;/code&amp;gt; || 4 || Approximate user data per block in a block-based SST table&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;blockCacheSizeMB&amp;lt;/code&amp;gt; || 8 || Block cache capacity&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;lockAcquireTimeoutMs&amp;lt;/code&amp;gt; || 60000 || Wait for the instance lock when loading&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;maxOpenFiles&amp;lt;/code&amp;gt; || -1 || Open file limit; -1 keeps all files open&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;resetStatsOnLoad&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; || Reset RocksDB statistics on load&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;trackTotalNumberOfRows&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; || Track total rows in state; costs an extra lookup per write&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeBufferSizeMB&amp;lt;/code&amp;gt; || -1 || Maximum memtable size; -1 uses the RocksDB default&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;maxWriteBufferNumber&amp;lt;/code&amp;gt; || -1 || Maximum number of memtables; -1 uses the RocksDB default&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;boundedMemoryUsage&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; || Bound total RocksDB memory per node&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;maxMemoryUsageMB&amp;lt;/code&amp;gt; || 500 || Total memory limit per node when bounded&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeBufferCacheRatio&amp;lt;/code&amp;gt; || 0.5 || Share of the bound used for write buffers&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;highPriorityPoolRatio&amp;lt;/code&amp;gt; || 0.1 || Share of the bound used for high-priority blocks&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;allowFAllocate&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; || Let RocksDB pre-allocate disk space with fallocate&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;compression&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;lz4&amp;lt;/code&amp;gt; || RocksDB compression type&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Turning off &amp;lt;code&amp;gt;trackTotalNumberOfRows&amp;lt;/code&amp;gt; can improve write performance; the reported number of rows in state is then 0. It can be changed when the query restarts.&amp;lt;ref name=&amp;quot;ss-rocks&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison with Flink&amp;#039;s RocksDB backend ==&lt;br /&gt;
[[Apache Flink]] also has an embedded RocksDB state backend, &amp;lt;code&amp;gt;EmbeddedRocksDBStateBackend&amp;lt;/code&amp;gt;. It stores state as serialized bytes, always takes asynchronous snapshots, and is the only Flink backend that offers incremental checkpoints.&amp;lt;ref name=&amp;quot;flink-sb&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/ops/state/state_backends/ |title=State Backends (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Flink&amp;#039;s default is the heap-based &amp;lt;code&amp;gt;HashMapStateBackend&amp;lt;/code&amp;gt;, as Spark&amp;#039;s default is the heap-based HDFS-backed state store.&amp;lt;ref name=&amp;quot;flink-sb&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[State store]]&lt;br /&gt;
* [[Streaming checkpoint]]&lt;br /&gt;
* [[Stateful stream processing]]&lt;br /&gt;
* [[transformWithState]]&lt;br /&gt;
* [[Structured Streaming]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Navbox open lakehouse}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Concepts]]&lt;br /&gt;
[[Category:Glossary terms]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;br /&gt;
[[Category:Pipelines and orchestration]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>