Skip to content

Commit

Permalink
add config to disable upload page data when do checkpoint (#7753)
Browse files Browse the repository at this point in the history
ref #6827
  • Loading branch information
lidezhu authored Jul 10, 2023
1 parent 5dfb465 commit 641a36b
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 8 deletions.
1 change: 1 addition & 0 deletions dbms/src/Interpreters/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ struct Settings
M(SettingInt64, dt_compression_level, 1, "The compression level.") \
\
M(SettingInt64, remote_checkpoint_interval_seconds, 30, "The interval of uploading checkpoint to the remote store. Unit is second.") \
M(SettingBool, remote_checkpoint_only_upload_manifest, true, "Only upload manifest data when uploading checkpoint") \
M(SettingInt64, remote_gc_method, 1, "The method of running GC task on the remote store. 1 - lifecycle, 2 - scan.") \
M(SettingInt64, remote_gc_interval_seconds, 3600, "The interval of running GC task on the remote store. Unit is second.") \
M(SettingInt64, remote_gc_verify_consistency, 0, "Verify the consistenct of valid locks when doing GC") \
Expand Down
9 changes: 8 additions & 1 deletion dbms/src/Storages/Page/V3/CheckpointFile/CPFilesWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <Storages/Page/V3/Universal/UniversalPageIdFormatImpl.h>
#include <fmt/core.h>

#include <memory>
#include <unordered_map>

namespace DB::PS::V3
Expand Down Expand Up @@ -67,7 +68,8 @@ void CPFilesWriter::writePrefix(const CPFilesWriter::PrefixInfo & info)

CPDataDumpStats CPFilesWriter::writeEditsAndApplyCheckpointInfo(
universal::PageEntriesEdit & edits,
const CPFilesWriter::CompactOptions & options)
const CPFilesWriter::CompactOptions & options,
bool manifest_only)
{
RUNTIME_CHECK_MSG(write_stage == WriteStage::WritingEdits, "unexpected write stage {}", magic_enum::enum_name(write_stage));

Expand Down Expand Up @@ -132,6 +134,11 @@ CPDataDumpStats CPFilesWriter::writeEditsAndApplyCheckpointInfo(
}

assert(rec_edit.type == EditRecordType::VAR_ENTRY);
// No need to read and write page data for the manifest only checkpoint.
if (manifest_only)
{
continue;
}
bool is_compaction = false;
if (rec_edit.entry.checkpoint_info.has_value())
{
Expand Down
3 changes: 2 additions & 1 deletion dbms/src/Storages/Page/V3/CheckpointFile/CPFilesWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class CPFilesWriter : private boost::noncopyable
};
CPDataDumpStats writeEditsAndApplyCheckpointInfo(
universal::PageEntriesEdit & edit,
const CompactOptions & options = CompactOptions(false));
const CompactOptions & options = CompactOptions(false),
bool manifest_only = false);

