Skip to content

Commit

Permalink
Storages: Refine FormatVersion (#9739)
Browse files Browse the repository at this point in the history
ref #6233

Signed-off-by: JaySon-Huang <[email protected]>

Co-authored-by: JaySon-Huang <[email protected]>
  • Loading branch information
JinheLin and JaySon-Huang authored Dec 24, 2024
1 parent a55423c commit 29d4b4f
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 53 deletions.
26 changes: 12 additions & 14 deletions dbms/src/Server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,26 +983,25 @@ int Server::main(const std::vector<std::string> & /*args*/)

if (storage_config.format_version != 0)
{
if (storage_config.s3_config.isS3Enabled() && storage_config.format_version != STORAGE_FORMAT_V100.identifier
&& storage_config.format_version != STORAGE_FORMAT_V101.identifier
&& storage_config.format_version != STORAGE_FORMAT_V102.identifier)
if (storage_config.s3_config.isS3Enabled() && !isStorageFormatForDisagg(storage_config.format_version))
{
LOG_WARNING(log, "'storage.format_version' must be set to 100/101/102 when S3 is enabled!");
throw Exception(
ErrorCodes::INVALID_CONFIG_PARAMETER,
"'storage.format_version' must be set to 100/101/102 when S3 is enabled!");
auto message = fmt::format(
"'storage.format_version' must be set to {} when S3 is enabled!",
getStorageFormatsForDisagg());
LOG_ERROR(log, message);
throw Exception(ErrorCodes::INVALID_CONFIG_PARAMETER, message);
}
setStorageFormat(storage_config.format_version);
LOG_INFO(log, "Using format_version={} (explicit storage format detected).", storage_config.format_version);
LOG_INFO(log, "Using format_version={} (explicit storage format detected).", STORAGE_FORMAT_CURRENT.identifier);
}
else
{
if (storage_config.s3_config.isS3Enabled())
{
// If the user does not explicitly set format_version in the config file but
// enables S3, then we set up a proper format version to support S3.
setStorageFormat(STORAGE_FORMAT_V102.identifier);
LOG_INFO(log, "Using format_version={} (infer by S3 is enabled).", STORAGE_FORMAT_V102.identifier);
setStorageFormat(DEFAULT_STORAGE_FORMAT_FOR_DISAGG.identifier);
LOG_INFO(log, "Using format_version={} (infer by S3 is enabled).", STORAGE_FORMAT_CURRENT.identifier);
}
else
{
Expand All @@ -1016,10 +1015,9 @@ int Server::main(const std::vector<std::string> & /*args*/)
{
if (auto disaggregated_mode = getDisaggregatedMode(config()); disaggregated_mode == DisaggregatedMode::None)
{
LOG_WARNING(log, "'flash.disaggregated_mode' must be set when S3 is enabled!");
throw Exception(
ErrorCodes::INVALID_CONFIG_PARAMETER,
"'flash.disaggregated_mode' must be set when S3 is enabled!");
const String message = "'flash.disaggregated_mode' must be set when S3 is enabled!";
LOG_ERROR(log, message);
throw Exception(ErrorCodes::INVALID_CONFIG_PARAMETER, message);
}
}

Expand Down
84 changes: 84 additions & 0 deletions dbms/src/Storages/FormatVersion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2024 PingCAP, Inc.
//
// 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.

#include <Common/Exception.h>
#include <Storages/FormatVersion.h>

namespace DB
{

namespace
{
const StorageFormatVersion & toStorageFormat(UInt64 setting)
{
switch (setting)
{
case 1:
return STORAGE_FORMAT_V1;
case 2:
return STORAGE_FORMAT_V2;
case 3:
return STORAGE_FORMAT_V3;
case 4:
return STORAGE_FORMAT_V4;
case 5:
return STORAGE_FORMAT_V5;
case 6:
return STORAGE_FORMAT_V6;
case 7:
return STORAGE_FORMAT_V7;
case 8:
return STORAGE_FORMAT_V8;
case 100:
return STORAGE_FORMAT_V100;
case 101:
return STORAGE_FORMAT_V101;
case 102:
return STORAGE_FORMAT_V102;
case 103:
return STORAGE_FORMAT_V103;
default:
throw Exception(ErrorCodes::LOGICAL_ERROR, "Illegal setting value: {}", setting);
}
}
} // namespace

std::span<const size_t> getStorageFormatsForDisagg()
{
static const auto formats = std::array{
STORAGE_FORMAT_V100.identifier,
STORAGE_FORMAT_V101.identifier,
STORAGE_FORMAT_V102.identifier,
STORAGE_FORMAT_V103.identifier};
return formats;
}

bool isStorageFormatForDisagg(UInt64 version)
{
return std::any_of(getStorageFormatsForDisagg().begin(), getStorageFormatsForDisagg().end(), [version](UInt64 v) {
return v == version;
});
}

void setStorageFormat(UInt64 setting)
{
STORAGE_FORMAT_CURRENT = toStorageFormat(setting);
}

void setStorageFormat(const StorageFormatVersion & version)
{
STORAGE_FORMAT_CURRENT = version;
}

} // namespace DB
48 changes: 9 additions & 39 deletions dbms/src/Storages/FormatVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

#pragma once

#include <Common/Exception.h>
#include <Core/Types.h>
#include <IO/WriteHelpers.h>

#include <span>

namespace DB
{
Expand Down Expand Up @@ -202,45 +202,15 @@ inline static const StorageFormatVersion STORAGE_FORMAT_V103 = StorageFormatVers
.identifier = 103,
};

// Default storage format for non-disaggregated mode
inline StorageFormatVersion STORAGE_FORMAT_CURRENT = STORAGE_FORMAT_V7;
// Default storage format for disaggregated mode
inline static const StorageFormatVersion DEFAULT_STORAGE_FORMAT_FOR_DISAGG = STORAGE_FORMAT_V102;

inline const StorageFormatVersion & toStorageFormat(UInt64 setting)
{
switch (setting)
{
case 1:
return STORAGE_FORMAT_V1;
case 2:
return STORAGE_FORMAT_V2;
case 3:
return STORAGE_FORMAT_V3;
case 4:
return STORAGE_FORMAT_V4;
case 5:
return STORAGE_FORMAT_V5;
case 6:
return STORAGE_FORMAT_V6;
case 7:
return STORAGE_FORMAT_V7;
case 100:
return STORAGE_FORMAT_V100;
case 101:
return STORAGE_FORMAT_V101;
case 102:
return STORAGE_FORMAT_V102;
default:
throw Exception(ErrorCodes::LOGICAL_ERROR, "Illegal setting value: {}", setting);
}
}

inline void setStorageFormat(UInt64 setting)
{
STORAGE_FORMAT_CURRENT = toStorageFormat(setting);
}
bool isStorageFormatForDisagg(UInt64 version);
std::span<const size_t> getStorageFormatsForDisagg();

inline void setStorageFormat(const StorageFormatVersion & version)
{
STORAGE_FORMAT_CURRENT = version;
}
void setStorageFormat(UInt64 setting);
void setStorageFormat(const StorageFormatVersion & version);

} // namespace DB

0 comments on commit 29d4b4f

Please sign in to comment.