Skip to content

Expose file_checksum and file_checksum_func_name in C API for live files#14532

Open
othmanekn wants to merge 2 commits intofacebook:mainfrom
othmanekn:add-livefiles-checksum-c-api
Open

Expose file_checksum and file_checksum_func_name in C API for live files#14532
othmanekn wants to merge 2 commits intofacebook:mainfrom
othmanekn:add-livefiles-checksum-c-api

Conversation

@othmanekn
Copy link
Copy Markdown

The C++ SstFileMetaData struct (via FileStorageInfo in metadata.h) already exposes file_checksum and file_checksum_func_name fields, which are populated when file_checksum_gen_factory is configured in DBOptions. However, these fields have no corresponding accessors in the C API (c.h), making them inaccessible to language bindings that wrap the C API (e.g., rust-rocksdb, gorocksdb, rocksdb-py).

This PR simply exposes the existing C++ functionality through the C API, following the exact same patterns used by the other rocksdb_livefiles_* accessors.

Changes

Getters (read checksum data from rocksdb_livefiles_t):

  • rocksdb_livefiles_file_checksum(livefiles, index) — returns the file checksum string
  • rocksdb_livefiles_file_checksum_func_name(livefiles, index) — returns the checksum function name (e.g., "FileChecksumCrc32c")

Setters (builder pattern on rocksdb_livefile_t, for symmetry with existing rocksdb_livefile_set_* functions):

  • rocksdb_livefile_set_file_checksum(livefile, checksum)
  • rocksdb_livefile_set_file_checksum_func_name(livefile, func_name)

Test in c_test.c:

  • Opens a DB with FileChecksumGenCrc32cFactory enabled
  • Writes data and flushes to create SST files
  • Verifies that rocksdb_livefiles_file_checksum() returns a non-empty value
  • Verifies that rocksdb_livefiles_file_checksum_func_name() returns "FileChecksumCrc32c"

Motivation

We maintain a distributed key-value store built on RocksDB (via rust-rocksdb, which wraps the C API). During snapshot operations, we need SST file checksums for deduplication. Currently we compute CRC32 checksums ourselves by reading entire SST files from disk, even though RocksDB already computes and stores these checksums internally when file_checksum_gen_factory is configured. Exposing these fields through the C API would eliminate redundant I/O for all C API consumers.

@meta-cla meta-cla bot added the CLA Signed label Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant