Part 4 · Delta Lake protocol · Chapter 12
Protocol versions and table features
How Delta evolves without breaking readers: minReaderVersion and minWriterVersion, table features at reader version 3 and writer version 7, supported vs active features, how a client decides it may read or write, and how the Spark connector drops a feature.
After this chapter you should be able to:
- Determine whether a client can read or write a table from its protocol action.
- Explain the difference between a supported and an active feature.
- Predict the protocol a feature upgrade produces, including normalization back to legacy versions.
- Describe how a feature is dropped safely (barrier checkpoints, checkpoint protection, history truncation).
Every chapter so far assumed the reader understands every action in the log. That only holds because of one action: protocol. It says which reader and writer a client must be to touch the table, so a client that would misread the log refuses instead of returning wrong rows. This chapter covers the two generations of that mechanism, the numbered versions and table features. It then covers how the Spark connector checks a table, adds a feature, and drops one again.
Legacy protocol versions
The protocol action has two required integers and two optional lists:[PROTOCOL]
{"protocol": {"minReaderVersion": 1, "minWriterVersion": 2}}
The spec says the version goes up “whenever non-forward-compatible changes are made”, and a client that is too old must throw an error telling the user to upgrade. Everything else is forward-compatible by rule: since breaking changes need a version bump or a table feature, clients “must ignore” unrecognized actions, fields and metadata domains instead of failing.[PROTOCOL]
Before table features, each version number was a bundle. Each row inherits the one above it:[PROTOCOL][PROTOCOL]
| Version | A client must respect |
|---|---|
| Writer 2 | append-only tables, column invariants |
| Writer 3 | writeStatsAsJson / writeStatsAsStruct, CHECK constraints |
| Writer 4 | Change Data Feed, generated columns |
| Writer 5 | column mapping |
| Writer 6 | identity columns |
| Writer 7 | table features, for writers |
| Reader 2 | column mapping |
| Reader 3 | table features, for readers (writer version must be 7) |
The problem with bundles is that you can’t take one item without the rest. A table that only wants identity columns has to be writer 6, so every writer must also implement CDF, generated columns and column mapping. Every new feature would have needed a new number, and every client would have needed to implement everything below it.
Q1. A table has minReaderVersion = 1, minWriterVersion = 4. Which features must a writer respect? (select all that apply)
Q2. Why were numbered versions replaced by table features?
Table features
Reader version 3 and writer version 7 replace the bundle with explicit lists: readerFeatures and writerFeatures. The rules:[PROTOCOL][PROTOCOL]
- At reader 3,
readerFeaturesmust exist; at writer 7,writerFeaturesmust exist. - To read, a client must implement every name in
readerFeatures. To write, every name inwriterFeatures, and also every reader feature, because “writers have to read the table (or only the Delta log) before write”. - A table may use writer features alone (
(1, 7)or(2, 7)), or both. Reader features without writer features are illegal: reader 3 with a writer version below 7 is not allowed. - A reader-writer feature is listed in both lists. A writer-only feature is listed only in
writerFeatures. Listing a feature only inreaderFeaturesis not allowed.[PROTOCOL]
{"protocol": {
"minReaderVersion": 3, "minWriterVersion": 7,
"readerFeatures": ["deletionVectors"],
"writerFeatures": ["appendOnly", "deletionVectors", "invariants"]}}
That is what a new table with delta.enableDeletionVectors = true gets from the Spark connector at the pin. appendOnly and invariants show up because the session default protocol is (1, 2), and those are the two features writer 2 implied.[src]
The spec lists every valid name and whether it is writer-only or reader-writer.[PROTOCOL] A selection:
| Name | Kind | Notes |
|---|---|---|
appendOnly, invariants, checkConstraints, changeDataFeed, generatedColumns, identityColumns | writer | the legacy writer bundle, now separable |
columnMapping | reader-writer | legacy reader 2 / writer 5 |
deletionVectors, timestampNtz, v2Checkpoint, vacuumProtocolCheck, catalogManaged | reader-writer | a reader that ignored them would return wrong results or delete live files |
domainMetadata, rowTracking, clustering, inCommitTimestamp, icebergCompatV2 | writer | readers can ignore them safely |
vacuumProtocolCheck is a good example of why a feature becomes reader-writer. Readers don’t need to do anything for it. It is reader-writer so that old VACUUM implementations, which only ran the reader protocol check, start failing on tables that have it.[PROTOCOL]
Supported versus active
A feature is supported when its name is in the lists. It is active when it is supported and the feature’s own metadata requirement holds.[PROTOCOL][PROTOCOL] The spec’s example: appendOnly in writerFeatures with no delta.appendOnly = true means the table is not append-only. Writers may still change and remove data, but they must check the property before every write, because someone may turn it on.
In the Spark connector, many features are added to the protocol automatically when their property is set. Those features mix in FeatureAutomaticallyEnabledByMetadata: for example delta.enableDeletionVectors, delta.enableRowTracking, delta.checkpointPolicy = v2. Other features are added explicitly, with delta.feature.<name> = supported.[src][src]
Q1. Which protocol is not allowed?
Q2. Where is deletionVectors listed in a (3, 7) protocol?
Q3. appendOnly is in writerFeatures, but delta.appendOnly is not set. What may a writer do?
Q4. Readers need to do nothing for vacuumProtocolCheck. Why is it a reader-writer feature?
How a client decides
The Spark connector models every feature as a TableFeature with a name, a minReaderVersion and a minWriterVersion. There are four kinds:[src][src]
| Class | minReaderVersion | minWriterVersion |
|---|---|---|
LegacyWriterFeature | 0 | the version that introduced it (2 to 6) |
LegacyReaderWriterFeature | 2 (only columnMapping) | 5 |
WriterFeature | 0 | 7 |
ReaderWriterFeature | 3 | 7 |
The version numbers a client accepts are computed from the features it implements, not hard-coded: every feature’s minimum version, plus 1, minus 0.[src]
lazy val supportedReaderVersionNumbers: Set[Int] = {
val allVersions =
supportedProtocolVersion().implicitlyAndExplicitlySupportedFeatures.map(_.minReaderVersion) +
1 // Version 1 does not introduce new feature, it's always supported.
...
allVersions - 0 // Delete 0 produced by writer-only features
}
protocolCheck then accepts a table when the client knows the table’s version number and the table’s feature list (reader or writer, depending on the operation) is a subset of the client’s:[src]
if (tableEnabledFeatureNames.subsetOf(clientSupportedFeatureNames) &&
clientSupportedVersions.contains(tableRequiredVersion)) {
return
}
- Reader version The client supports minReaderVersion.
- Reader features The client implements every required reader feature.
- Writer version The client supports minWriterVersion.
- Writer features The client implements every required writer feature.
Two things follow. A client built before table features knows writer versions 1 to 6 and reader versions 1 and 2. So it can still read a (1, 7) table, since reader 1 has no feature list to check, but it cannot write it. And a table-features client that lacks one reader feature can neither read nor write a table that lists it.
Under a legacy protocol (writer below 7), the features are implied by the numbers. implicitlySupportedFeatures is every legacy feature whose versions the protocol meets. Once a protocol has both lists, it implies nothing: only the names count.[src]
Adding a feature
Protocol.withFeature adds a feature and everything in its requiredFeatures first. rowTracking brings domainMetadata, clustering brings domainMetadata, icebergCompatV2 brings columnMapping, and catalogManaged brings inCommitTimestamp and vacuumProtocolCheck. A legacy feature that the current numbers already cover is not listed. A feature that needs table features on a legacy protocol throws.[src]
After any change, the connector rewrites the protocol in its weakest form. normalized turns a table-features protocol back into a legacy pair when the feature set matches one exactly, or lowers the reader version when no reader feature needs 3. denormalized is the inverse. merge, which every upgrade goes through, does both:[src][src]
(1, 7, [appendOnly, invariants, checkConstraints]) normalizes to (1, 3)
(3, 7, [], [domainMetadata, rowTracking]) normalizes to (1, 7, [domainMetadata, rowTracking])
(2, 3) merges to (1, 3) no legacy feature needs reader 2 below writer 5
Upgrading an old table has a trap the spec spells out. Moving from (1, 4) to (3, 7) means listing the features the old numbers implied. A writer might want to list only the ones in use, but a feature may have been used in history that is still reachable by time travel. In the spec’s example, CDF was on in version 1, wrote cdc files in version 2 and was turned off in version 3. So the client “must assume a feature has been used, unless it can prove that the feature is definitely not used”.[PROTOCOL] The Spark connector simply denormalizes: all features implied by (1, 4) become explicit.
A protocol upgrade is also a conflict. If a winning commit changed the protocol and the current transaction also contains a protocol action, it fails with ProtocolChangedException. There is a stricter check behind an internal flag, conflictChecker.enforceConcurrentFeatureEnablement.enabled, which is off by default. With it on, the transaction also fails if the winner added a feature whose failConcurrentTransactionsAtUpgrade is true. That method returns true unless the feature does its own conflict resolution, as deletionVectors, rowTracking and v2Checkpoint do.[src][src][src]
Q1. A client implements only the legacy features, so it knows writer versions 1 to 6. The table is (1, 7) with writerFeatures = [inCommitTimestamp]. What can it do?
Q2. Why must a writer implement every reader feature as well as every writer feature?
Q3. The Spark connector computes (1, 7, writerFeatures = [appendOnly, invariants, checkConstraints]). What does it commit?
Q4. With the default session settings, you create a table with delta.enableDeletionVectors = true. Which protocol does it get?
Q5. A (1, 4) table had CDF on in an old version and off now. You upgrade it to (3, 7). May the writer leave changeDataFeed out of writerFeatures?
Try it
Pick a starting protocol, enable features, and watch the protocol action, the client matrix and the drop plan change. The engine is a port of TableFeatureSupport, protocolCheck and AlterTableDropFeatureDeltaCommand (src/sim/delta/protocol.ts). The four clients are illustrative, not specific releases.
Table protocol
Then enable features (each one upgrades the protocol):
{
"protocol": {
"minReaderVersion": 3,
"minWriterVersion": 7,
"readerFeatures": [
"deletionVectors"
],
"writerFeatures": [
"appendOnly",
"deletionVectors",
"invariants"
]
}
}Supported features: appendOnlydeletionVectorsinvariants
Dashed = implied by the version numbers, not listed. implicitlySupportedFeatures ↗ · normalized ↗
Who can use this table?
| Client | Read | Write |
|---|---|---|
| Reader 1 / writer 2 client | ✗Reader version 3 is unknown to this client | ✗Cannot read: Reader version 3 is unknown to this client |
| Legacy client up to reader 2 / writer 6 | ✗Reader version 3 is unknown to this client | ✗Cannot read: Reader version 3 is unknown to this client |
| Table-features client without deletion vectors | ✗Unsupported reader features: deletionVectors | ✗Cannot read: Unsupported reader features: deletionVectors |
| Client that implements every feature here | ✓ | ✓ |
A client knows a version number when one of its features needs it. A write also needs a read. protocolCheck ↗
Drop a feature
Path: checkpoint protection (default)
- Pre-downgrade command. Unset delta.enableDeletionVectors so no new DVs are written, rewrite files that have DVs (REORG ... APPLY (PURGE)), and add tombstones that point at DV files still referenced within the retention period, so clients without DV support do not lose track of them. ↗
- 3 barrier checkpoints. Three times: an empty commit, then a checkpoint at it. Readers that cannot read an older checkpoint give up before reaching history that uses the feature. ↗
- validateDropInvariants. Check the latest snapshot has no traces of the feature. If a concurrent commit put them back, the drop fails. ↗
- Protocol downgrade commit. One commit removes the feature, adds checkpointProtection and sets delta.requireCheckpointProtectionBeforeVersion to this commit's version. Concurrent transactions that see this protocol change abort. ↗
- Checkpoint after the downgrade. So replay from the barrier to the downgrade commit is never needed. ↗
Protocol after:
{
"protocol": {
"minReaderVersion": 1,
"minWriterVersion": 7,
"writerFeatures": [
"appendOnly",
"checkpointProtection",
"invariants"
]
}
}Things to try:
- Start from
reader 1, writer 2with nothing enabled, then enableinCommitTimestamp. The legacy client can still read, but not write. - Enable
rowTrackingand try to dropdomainMetadata. The drop is refused while a feature that depends on it is supported. - Drop
deletionVectorsand look at the protocol after:checkpointProtectionhas appeared. - Tick TRUNCATE HISTORY with a writer-only feature selected.
Dropping a feature
The spec at the pin has one sentence about removal: once a feature is supported, “Clients must not remove the feature from the protocol action”.[PROTOCOL] It does not describe a downgrade procedure. ALTER TABLE … DROP FEATURE is Spark connector behavior, built so that a client following the spec is never hurt by it.
The command (AlterTableDropFeatureDeltaCommand.run) checks, in order, that:[src]
- the feature is supported by the protocol and known to this client,
- it is a
RemovableFeature, - TRUNCATE HISTORY is used only for features that need history protection (and that
checkpointProtectionis dropped only with it), and - no supported feature lists it in
requiredFeatures.
Each removable feature brings four things: a pre-downgrade command that removes its traces from the latest version and stops new ones, validateDropInvariants on the latest snapshot, requiresHistoryProtection, and actionUsesFeature for scanning history. requiresHistoryProtection defaults to true for reader-writer features and false for writer features.[src] A writer-only feature leaves nothing a reader could misread, so dropping it is just cleanup plus one protocol commit. A reader-writer feature is the hard case: commits still in the log may contain DVs, V2 checkpoints or physical column names that an old reader would get wrong if it replayed them.
There are two ways to make that safe. The default is checkpoint protection (tableFeatures.fastDropFeature.enabled, default true):[src][src]
- checks. The feature must be in the protocol, known to this client and removable. No feature that requires it (
requiredFeatures) may be supported.deletionVectorsis a reader-writer feature, so it needs history protection. run ↗ - unset delta.enableDeletionVectors. The pre-downgrade command first stops new DVs: with the property gone, concurrent writers can no longer add them. DeletionVectorsPreDowngradeCommand ↗
- REORG … APPLY (PURGE). Rewrite every file that has a DV, so the latest snapshot has none. reorgTable ↗
- commit DV tombstones (dataChange=false).
removeactions whose path is a DV file, for DVs still referenced by tombstones within the retention period. The source says they protect those DV files from clients that do not support DVs, and let VACUUM delete them later. They drop no rows. generateDVTombstones ↗ - 3 × (empty commit + checkpoint). Barrier checkpoints. A reader that fails on a checkpoint may retry an older one; three of them make it give up before it reaches history that still has DVs. executeDropFeatureWithCheckpointProtection ↗
- validateDropInvariants(snapshot). No DVs and no DV property in the latest snapshot. If a concurrent commit put them back, the drop fails. RemovableFeature ↗
- commit v: protocol −deletionVectors +checkpointProtection. One commit:
protocol.denormalized.withFeature(checkpointProtection).removeFeature(deletionVectors)anddelta.requireCheckpointProtectionBeforeVersion = v. Metadata cleanup may delete checkpoints before v only together with the commits before them. downgrade commit ↗ - commit → ProtocolChangedException. The conflict checker aborts every transaction that interleaves with a protocol change that removes features. The writer retries on the new protocol. checkProtocolCompatibility ↗
- checkpoint at v. Optional but done: clients that validate every protocol they replay never need to start below v. createCheckpointWithRetries ↗
- load latest snapshot: protocol check passes. The latest protocol no longer lists
deletionVectors, and replay starts at a checkpoint at or after the barrier. protocolCheck ↗
The new protocol is computed as protocol.denormalized.withFeature(CheckpointProtectionTableFeature).removeFeature(feature). The metadata gets delta.requireCheckpointProtectionBeforeVersion = v, the version of the downgrade commit. checkpointProtection is a writer feature, so readers that don’t know it are not blocked. Writers must respect it: they may delete checkpoints before v only together with the commits before them, and may not create checkpoints before v unless they support every feature in the history they keep.[src][src] checkpointProtection is not in the spec’s list of valid feature names at the pin. It is defined by the Spark connector.
The older way, also used whenever TRUNCATE HISTORY is given, is history truncation.[src] The first run cleans the latest version, writes an empty commit and a checkpoint, and fails with “wait for the retention period”. The second run cleans up expired logs, scans the earliest remaining checkpoint and every remaining commit with actionUsesFeature, and commits the downgrade only if nothing is found. Without TRUNCATE HISTORY the cleanup uses delta.logRetentionDuration (30 days by default). With it, the cleanup uses delta.dropFeatureTruncateHistory.retentionDuration, which defaults to 24 hours.[src] Either way, time travel to before the cut is gone.
Every transaction that interleaves with the downgrade aborts: the conflict checker throws ProtocolChangedException when the winning protocol removes features. Going the other way, a downgrade that loses a race re-runs validateDropInvariants against the winner and continues.[src]
Q1. What does PROTOCOL.md at the pin say about removing a supported feature from the protocol?
Q2. The table supports rowTracking. You run DROP FEATURE domainMetadata. What happens?
Q3. Why does the default DROP FEATURE path write three checkpoints before the downgrade commit?
Q4. You run DROP FEATURE inCommitTimestamp TRUNCATE HISTORY. What happens?
Q5. A writer started on the old protocol. The drop commits first. What happens to the writer's commit?
Summary
protocolis the compatibility gate. Legacy versions are bundles: writer 2 to 6 and reader 2 each imply a fixed set of features.- Reader 3 and writer 7 replace bundles with
readerFeaturesandwriterFeatures. Reader-writer features go in both lists, and writers must also implement every reader feature. - Supported means listed. Active means listed and switched on by the feature’s own metadata.
- A client accepts a table when it knows the version number and implements every listed feature. That is why old clients can read but not write
(1, 7)tables. - Adding a feature pulls in its dependencies, and the result is normalized to the weakest equivalent protocol.
- The spec forbids removing a supported feature. The Spark connector’s DROP FEATURE gets around this safely, with barrier checkpoints and
checkpointProtectionby default, or by truncating history.
Concepts in this chapter
Explained here
- Protocol version
- Table feature · also in chapters 9
Primary sources
Review this chapter
This chapter has 16 quiz questions.