Josh Kang 812a5f4040 [rocksdb] Pass file metadata to IngestExternalFile to improve ingestion latency
Pull Request resolved: https://github.com/facebook/rocksdb/pull/14824


## Summary

External file ingestion (`DB::IngestExternalFile[s]`) re-opens every SST file and scans it -- footer, properties, index, filter, and the first/last data blocks -- to recompute the boundary keys, sequence-number bounds, and table properties before committing. For cold, I/O-bound files this scan dominates ingest latency, even when the file is moved/linked rather than copied.

This change lets a caller skip that work when it already has the file's metadata. `SstFileWriter::Finish()` now populates the full `ExternalSstFileInfo` (its `smallest_internal_key`, `largest_internal_key`, and `table_properties`), and a new `IngestExternalFileArg::file_infos` field carries one `ExternalSstFileInfo` per file into `IngestExternalFiles()`. When set, ingestion reuses that metadata instead of re-opening and scanning each file. The file is still copied/linked, and the checksum is still verified when `verify_checksums_before_ingest` is set (the fast path opens the file only for that). Range tombstones and user-defined-timestamp files (including the "UDT in Memtables only" format, whose boundary keys carry no timestamp) are handled.

Internally, ingestion-job metadata acquisition was split into `GetIngestedFileInfoFromFileInfo` (reuse caller metadata) and `GetIngestedFileInfoFromFile` (open + scan).

## Benchmark results

`db_bench` `ingestexternalfile` benchmark, release build, on SSD (btrfs). Files are linked (`move_files`) so the measurement isolates the ingest path rather than file-copy throughput.

| Config | Ingest latency / call (P50) |
| --- | --- |
| Baseline (open + scan each file) | 28,111 us |
| `--ingest_external_file_use_file_info=true` | 18,444 us |

~34% lower median ingest latency by skipping the per-file open + scan (a warm/page-cache number; the gain is larger for cold files).

Command:

```
make clean && DEBUG_LEVEL=0 make -j$(nproc) db_bench
B=/data/$USER/ingest_bench
for fi in false true; do
  rm -rf $B
  ./db_bench --benchmarks=ingestexternalfile --num=1000000 --value_size=100 \
    --compression_type=none --ingest_external_file_batch_size=10 \
    --ingest_external_file_num_batches=10 --disable_auto_compactions=1 \
    --statistics --db=$B --ingest_external_file_use_file_info=$fi 2>&1 \
    | grep rocksdb.ingest.external.file.micros
done
```

## Test Plan

Unit tests in `db/external_sst_file_test.cc`, built with `ASSERT_STATUS_CHECKED=1`:

- `ExternalSSTFileTest.IngestWithFileInfo` -- ingests via `file_infos` (normal options, no `allow_db_generated_files`), asserts the open-and-scan path is not entered (sync point), including data that overlaps existing keys and is reassigned a new global seqno, then verifies the data with `VerifyDBFromMap`.
- `ExternalSSTFileTest.IngestWithFileInfoRangeDeletion` -- a file with a `DeleteRange` ingested via `file_infos` still shadows the covered keys (the writer's range-del bounds are carried in the metadata).
- `ExternalSSTFileTest.IngestWithFileInfoVerifiesChecksum` -- with `verify_checksums_before_ingest`, the fast path opens the file just to verify and still detects corruption.
- `ExternalSSTFileTest.IngestWithFileInfoRejectsWriteGlobalSeqno` -- `write_global_seqno` + `file_infos` is rejected with `InvalidArgument`.
- The shared `GenerateAndAddExternalFile` helper gained an `ingest_with_file_info` mode (and `SstFileWriter::Finish(&info)` capture), so existing ingestion tests (e.g. `IngestFileWithGlobalSeqnoRandomized`) also exercise metadata population.

Full suite: `./external_sst_file_test` -> 207/207 passed.

db_bench unit test: `./db_bench_tool_test --gtest_filter='*IngestExternalFile*'` -> `IngestExternalFile` and `IngestExternalFileWithFileInfo` pass.

Crash/stress: added `--ingest_external_file_use_file_info_one_in` to db_stress and to `db_crashtest.py` defaults. Smoke test with file-info ingestion forced on:

```
python3 tools/db_crashtest.py blackbox --simple --duration=120 --interval=30 \
  --threads=4 --max_key=200000 --ingest_external_file_one_in=5 \
  --ingest_external_file_use_file_info_one_in=1 \
  --test_ingest_standalone_range_deletion_one_in=0
```

-> "Verification successful", 0 key mismatches, no corruption.

@imported-using-ghimport

Differential Revision: [D107721261](https://our.internmc.facebook.com/intern/diff/D107721261/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D107721261/)!
ghstack-source-id: 390599675
2026-06-08 15:59:26 -07:00
2024-02-22 14:39:05 -08:00
2024-10-14 03:01:20 -07:00
2026-05-15 10:59:47 -07:00
2026-05-15 10:59:47 -07:00
2026-05-18 13:35:11 -07:00
2026-02-24 04:47:32 -08:00
2017-10-18 14:42:10 -07:00
2026-05-18 13:35:11 -07:00
2019-08-29 23:21:01 -07:00
2017-12-05 18:42:35 -08:00
2017-04-27 18:06:12 -07:00
2026-05-18 13:35:11 -07:00
2025-08-28 16:59:16 -07:00
2017-07-15 16:11:23 -07:00
2023-11-14 07:33:21 -08:00
2019-06-24 17:40:32 -07:00
2024-12-05 12:09:44 -08:00

RocksDB: A Persistent Key-Value Store for Flash and RAM Storage

CircleCI Status

RocksDB is developed and maintained by Facebook Database Engineering Team. It is built on earlier work on LevelDB by Sanjay Ghemawat (sanjay@google.com) and Jeff Dean (jeff@google.com)

This code is a library that forms the core building block for a fast key-value server, especially suited for storing data on flash drives. It has a Log-Structured-Merge-Database (LSM) design with flexible tradeoffs between Write-Amplification-Factor (WAF), Read-Amplification-Factor (RAF) and Space-Amplification-Factor (SAF). It has multi-threaded compactions, making it especially suitable for storing multiple terabytes of data in a single database.

Start with example usage here: https://github.com/facebook/rocksdb/tree/main/examples

See the github wiki for more explanation.

The public interface is in include/. Callers should not include or rely on the details of any other header files in this package. Those internal APIs may be changed without warning.

Questions and discussions are welcome on the RocksDB Developers Public Facebook group and email list on Google Groups.

License

RocksDB is dual-licensed under both the GPLv2 (found in the COPYING file in the root directory) and Apache 2.0 License (found in the LICENSE.Apache file in the root directory). You may select, at your option, one of the above-listed licenses.

S
Description
No description provided
Readme 394 MiB
Languages
C++ 82.9%
Java 7.7%
C 2.6%
Python 2.2%
Starlark 2%
Other 2.4%