hawdb-storage 0.37.0

An embedded Rust graph database for local data-plane workloads
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
// Copyright 2026 Nowledge
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use super::*;
use crate::relational::{RelationalRow, RelationalRowPagePublisher, RelationalValue};
use std::fs;
use std::num::{NonZeroU64, NonZeroUsize};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU64, Ordering};

static TEST_SEQUENCE: AtomicU64 = AtomicU64::new(1);

#[test]
fn mutation_planner_reads_only_affected_leaves_and_splits_deterministically() {
    let directory = unique_test_dir("split");
    let config = two_row_config();
    publish_base(&directory, config);
    let base = RelationalRowPageRootReader::open_latest(&directory, config)
        .unwrap()
        .unwrap();
    let planner = RelationalRowPageMutationPlanner::new(Some(&base), 2, 2, config).unwrap();
    let changes = vec![change(2, Some("two"))];
    let first = planner
        .plan_table("documents", schema_digest(), 2, changes.clone())
        .unwrap();
    let second = planner
        .plan_table("documents", schema_digest(), 2, changes)
        .unwrap();

    assert_eq!(first, second);
    assert_eq!(first.distinct_changes, 1);
    assert_eq!(first.base_pages_read, 1);
    assert_eq!(first.dirty_pages, 2);
    assert_eq!(first.split_pages, 1);
    assert_eq!(first.deleted_pages, 0);
    assert_eq!(first.delta.next_page_id.get(), 4);
    assert_eq!(page_ids(&first.delta.dirty_pages), vec![1, 3]);
    assert_eq!(row_keys(&first.delta.dirty_pages[0]), vec![1, 2]);
    assert_eq!(row_keys(&first.delta.dirty_pages[1]), vec![3]);

    RelationalRowPagePublisher::new(config)
        .publish(&directory, 2, 2, Some(1), vec![first.delta])
        .unwrap();
    let current = RelationalRowPageRootReader::open_latest(&directory, config)
        .unwrap()
        .unwrap();
    assert_eq!(
        current.table_root("documents").unwrap().next_page_id.get(),
        4
    );
    let key_two = key(2);
    let descriptor = current
        .find_table_page_descriptor("documents", &key_two)
        .unwrap()
        .unwrap();
    assert_eq!(descriptor.logical_page_id.get(), 1);
    let page = current.read_page(&descriptor).unwrap();
    assert_eq!(row_keys(&page), vec![1, 2]);
    assert_eq!(
        page.rows[1].row,
        RelationalRow::new(vec![
            RelationalValue::BigInt(2),
            RelationalValue::Text("two".to_string()),
        ])
    );

    fs::remove_dir_all(directory).unwrap();
}

#[test]
fn mutation_planner_updates_deletes_and_never_reuses_page_ids() {
    let directory = unique_test_dir("delete");
    let config = two_row_config();
    publish_base(&directory, config);
    let base = RelationalRowPageRootReader::open_latest(&directory, config)
        .unwrap()
        .unwrap();
    let first = RelationalRowPageMutationPlanner::new(Some(&base), 2, 2, config)
        .unwrap()
        .plan_table(
            "documents",
            schema_digest(),
            2,
            vec![change(2, Some("two"))],
        )
        .unwrap();
    RelationalRowPagePublisher::new(config)
        .publish(&directory, 2, 2, Some(1), vec![first.delta])
        .unwrap();

    let base = RelationalRowPageRootReader::open_latest(&directory, config)
        .unwrap()
        .unwrap();
    let plan = RelationalRowPageMutationPlanner::new(Some(&base), 3, 3, config)
        .unwrap()
        .plan_table(
            "documents",
            schema_digest(),
            2,
            vec![change(2, Some("two-updated")), change(3, None)],
        )
        .unwrap();
    assert_eq!(plan.base_pages_read, 2);
    assert_eq!(plan.dirty_pages, 1);
    assert_eq!(plan.deleted_pages, 1);
    assert_eq!(plan.delta.deleted_page_ids[0].get(), 3);
    assert_eq!(plan.delta.dirty_pages[0].page_id.get(), 1);
    assert_eq!(plan.delta.next_page_id.get(), 4);

    RelationalRowPagePublisher::new(config)
        .publish(&directory, 3, 3, Some(2), vec![plan.delta])
        .unwrap();
    let current = RelationalRowPageRootReader::open_latest(&directory, config)
        .unwrap()
        .unwrap();
    assert_eq!(
        current.table_root("documents").unwrap().next_page_id.get(),
        4
    );
    let descriptors = collect_descriptors(&current, "documents");
    assert_eq!(
        descriptors
            .iter()
            .map(|descriptor| descriptor.logical_page_id.get())
            .collect::<Vec<_>>(),
        vec![1, 2]
    );

    let plan = RelationalRowPageMutationPlanner::new(Some(&current), 4, 4, config)
        .unwrap()
        .plan_table(
            "documents",
            schema_digest(),
            2,
            vec![change(12, Some("twelve"))],
        )
        .unwrap();
    assert_eq!(plan.base_pages_read, 1);
    assert_eq!(plan.split_pages, 1);
    assert_eq!(page_ids(&plan.delta.dirty_pages), vec![2, 4]);
    assert_eq!(plan.delta.next_page_id.get(), 5);
    RelationalRowPagePublisher::new(config)
        .publish(&directory, 4, 4, Some(3), vec![plan.delta])
        .unwrap();
    let current = RelationalRowPageRootReader::open_latest(&directory, config)
        .unwrap()
        .unwrap();
    assert_eq!(
        collect_descriptors(&current, "documents")
            .iter()
            .map(|descriptor| descriptor.logical_page_id.get())
            .collect::<Vec<_>>(),
        vec![1, 2, 4]
    );

    fs::remove_dir_all(directory).unwrap();
}

