Skip to content

[Variant] Restore object field offsets after failed append - #11403

Merged
sdf-jkl merged 6 commits into
apache:mainfrom
Embucket:upstream-variant-object-rollback
Oct 23, 2026
Merged

sdf-jkl merged 6 commits into
apache:mainfrom
Embucket:upstream-variant-object-rollback

Conversation

@osipovartem

@osipovartem osipovartem commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Why

ObjectBuilder updates its field-offset map before appending a value. With duplicate-key validation enabled, rejecting a duplicate can leave the map changed. With validation disabled, a failed fallible overwrite truncates bytes but leaves the previous offset unrestored. Continuing to build the object can then produce an invalid value.

Change

Reject validated duplicates before mutation and restore the previous offset when a permitted overwrite fails. The default non-validating path keeps its existing fields.insert fast path. Add regression tests that continue building after each error. This is independent of the fallible trait API in #11106; it is the unique correction extracted from superseded #11401.

Validation

  • cargo +1.98.1 test -p parquet-variant --lib: 176 passed.
  • Formatting and cargo +1.98.1 clippy -p parquet-variant --lib pass (installed 1.98.1 reports the repo's newer lint as unknown).
  • Focused short Criterion runs showed no repeatable regression, but WSL measurements were noisy; the default insert path is unchanged.
  • Independent read-only review covered correctness, regressions, performance, API compatibility, and tests; approved with no blockers.

@sdf-jkl

sdf-jkl commented Oct 8, 2026

Copy link
Copy Markdown
Member

Hi @osipovartem, I'd like to have a bench for this change as well.

It seems like we already have some benchmarks that can partially cover the changed behavior, but they not targeted enough and require a Validation toggle

fn bench_object_same_schema(c: &mut Criterion) {
let mut rng = StdRng::seed_from_u64(42);
let mut string_table = RandomStringGenerator::new(&mut rng, 117);
c.bench_function("bench_object_same_schema", |b| {
b.iter(|| {
for _ in 0..25_000 {
let mut variant = VariantBuilder::new();
let mut object_builder = variant.new_object();
object_builder.insert("name", string_table.next());
object_builder.insert("age", random::<u32>(&mut rng, 18..100) as i32);
object_builder.insert("likes_cilantro", rng.random_bool(0.5));
object_builder.insert("comments", string_table.next());
let mut inner_list_builder = object_builder.new_list("dishes");
inner_list_builder.append_value(string_table.next());
inner_list_builder.append_value(string_table.next());
inner_list_builder.append_value(string_table.next());

or time smth else entirely

fn bench_validation_validated_vs_unvalidated(c: &mut Criterion) {
let mut rng = StdRng::seed_from_u64(42);
let mut string_table = RandomStringGenerator::new(&mut rng, 117);
// Pre-generate test data
let mut test_data = Vec::new();
for _ in 0..100 {
let mut builder = VariantBuilder::new();
let mut obj = builder.new_object();
obj.insert("field1", string_table.next());
obj.insert("field2", rng.random::<i32>());

I think adding a small bench timing the ObjectBuilder::insert with validation on and off should do

@osipovartem

Copy link
Copy Markdown
Contributor Author

Added the requested ObjectBuilder::insert benchmark in d3b825e. It builds an object with 128 pre-generated unique fields in both with_validate_unique_fields(false) and true modes (Criterion object_insert_unique_fields). This measures end-to-end object construction, including builder creation/finalization, amortized across the inserts. A short WSL run measured ~14.9/15.2 us on upstream/main and ~15.3/15.0 us on the PR branch (unvalidated/validated); I do not see a repeatable regression, but these close numbers are too noisy for a stronger claim. parquet-variant tests: 176 passed; formatting and bench Clippy passed. Independent read-only review approved the benchmark.

@sdf-jkl

sdf-jkl commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

@osipovartem sorry I didn't make myself clear. Can we add the benchmark in a separate PR so we the bot can run it? The bench looks good

@osipovartem

Copy link
Copy Markdown
Contributor Author

Thanks for clarifying. I moved the benchmark into a standalone PR: #11461. I removed it from this PR so the benchmark can land and be measured independently first.

@sdf-jkl

sdf-jkl commented Oct 9, 2026

Copy link
Copy Markdown
Member

@osipovartem can you merge with main again, I'll run the bench

adriangb pushed a commit to pydantic/arrow-rs that referenced this pull request Oct 9, 2026
…pache#11461)

Adds a focused Criterion benchmark for inserting 128 pre-generated
unique fields into a Variant object, in both validated and unvalidated
modes. This benchmark-only PR establishes a baseline for the behavior
change in apache#11403, as requested in review.

Validation: the benchmark compiled on current Apache main; both cases
ran in a short local smoke test. Independent read-only review found no
blocking issues.
@sdf-jkl

sdf-jkl commented Oct 9, 2026

Copy link
Copy Markdown
Member

run benchmark variant_builder

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: variant_builder

Sharding factor: 1 (1 workers).

Comparing upstream-variant-object-rollback (effbfc6) to 4d8b332 (merge-base) diff

Run configuration
run benchmark variant_builder
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: variant_builder

Comparing upstream-variant-object-rollback (effbfc6) to 4d8b332 (merge-base) diff

Run configuration
run benchmark variant_builder
shards: 1
Details
group                                       base                                   changed
-----                                       ----                                   -------
bench_extend_metadata_builder               1.00     21.0±0.08ms        ? ?/sec    1.09     22.8±0.10ms        ? ?/sec
bench_object_field_names_reverse_order      1.00     12.8±0.06ms        ? ?/sec    1.04     13.4±0.35ms        ? ?/sec
bench_object_list_partially_same_schema     1.00  1052.8±12.20µs        ? ?/sec    1.01  1064.7±12.22µs        ? ?/sec
bench_object_list_same_schema               1.00     21.2±0.10ms        ? ?/sec    1.05     22.4±0.18ms        ? ?/sec
bench_object_list_unknown_schema            1.00     10.8±0.05ms        ? ?/sec    1.01     10.9±0.04ms        ? ?/sec
bench_object_partially_same_schema          1.00      2.7±0.01ms        ? ?/sec    1.02      2.7±0.01ms        ? ?/sec
bench_object_same_schema                    1.00     31.7±0.10ms        ? ?/sec    1.03     32.8±0.10ms        ? ?/sec
bench_object_unknown_schema                 1.00     13.2±0.04ms        ? ?/sec    1.01     13.4±0.03ms        ? ?/sec
iteration/unvalidated_fallible_iteration    1.03      2.8±0.00ms        ? ?/sec    1.00      2.7±0.00ms        ? ?/sec
iteration/validated_iteration               1.00     40.1±0.34µs        ? ?/sec    1.00     40.0±0.37µs        ? ?/sec
object_insert_unique_fields/unvalidated     1.00     24.0±0.15µs  5.1 MElem/sec    1.04     25.0±0.07µs  4.9 MElem/sec
object_insert_unique_fields/validated       1.00     24.0±0.15µs  5.1 MElem/sec    1.02     24.4±0.08µs  5.0 MElem/sec
validation/unvalidated_construction         1.00      4.3±0.07µs        ? ?/sec    1.01      4.3±0.08µs        ? ?/sec
validation/validated_construction           1.00     67.1±0.85µs        ? ?/sec    1.00     67.2±0.86µs        ? ?/sec
validation/validation_cost                  1.00     56.8±0.86µs        ? ?/sec    1.00     57.0±0.88µs        ? ?/sec

Per-runner information
variant_builder — shard 1/1

Node: gk3-benchmark-cluster-nap-hzcqstew-0cdd7fda-f7bv

Instance: c4a-highcpu-48 (12 vCPU / 65 GiB)

uname:

Linux bench-c6087961676-3257-jr5wk 6.12.94+ #1 SMP Fri Aug 21 08:00:16 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_builder
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  48
On-line CPU(s) list:                     0-47
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     48
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               3 MiB (48 instances)
L1i cache:                               3 MiB (48 instances)
L2 cache:                                96 MiB (48 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-47
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Resource Usage

base (merge-base)

Metric Value
Wall time 155.0s
Peak memory 54.2 MiB
Avg memory 21.2 MiB
CPU user 150.3s
CPU sys 1.6s
Peak spill 0 B

branch

Metric Value
Wall time 155.0s
Peak memory 54.2 MiB
Avg memory 21.3 MiB
CPU user 151.6s
CPU sys 1.5s
Peak spill 0 B

File an issue against this benchmark runner

@sdf-jkl

sdf-jkl commented Oct 9, 2026

Copy link
Copy Markdown
Member

run benchmark variant_builder

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: variant_builder

Sharding factor: 1 (1 workers).

Comparing upstream-variant-object-rollback (effbfc6) to 4d8b332 (merge-base) diff

Run configuration
run benchmark variant_builder
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: variant_builder

Comparing upstream-variant-object-rollback (effbfc6) to 4d8b332 (merge-base) diff

Run configuration
run benchmark variant_builder
shards: 1
Details
group                                       base                                   changed
-----                                       ----                                   -------
bench_extend_metadata_builder               1.00     21.9±0.50ms        ? ?/sec    1.07     23.5±0.54ms        ? ?/sec
bench_object_field_names_reverse_order      1.00     14.3±0.70ms        ? ?/sec    1.01     14.3±0.64ms        ? ?/sec
bench_object_list_partially_same_schema     1.00  1057.6±11.89µs        ? ?/sec    1.01  1065.7±12.33µs        ? ?/sec
bench_object_list_same_schema               1.00     21.5±0.13ms        ? ?/sec    1.05     22.5±0.20ms        ? ?/sec
bench_object_list_unknown_schema            1.00     11.0±0.12ms        ? ?/sec    1.00     11.0±0.08ms        ? ?/sec
bench_object_partially_same_schema          1.00      2.7±0.01ms        ? ?/sec    1.02      2.7±0.01ms        ? ?/sec
bench_object_same_schema                    1.00     31.8±0.09ms        ? ?/sec    1.03     32.8±0.10ms        ? ?/sec
bench_object_unknown_schema                 1.00     13.2±0.07ms        ? ?/sec    1.01     13.3±0.03ms        ? ?/sec
iteration/unvalidated_fallible_iteration    1.03      2.8±0.00ms        ? ?/sec    1.00      2.7±0.00ms        ? ?/sec
iteration/validated_iteration               1.00     40.0±0.33µs        ? ?/sec    1.00     40.0±0.38µs        ? ?/sec
object_insert_unique_fields/unvalidated     1.00     24.6±0.15µs  5.0 MElem/sec    1.02     25.0±0.07µs  4.9 MElem/sec
object_insert_unique_fields/validated       1.01     24.7±0.13µs  5.0 MElem/sec    1.00     24.5±0.07µs  5.0 MElem/sec
validation/unvalidated_construction         1.02      4.4±0.06µs        ? ?/sec    1.00      4.3±0.08µs        ? ?/sec
validation/validated_construction           1.00     67.0±1.02µs        ? ?/sec    1.00     67.2±0.85µs        ? ?/sec
validation/validation_cost                  1.00     57.0±0.76µs        ? ?/sec    1.00     57.0±0.92µs        ? ?/sec

Per-runner information
variant_builder — shard 1/1

Node: gk3-benchmark-cluster-nap-orq9b72x-d7b0b158-fnjb

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

uname:

Linux bench-c6089019578-3259-7mdgs 6.12.94+ #1 SMP Fri Aug 21 08:00:16 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_builder
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Resource Usage

base (merge-base)

Metric Value
Wall time 155.0s
Peak memory 54.2 MiB
Avg memory 21.4 MiB
CPU user 150.0s
CPU sys 2.0s
Peak spill 0 B

branch

Metric Value
Wall time 155.0s
Peak memory 54.2 MiB
Avg memory 20.7 MiB
CPU user 149.2s
CPU sys 1.9s
Peak spill 0 B

File an issue against this benchmark runner

@cakeni cakeni left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I also checked dropping an unfinished overwrite: the previous field survives, and a completed overwrite still replaces it.

@sdf-jkl sdf-jkl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @osipovartem LGTM

@sdf-jkl
sdf-jkl added this pull request to the merge queue Oct 23, 2026
Merged via the queue into apache:main with commit 2a22dd7 Oct 23, 2026
25 checks passed
@sdf-jkl

sdf-jkl commented Oct 23, 2026

Copy link
Copy Markdown
Member

Thanks again @osipovartem @cakeni

@Jefffrey Jefffrey added the bug Squash those bugs label Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Squash those bugs parquet-variant parquet-variant* crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants