1
0
mirror of https://github.com/facebook/rocksdb.git synced 2026-10-23 08:09:02 +03:00

Expose kLatestSupportedFormatVersion in BlockBasedTableOptions (#15397)

Summary:
Before this change, the highest supported block-based table format_version was only available as the internal constant kLatestBbtFormatVersion in table/format.h. Applications that accept a format_version setting from users or configuration (especially for SetOptions()) had no public way to validate it against the linked RocksDB build before applying it.

This adds the public constant
BlockBasedTableOptions::kLatestSupportedFormatVersion (currently 8) and removes kLatestBbtFormatVersion, redirecting all internal and test uses to the new constant. Supported-version checks and option validation are unchanged: format_version above the constant is still rejected as InvalidArgument, and draft format_versions remain usable only under the TEST-only TEST_AllowUnsupportedFormatVersion() hook.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/15397

Test Plan: Same value and same checks, so no new tests. Existing format_version validation coverage (e.g. TableTest.UnsupportedFormatVersionConfigTest) and the FormatLatest test instantiations now go through the public constant.

Reviewed By: rban1

Differential Revision: D125117976

Pulled By: pdillinger

fbshipit-source-id: 67e0c5b7eade4bf649957435aa0b28b187793f7c
This commit is contained in:
Peter Dillinger
2026-10-19 06:32:23 -07:00
committed by meta-codesync[bot]
parent 54732b0c8f
commit 8121c7e254
10 changed files with 39 additions and 29 deletions

View File

@@ -546,8 +546,9 @@ class ColumnFamilyTest
INSTANTIATE_TEST_CASE_P(FormatDef, ColumnFamilyTest,
testing::Values(test::kDefaultFormatVersion));
INSTANTIATE_TEST_CASE_P(FormatLatest, ColumnFamilyTest,
testing::Values(kLatestBbtFormatVersion));
INSTANTIATE_TEST_CASE_P(
FormatLatest, ColumnFamilyTest,
testing::Values(BlockBasedTableOptions::kLatestSupportedFormatVersion));
TEST_P(ColumnFamilyTest, DontReuseColumnFamilyID) {
for (int iter = 0; iter < 3; ++iter) {
@@ -737,8 +738,11 @@ INSTANTIATE_TEST_CASE_P(
std::make_tuple(test::kDefaultFormatVersion, false)));
INSTANTIATE_TEST_CASE_P(
FormatLatest, FlushEmptyCFTestWithParam,
testing::Values(std::make_tuple(kLatestBbtFormatVersion, true),
std::make_tuple(kLatestBbtFormatVersion, false)));
testing::Values(
std::make_tuple(BlockBasedTableOptions::kLatestSupportedFormatVersion,
true),
std::make_tuple(BlockBasedTableOptions::kLatestSupportedFormatVersion,
false)));
TEST_P(ColumnFamilyTest, AddDrop) {
Open();
@@ -4170,7 +4174,9 @@ TEST(ColumnFamilyTest, ValidateMemtableKVChecksumOption) {
// the behavior of manual flush is that it skips retaining UDTs.
class ColumnFamilyRetainUDTTest : public ColumnFamilyTestBase {
public:
ColumnFamilyRetainUDTTest() : ColumnFamilyTestBase(kLatestBbtFormatVersion) {}
ColumnFamilyRetainUDTTest()
: ColumnFamilyTestBase(
BlockBasedTableOptions::kLatestSupportedFormatVersion) {}
void SetUp() override {
db_options_.allow_concurrent_memtable_write = false;

View File

@@ -315,8 +315,9 @@ class ComparatorDBTest
INSTANTIATE_TEST_CASE_P(FormatDef, ComparatorDBTest,
testing::Values(test::kDefaultFormatVersion));
INSTANTIATE_TEST_CASE_P(FormatLatest, ComparatorDBTest,
testing::Values(kLatestBbtFormatVersion));
INSTANTIATE_TEST_CASE_P(
FormatLatest, ComparatorDBTest,
testing::Values(BlockBasedTableOptions::kLatestSupportedFormatVersion));
TEST_P(ComparatorDBTest, Bytewise) {
for (int rand_seed = 301; rand_seed < 306; rand_seed++) {

View File

@@ -917,14 +917,15 @@ INSTANTIATE_TEST_CASE_P(
::testing::Values(
std::make_tuple(kAutoBloom,
FilterPartitioning::kCoupledPartitionedFilter,
kLatestBbtFormatVersion),
BlockBasedTableOptions::kLatestSupportedFormatVersion),
std::make_tuple(kAutoBloom,
FilterPartitioning::kDecoupledPartitionedFilter,
kLatestBbtFormatVersion),
BlockBasedTableOptions::kLatestSupportedFormatVersion),
std::make_tuple(kAutoBloom, FilterPartitioning::kUnpartitionedFilter,
kLatestBbtFormatVersion),
std::make_tuple(kAutoRibbon, FilterPartitioning::kUnpartitionedFilter,
kLatestBbtFormatVersion)));
BlockBasedTableOptions::kLatestSupportedFormatVersion),
std::make_tuple(
kAutoRibbon, FilterPartitioning::kUnpartitionedFilter,
BlockBasedTableOptions::kLatestSupportedFormatVersion)));
#endif // !defined(ROCKSDB_VALGRIND_RUN) || defined(ROCKSDB_FULL_VALGRIND_RUN)
TEST_F(DBBloomFilterTest, BloomFilterRate) {

View File

@@ -535,7 +535,8 @@ Options DBTestBase::GetOptions(
}
case kBlockBasedTableWithLatestFormat: {
// In case different from default
table_options.format_version = kLatestBbtFormatVersion;
table_options.format_version =
BlockBasedTableOptions::kLatestSupportedFormatVersion;
break;
}
case kOptimizeFiltersForHits: {

View File

@@ -766,6 +766,11 @@ struct BlockBasedTableOptions {
// who might only upgrade a few times per year.
uint32_t format_version = 7;
// Latest format_version supported by this version of RocksDB for both
// reading and writing SST files. Setting format_version higher than this is
// rejected as InvalidArgument (e.g. by DB::Open() or SetOptions()).
static constexpr uint32_t kLatestSupportedFormatVersion = 8;
// When true, data blocks store keys and values separately. Keys are stored
// at the beginning of the block, followed by values at the end. This can
// improve read performance at a cost of a varint per restart interval (~1 bit

View File

@@ -405,7 +405,8 @@ INSTANTIATE_TEST_CASE_P(
FormatVersions, PartitionedFilterBlockTest,
testing::Combine(
testing::ValuesIn(std::set<uint32_t>{
2, 3, 4, 5, test::kDefaultFormatVersion, kLatestBbtFormatVersion}),
2, 3, 4, 5, test::kDefaultFormatVersion,
BlockBasedTableOptions::kLatestSupportedFormatVersion}),
testing::ValuesIn(test::GetUDTTestModes()), testing::Bool()));
TEST_P(PartitionedFilterBlockTest, EmptyBuilder) {

View File

@@ -180,13 +180,6 @@ inline uint32_t ChecksumModifierForContext(uint32_t base_context_checksum,
return modifier & all_or_nothing;
}
// Latest format_version supported for both reading and writing new SST files in
// block-based format. Newer "draft" format_versions that are still in
// development are not published: they are exercised only in tests, gated behind
// the TEST-only TEST_AllowUnsupportedFormatVersion() hook, and are neither
// readable nor writable in production until finalized by bumping this constant.
constexpr uint32_t kLatestBbtFormatVersion = 8;
// Sentinel for "no format_version known yet," e.g. a Footer that has not been
// populated by DecodeFrom. Deliberately larger than any real version so that
// accidentally treating it as one is caught by the FormatVersionUses*
@@ -213,7 +206,7 @@ static_assert(kMinSupportedBbtFormatVersionForWrite >=
inline bool IsSupportedFormatVersionForRead(uint64_t magic, uint32_t version) {
if (magic == kBlockBasedTableMagicNumber) {
return version >= kMinSupportedBbtFormatVersionForRead &&
version <= kLatestBbtFormatVersion;
version <= BlockBasedTableOptions::kLatestSupportedFormatVersion;
} else if (magic == kPlainTableMagicNumber) {
return version == 0;
} else if (magic == kCuckooTableMagicNumber) {
@@ -226,7 +219,7 @@ inline bool IsSupportedFormatVersionForRead(uint64_t magic, uint32_t version) {
inline bool IsSupportedFormatVersionForWrite(uint64_t magic, uint32_t version) {
if (magic == kBlockBasedTableMagicNumber) {
return version >= kMinSupportedBbtFormatVersionForWrite &&
version <= kLatestBbtFormatVersion;
version <= BlockBasedTableOptions::kLatestSupportedFormatVersion;
} else if (magic == kPlainTableMagicNumber) {
return version == 0;
} else if (magic == kCuckooTableMagicNumber) {

View File

@@ -763,8 +763,9 @@ static std::vector<TestArgs> GenerateArgList() {
for (auto num_threads : compression_parallel_threads) {
// format_version = 7 changes some compression handling; 8 adds the
// index value-delta escape and the common-key-prefix feature.
for (uint32_t fv : {kMinSupportedBbtFormatVersionForRead, 7U,
kLatestBbtFormatVersion}) {
for (uint32_t fv :
{kMinSupportedBbtFormatVersionForRead, 7U,
BlockBasedTableOptions::kLatestSupportedFormatVersion}) {
TestArgs one_arg;
one_arg.type = test_type;
one_arg.reverse_compare = reverse_compare;
@@ -5868,12 +5869,13 @@ TEST(TableTest, UnsupportedFormatVersionConfigTest) {
ASSERT_OK(s) << "format_version=" << fv << ": " << s.ToString();
}
// Test that format_version > kLatestBbtFormatVersion is rejected by
// Test that format_version > kLatestSupportedFormatVersion is rejected by
// ValidateOptions (not sanitized, since it could be a future version that
// requires newer code)
{
BlockBasedTableOptions table_options;
table_options.format_version = kLatestBbtFormatVersion + 1;
table_options.format_version =
BlockBasedTableOptions::kLatestSupportedFormatVersion + 1;
BlockBasedTableFactory factory(table_options);
ColumnFamilyOptions cf_opts;

View File

@@ -45,7 +45,7 @@ const std::set<uint32_t> kFooterFormatVersionsToTest{
6U,
// In case any interesting future changes
kDefaultFormatVersion,
kLatestBbtFormatVersion,
BlockBasedTableOptions::kLatestSupportedFormatVersion,
// Unpublished draft format_version 8 (index value-delta escape). Writing it
// requires the TEST_AllowUnsupportedFormatVersion() opt-in, enabled by the
// test files that instantiate parameterized suites over this set.

View File

@@ -603,7 +603,7 @@ int SSTDumpTool::Run(int argc, char const* const* argv, Options options) {
}
bbto.block_size = 16384; // A popular choice for default
// Maximize compression features available
bbto.format_version = kLatestBbtFormatVersion;
bbto.format_version = BlockBasedTableOptions::kLatestSupportedFormatVersion;
for (int i = 1; i < argc; i++) {
if (strncmp(argv[i], "--env_uri=", 10) == 0) {