#[test]
fn streaming_bootstrap_keeps_one_page_plus_one_candidate_row() {
    let config = two_row_config();
    let mut bootstrap = RelationalRowPageBootstrap::new(
        1,
        1,
        schema_digest(),
        2,
        NonZeroU64::new(1).unwrap(),
        config,
    )
    .unwrap();
    let mut pages = Vec::new();
    for value in 1..=5 {
        bootstrap
            .push(entry(value, &format!("row-{value}")), |page| {
                pages.push(page);
                Ok(())
            })
            .unwrap();
    }
    let report = bootstrap
        .finish(|page| {
            pages.push(page);
            Ok(())
        })
        .unwrap();

    assert_eq!(report.rows, 5);
    assert_eq!(report.pages, 3);
    assert_eq!(report.peak_buffered_rows, 3);
    assert_eq!(report.next_page_id.get(), 4);
    assert_eq!(page_ids(&pages), vec![1, 2, 3]);
    assert_eq!(
        pages.iter().map(|page| page.rows.len()).collect::<Vec<_>>(),
        vec![2, 2, 1]
    );
}

#[test]
fn allocator_exhaustion_is_atomic() {
    let mut allocator = RelationalRowPageIdAllocator::new(NonZeroU64::new(u64::MAX).unwrap());
    let error = allocator.allocate().unwrap_err();
    assert!(matches!(
        error,
        RelationalRowPageMutationError::Admission(message)
            if message.contains("allocator is exhausted")
    ));
    assert_eq!(allocator.next_page_id().get(), u64::MAX);
}

#[test]
fn streaming_bootstrap_fails_closed_after_emit_error() {
    let mut config = two_row_config();
    config.page_limits.max_rows = NonZeroUsize::new(1).unwrap();
    let mut bootstrap = RelationalRowPageBootstrap::new(
        1,
        1,
        schema_digest(),
        2,
        NonZeroU64::new(1).unwrap(),
        config,
    )
    .unwrap();
    bootstrap.push(entry(1, "one"), |_| Ok(())).unwrap();
    let error = bootstrap
        .push(entry(2, "two"), |_| {
            Err(RelationalRowPageMutationError::Admission(
                "bootstrap sink failed".to_string(),
            ))
        })
        .unwrap_err();
    assert!(error.to_string().contains("bootstrap sink failed"));

    let error = bootstrap.push(entry(3, "three"), |_| Ok(())).unwrap_err();
    assert!(error.to_string().contains("cannot continue"));
    let error = bootstrap.finish(|_| Ok(())).unwrap_err();
    assert!(error.to_string().contains("cannot finish"));
}

#[test]
fn mutation_planner_rejects_the_global_dirty_page_budget() {
    let directory = unique_test_dir("dirty-budget");
    let base_config = two_row_config();
    publish_base(&directory, base_config);
    RelationalRowPagePublisher::new(base_config)
        .publish(&directory, 2, 2, Some(1), Vec::new())
        .unwrap();
    let mut config = base_config;
    config.max_dirty_pages = NonZeroUsize::new(1).unwrap();
    let base = RelationalRowPageRootReader::open_latest(&directory, config)
        .unwrap()
        .unwrap();
    let error = RelationalRowPageMutationPlanner::new(Some(&base), 3, 3, config)
        .unwrap()
        .plan_table(
            "documents",
            schema_digest(),
            2,
            vec![
                change(1, Some("one-updated")),
                change(10, Some("ten-updated")),
            ],
        )
        .unwrap_err();
    assert!(matches!(
        error,
        RelationalRowPageMutationError::Admission(message)
            if message.contains("emits 2 dirty pages")
    ));

    fs::remove_dir_all(directory).unwrap();
}

