Repository navigation
Why does Secondary Index not offer a partitioned variant like Record Level Index? #20902
Replies: 1 comment 2 replies
|
Thanks for the detailed reproduction. There are already two open requests for this: apache/hudi#16706 (HUDI-8446) and apache/hudi#17308 (HUDI-8517). The latter explicitly proposes carrying partition information and adjusting delete handling.
|
Uh oh!
There was an error while loading. Please reload this page.
Hi Hudi community,
I've been exploring Hudi's indexing subsystem and noticed an asymmetry: Record Level Index (RLI) supports both global and partitioned variants (the partitioned variant was introduced in 1.1.x), while Secondary Index (SI) only exists as a global variant. I'd like to understand the design rationale behind this, and whether a partitioned SI variant might be worth considering.
Our use case:
We run Hudi on partitioned tables under pessimistic concurrency control with partition-level locks. Writers acquire locks scoped to the partitions they modify, which allows independent writers on different partitions to proceed concurrently without stepping on each other.
Partitioned RLI fits this model naturally: an upsert touching partition
Ponly needs to read and update RLI entries withinrecord-index-P-xxxx, so the metadata-table write scope matches the data-table lock scope.Secondary indexes, however, are stored in a single
secondary_index_<col>/partition regardless of the data table's partitioning. This means any data write can trigger SI maintenance that touches the entire SI partition — effectively requiring a table-wide lock (or at least a lock covering all SI file groups) to safely update the index, even when the underlying data change is confined to a single partition.This creates a lock-granularity mismatch between data writes and index maintenance, and it undermines the concurrency benefits that partitioned RLI provides under pessimistic locking.
Reproducible failure: SI + partitioned RLI on duplicate record keys across partitions
Beyond the concurrency concern, we found that the semantic gap between partitioned RLI and SI leads to an outright build failure. Partitioned RLI allows the same record key to exist in different data partitions (uniqueness is scoped to
(partition_path, record_key)), but SI keys are encoded as<escaped-secondary-key>$<escaped-primary-key>without partition path. When both are used together, two rows sharing the same record key but living in different partitions produce the same SI key, and the SI build fails with a duplicate key exception.Reproduction (Spark SQL):
The last statement fails with:
Note that both
(id=1695516137, city='houston')and(id=1695516137, city='austin')are legitimate rows under partitioned RLI semantics — the failure is purely on the SI side, where both rows collapse to the identical keydriver-P$1695516137in thesecondary_index_driverpartition.Unless I'm missing something, this means partitioned RLI and SI are currently incompatible whenever record keys repeat across partitions — which is precisely the scenario partitioned RLI is designed to support.
Questions:
CREATE INDEXtime) rather than failing mid-build?Any partitioned SI design would need to address the key-collision issue — for example, by encoding the partition path into the SI key, or by scoping SI entries to per-partition file groups. But from a concurrency standpoint, being able to confine SI writes to per-partition file groups would meaningfully reduce lock contention in our setup.
Would love to hear the community's thoughts — whether this is a known limitation, a deliberate tradeoff, or a potential future direction worth exploring.
Thanks!
All reactions