/**
* This function must be called, and must be called last, after other `writeXxx`.
Expand Down
7 changes: 5 additions & 2 deletions dbms/src/Storages/Page/V3/PageEntriesEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ CheckpointProto::EditRecord PageEntriesEdit<UniversalPageId>::EditRecord::toProt
proto_edit.set_version_epoch(version.epoch);
if (type == EditRecordType::VAR_ENTRY)
{
RUNTIME_CHECK(entry.checkpoint_info.has_value());
proto_edit.set_entry_size(entry.size);
proto_edit.set_entry_tag(entry.tag);
proto_edit.set_entry_checksum(entry.checksum);
proto_edit.mutable_entry_location()->CopyFrom(entry.checkpoint_info.data_location.toProto());
// uploading page data may be disabled
if (entry.checkpoint_info.has_value())
{
proto_edit.mutable_entry_location()->CopyFrom(entry.checkpoint_info.data_location.toProto());
}
for (const auto & [offset, checksum] : entry.field_offsets)
{
proto_edit.add_entry_fields_offset(offset);
Expand Down
13 changes: 9 additions & 4 deletions dbms/src/Storages/Page/V3/Universal/UniversalPageStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,13 @@ PS::V3::CPDataDumpStats UniversalPageStorage::dumpIncrementalCheckpoint(const Un
if (options.override_sequence)
sequence = options.override_sequence.value();


// The output of `PageDirectory::dumpSnapshotToEdit` may contain page ids which are logically deleted but have not been gced yet.
// These page ids may be GC-ed when dumping snapshot, so we cannot read data of these page ids.
// So we create a clean temp page_directory here and use it to dump edits with all visible page ids for `snap`.
// But if we just upload manifest without reading page data, we can skip this step.
if (!options.only_upload_manifest)
{
// The output of `PageDirectory::dumpSnapshotToEdit` may contain page ids which are logically deleted but have not been gced yet.
// These page ids may be GC-ed when dumping snapshot, so we cannot read data of these page ids.
// So we create a clean temp page_directory here and use it to dump edits with all visible page ids for `snap`.
PS::V3::universal::PageDirectoryFactory factory;
auto temp_page_directory = factory.dangerouslyCreateFromEditWithoutWAL(fmt::format("{}_{}", storage_name, sequence), edit_from_mem);
edit_from_mem = temp_page_directory->dumpSnapshotToEdit();
Expand Down Expand Up @@ -494,7 +497,8 @@ PS::V3::CPDataDumpStats UniversalPageStorage::dumpIncrementalCheckpoint(const Un
// get the remote file ids that need to be compacted
const auto checkpoint_dump_stats = writer->writeEditsAndApplyCheckpointInfo(
edit_from_mem,
compact_opts);
compact_opts,
options.only_upload_manifest);
auto data_file_paths = writer->writeSuffix();
writer.reset();
auto dump_data_seconds = sw.elapsedMillisecondsFromLastTime() / 1000.0;
Expand All @@ -521,6 +525,7 @@ PS::V3::CPDataDumpStats UniversalPageStorage::dumpIncrementalCheckpoint(const Un
{
// Copy back the checkpoint info to the current PageStorage.
// New checkpoint infos are attached in `writeEditsAndApplyCheckpointInfo`.
RUNTIME_CHECK(!options.only_upload_manifest);
page_directory->copyCheckpointInfoFromEdit(edit_from_mem);
}
auto copy_checkpoint_info_seconds = sw.elapsedMillisecondsFromLastTime() / 1000.0;
Expand Down
5 changes: 5 additions & 0 deletions dbms/src/Storages/Page/V3/Universal/UniversalPageStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ class UniversalPageStorage final
*/
const std::function<std::unordered_set<String>()> compact_getter = nullptr;

/**
* Only upload the manifest file.
*/
bool only_upload_manifest = false;

UInt64 max_data_file_size = 256 * 1024 * 1024; // 256MB
UInt64 max_edit_records_per_part = 100000;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ bool UniversalPageStorageService::uploadCheckpointImpl(
.remote_store = remote_store,
.log = log,
},
.only_upload_manifest = settings.remote_checkpoint_only_upload_manifest,
};

const auto write_stats = uni_page_storage->dumpIncrementalCheckpoint(opts);
Expand Down
13 changes: 13 additions & 0 deletions dbms/src/Storages/Page/V3/Universal/tests/gtest_checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,12 +953,23 @@ class UniversalPageStorageServiceCheckpointTest : public DB::base::TiFlashStorag
void SetUp() override
{
TiFlashStorageTestBasic::SetUp();
auto & global_context = DB::tests::TiFlashTestEnv::getGlobalContext();
auto & settings = global_context.getSettingsRef();
old_remote_checkpoint_only_upload_manifest = settings.remote_checkpoint_only_upload_manifest;
settings.remote_checkpoint_only_upload_manifest = false;
uni_ps_service = newService();
log = Logger::get("UniversalPageStorageServiceCheckpointTest");
s3_client = S3::ClientFactory::instance().sharedTiFlashClient();
ASSERT_TRUE(::DB::tests::TiFlashTestEnv::createBucketIfNotExist(*s3_client));
}

void TearDown() override
{
auto & global_context = DB::tests::TiFlashTestEnv::getGlobalContext();
auto & settings = global_context.getSettingsRef();
settings.remote_checkpoint_only_upload_manifest = old_remote_checkpoint_only_upload_manifest;
}

static UniversalPageStorageServicePtr newService()
{
auto path = getTemporaryPath();
Expand Down Expand Up @@ -1003,6 +1014,8 @@ class UniversalPageStorageServiceCheckpointTest : public DB::base::TiFlashStorag
UInt64 tag = 0;
UInt64 store_id = 2;

bool old_remote_checkpoint_only_upload_manifest;

LoggerPtr log;
};

Expand Down

0 comments on commit 641a36b

Please sign in to comment.