#[test]
fn change_admission_replaces_duplicate_key_charges_before_rejecting_growth() {
    let config = two_row_config();
    let limits = RelationalRowChangeCaptureLimits {
        max_entries: NonZeroUsize::new(2).unwrap(),
        max_bytes: NonZeroUsize::new(2 * 1024).unwrap(),
    };
    let first = "a".repeat(1_500);
    let replacement = "b".repeat(1_500);
    let changes = collect_changes_with_limits(
        "documents",
        vec![change(1, Some(&first)), change(1, Some(&replacement))],
        config,
        limits,
    )
    .unwrap();
    assert_eq!(changes.len(), 1);

    let error = collect_changes_with_limits(
        "documents",
        vec![change(1, Some(&first)), change(2, Some(&replacement))],
        config,
        limits,
    )
    .unwrap_err();
    assert!(matches!(
        error,
        RelationalRowPageMutationError::Admission(message)
            if message.contains("exceeding limit 2048")
    ));
}

fn publish_base(directory: &Path, config: RelationalRowPagePublicationConfig) {
    RelationalRowPagePublisher::new(config)
        .publish(
            directory,
            1,
            1,
            None,
            vec![RelationalRowPageTableDelta {
                replaces_base: false,
                last_row_id: 0,
                table: "documents".to_string(),
                schema: Some(crate::relational::row_page::test_row_page_schema(
                    "documents",
                    2,
                )),
                schema_digest: schema_digest(),
                column_count: NonZeroU32::new(2).unwrap(),
                next_page_id: NonZeroU64::new(3).unwrap(),
                dirty_pages: vec![page(1, 1, 1, &[1, 3]), page(2, 1, 1, &[10, 11])],
                deleted_page_ids: Vec::new(),
            }],
        )
        .unwrap();
}

fn two_row_config() -> RelationalRowPagePublicationConfig {
    let mut config = RelationalRowPagePublicationConfig::default();
    config.page_limits.max_rows = NonZeroUsize::new(2).unwrap();
    config
}

fn page(page_id: u64, generation: u64, epoch: u64, keys: &[i64]) -> ImmutableRelationalRowPage {
    ImmutableRelationalRowPage {
        generation,
        source_commit_epoch: epoch,
        page_id: RelationalRowPageId::new(NonZeroU64::new(page_id).unwrap()),
        schema_digest: schema_digest(),
        column_count: 2,
        rows: keys
            .iter()
            .map(|value| entry(*value, &format!("row-{value}")))
            .collect(),
    }
}

fn entry(value: i64, text: &str) -> RelationalRowPageEntry {
    RelationalRowPageEntry {
        primary_key: key(value),
        row: RelationalRow::new(vec![
            RelationalValue::BigInt(value),
            RelationalValue::Text(text.to_string()),
        ]),
    }
}

fn change(value: i64, text: Option<&str>) -> RelationalRowChange {
    RelationalRowChange {
        table: "documents".to_string(),
        primary_key: key(value),
        row: text.map(|text| entry(value, text).row),
    }
}

fn key(value: i64) -> RelationalKey {
    RelationalKey(vec![RelationalValue::BigInt(value)])
}

fn schema_digest() -> Sha256Digest {
    crate::relational::row_page::test_row_page_schema_digest("documents", 2)
}

fn row_keys(page: &ImmutableRelationalRowPage) -> Vec<i64> {
    page.rows
        .iter()
        .map(|entry| match entry.primary_key.0[0] {
            RelationalValue::BigInt(value) => value,
            _ => panic!("test primary key is not an integer"),
        })
        .collect()
}

fn page_ids(pages: &[ImmutableRelationalRowPage]) -> Vec<u64> {
    pages.iter().map(|page| page.page_id.get()).collect()
}

fn collect_descriptors(
    reader: &RelationalRowPageRootReader,
    table: &str,
) -> Vec<RelationalRowPageRootDescriptor> {
    let mut descriptors = Vec::new();
    reader
        .visit_table_pages(table, |descriptor| {
            descriptors.push(descriptor.clone());
            Ok(())
        })
        .unwrap();
    descriptors
}

fn unique_test_dir(label: &str) -> PathBuf {
    std::env::temp_dir().join(format!(
        "hawdb-row-page-mutation-{label}-{}-{}",
        std::process::id(),
        TEST_SEQUENCE.fetch_add(1, Ordering::Relaxed)
    ))
}

/// The packer before linear sizing: it encoded the whole candidate page after
/// every row and split at the first row the codec rejected or, with format v2,
/// at the first row past the target page size.
fn reference_pack(
    column_count: usize,
    digest: Sha256Digest,
    config: RelationalRowPagePublicationConfig,
    rows: &[RelationalRowPageEntry],
) -> (
    Vec<ImmutableRelationalRowPage>,
    Option<RelationalRowPageMutationError>,
) {
    let limits = config.page_limits;
    let new_page = |id: u64| ImmutableRelationalRowPage {
        generation: 1,
        source_commit_epoch: 1,
        page_id: RelationalRowPageId::new(NonZeroU64::new(id).unwrap()),
        schema_digest: digest,
        column_count,
        rows: Vec::new(),
    };
    let mut pages = Vec::new();
    let mut next_id = 1;
    let mut pending: Option<ImmutableRelationalRowPage> = None;
    for row in rows {
        let page = pending.get_or_insert_with(|| new_page(next_id));
        page.rows.push(row.clone());
        // A page closes at the first row that the codec rejects or that grows
        // a page already holding a row past the target (format v2).
        if page.encode(limits).is_ok_and(|encoded| {
            page.rows.len() == 1 || encoded.len() <= config.target_page_bytes.get()
        }) {
            continue;
        }
        let row = page.rows.pop().unwrap();
        if page.rows.is_empty() {
            let mut single = new_page(next_id);
            single.rows.push(row);
            return (pages, Some(single.encode(limits).unwrap_err().into()));
        }
        page.encode(limits).unwrap();
        pages.push(pending.take().unwrap());
        next_id += 1;
        let mut next = new_page(next_id);
        next.rows.push(row);
        if let Err(error) = next.encode(limits) {
            return (pages, Some(error.into()));
        }
        pending = Some(next);
    }
    pages.extend(pending);
    (pages, None)
}

fn linear_pack(
    column_count: usize,
    digest: Sha256Digest,
    config: RelationalRowPagePublicationConfig,
    rows: &[RelationalRowPageEntry],
) -> (
    Vec<ImmutableRelationalRowPage>,
    Option<RelationalRowPageMutationError>,
) {
    let mut pages = Vec::new();
    let mut bootstrap = RelationalRowPageBootstrap::new(
        1,
        1,
        digest,
        column_count,
        NonZeroU64::new(1).unwrap(),
        config,
    )
    .unwrap();
    for row in rows {
        if let Err(error) = bootstrap.push(row.clone(), |page| {
            pages.push(page);
            Ok(())
        }) {
            return (pages, Some(error));
        }
    }
    let result = bootstrap.finish(|page| {
        pages.push(page);
        Ok(())
    });
    (pages, result.err())
}

fn assert_same_packing(
    label: &str,
    column_count: usize,
    config: RelationalRowPagePublicationConfig,
    rows: &[RelationalRowPageEntry],
) {
    let digest = crate::relational::row_page::test_row_page_schema_digest("packing", column_count);
    let (expected, expected_error) = reference_pack(column_count, digest, config, rows);
    let (actual, actual_error) = linear_pack(column_count, digest, config, rows);
    assert_eq!(
        actual_error.as_ref().map(ToString::to_string),
        expected_error.as_ref().map(ToString::to_string),
        "{label}: packing outcome differs"
    );
    assert_eq!(actual, expected, "{label}: page partition differs");
    for (actual, expected) in actual.iter().zip(&expected) {
        let encoded = actual.encode(config.page_limits).unwrap();
        assert_eq!(
            encoded,
            expected.encode(config.page_limits).unwrap(),
            "{label}: encoded page bytes differ"
        );
        // The dirty budget charges `encoded_len` (#1593).
        assert_eq!(
            actual.encoded_len(config.page_limits).unwrap(),
            encoded.len() as u64,
            "{label}: encoded_len differs from the encoded page"
        );
    }
}

fn varied_row(index: usize, column_count: usize) -> RelationalRow {
    let mut values = Vec::with_capacity(column_count);
    values.push(RelationalValue::BigInt(index as i64));
    for column in 1..column_count {
        values.push(match (index * 7 + column * 3) % 8 {
            0 => RelationalValue::Null,
            1 => RelationalValue::Boolean(index.is_multiple_of(2)),
            2 => RelationalValue::DoublePrecision(index as f64 / 3.0),
            3 => RelationalValue::Bytea(vec![column as u8; (index * 13) % 97]),
            4 => RelationalValue::Overflow(crate::relational::RelationalOverflowRef {
                digest: Sha256Digest::from_bytes([index as u8; 32]),
                scalar_type: crate::relational::RelationalScalarType::Text,
                compressed_bytes: 5_000 + index as u64,
                uncompressed_bytes: 9_000 + index as u64,
            }),
            5 => RelationalValue::Text(String::new()),
            _ => RelationalValue::Text("w".repeat((index * 37 + column) % 300)),
        });
    }
    RelationalRow::new(values)
}

fn integer_rows(count: usize, column_count: usize) -> Vec<RelationalRowPageEntry> {
    (0..count)
        .map(|index| RelationalRowPageEntry {
            primary_key: key(index as i64),
            row: varied_row(index, column_count),
        })
        .collect()
}

/// Strictly increasing text keys whose length shrinks after long keys, so a
/// later row's per-row size projection can be smaller than an earlier one.
fn text_key_rows(count: usize) -> Vec<RelationalRowPageEntry> {
    (0..count)
        .map(|index| {
            let length = if index.is_multiple_of(3) {
                400
            } else {
                1 + index % 5
            };
            let text = format!("{:04}{}", index, "k".repeat(length));
            RelationalRowPageEntry {
                primary_key: RelationalKey(vec![RelationalValue::Text(text.clone())]),
                row: RelationalRow::new(vec![
                    RelationalValue::Text(text),
                    RelationalValue::Text("v".repeat(index % 11)),
                ]),
            }
        })
        .collect()
}

fn limits_config(page_bytes: usize, rows: usize) -> RelationalRowPagePublicationConfig {
    let mut config = RelationalRowPagePublicationConfig::default();
    config.page_limits.max_page_bytes = NonZeroUsize::new(page_bytes).unwrap();
    config.page_limits.max_rows = NonZeroUsize::new(rows).unwrap();
    config
}

#[test]
fn linear_packing_matches_whole_page_encoding_at_default_limits() {
    let config = RelationalRowPagePublicationConfig::default();
    // Narrow rows fill pages to exactly the 256-row cap; one more row splits.
    for count in [1, 255, 256, 257, 513, 1_000] {
        assert_same_packing(
            &format!("narrow {count}"),
            2,
            config,
            &integer_rows(count, 2),
        );
    }
    assert_same_packing("wide", 24, config, &integer_rows(600, 24));
    assert_same_packing("text keys", 2, config, &text_key_rows(700));
}

#[test]
fn linear_packing_matches_whole_page_encoding_at_every_byte_cap() {
    let wide = integer_rows(60, 6);
    let keyed = text_key_rows(60);
    // Every byte limit in the sweep lands some page exactly at its cap and
    // the next row one byte or more over it, including single rows that no
    // page can hold.
    for page_bytes in (ROW_PAGE_TEST_HEADER_BYTES..6_000).step_by(3) {
        for max_rows in [1, 2, 3, 7, 256] {
            let config = limits_config(page_bytes, max_rows);
            assert_same_packing(&format!("wide {page_bytes}/{max_rows}"), 6, config, &wide);
            assert_same_packing(&format!("keyed {page_bytes}/{max_rows}"), 2, config, &keyed);
        }
    }
}

#[test]
fn linear_packing_reports_the_codec_error_for_unpackable_rows() {
    let mut rows = integer_rows(20, 3);
    let config = limits_config(64 * 1024, 256);

    // A row wider than its row limit, after rows that already fill a page.
    let mut row_limited = config;
    row_limited.page_limits.max_row_bytes = NonZeroUsize::new(200).unwrap();
    rows[10].row = RelationalRow::new(vec![
        RelationalValue::BigInt(10),
        RelationalValue::Text("x".repeat(400)),
        RelationalValue::Null,
    ]);
    assert_same_packing("row over row limit", 3, row_limited, &rows);

    // A single row larger than a whole page.
    let page_limited = limits_config(600, 256);
    assert_same_packing("row over page limit", 3, page_limited, &rows);

    // A row with the wrong number of values.
    let mut short = integer_rows(20, 3);
    short[5].row = RelationalRow::new(vec![RelationalValue::BigInt(5)]);
    assert_same_packing("wrong column count", 3, config, &short);

    // A key over the key limit.
    let mut key_limited = config;
    key_limited.page_limits.max_key_bytes = NonZeroUsize::new(64).unwrap();
    assert_same_packing("key over key limit", 2, key_limited, &text_key_rows(10));
}

const ROW_PAGE_TEST_HEADER_BYTES: usize = 140;