From cea728d5d2bad7766dfc5e97cdf8ef16fe4a791f Mon Sep 17 00:00:00 2001 From: JaySon Date: Thu, 10 Oct 2024 10:50:03 +0800 Subject: [PATCH] Storage: Abort adding vector index if encryption enabled (#9504) ref pingcap/tiflash#9032, close pingcap/tiflash#9505 Storage: Abort adding vector index if encryption enabled --- .../DeltaMergeStore_InternalSegment.cpp | 9 ++++++++ .../DeltaMerge/File/DMFilePackFilter.cpp | 7 +++--- .../File/DMFileV3IncrementWriter.cpp | 2 +- dbms/src/Storages/DeltaMerge/ScanContext.cpp | 23 +++++++++++++++++-- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/dbms/src/Storages/DeltaMerge/DeltaMergeStore_InternalSegment.cpp b/dbms/src/Storages/DeltaMerge/DeltaMergeStore_InternalSegment.cpp index ffad4bd1a84..28800033657 100644 --- a/dbms/src/Storages/DeltaMerge/DeltaMergeStore_InternalSegment.cpp +++ b/dbms/src/Storages/DeltaMerge/DeltaMergeStore_InternalSegment.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -543,6 +544,14 @@ bool DeltaMergeStore::segmentEnsureStableIndexAsync(const SegmentPtr & segment) if (!build_info.indexes_to_build || build_info.indexes_to_build->empty() || build_info.dm_files.empty()) return false; + if (auto encryption_enabled = global_context.getFileProvider()->isEncryptionEnabled(); encryption_enabled) + { + segment->setIndexBuildError( + build_info.indexesIDs(), + "Encryption-at-rest on TiFlash is enabled, which does not support building vector index"); + return false; + } + auto store_weak_ptr = weak_from_this(); auto tracing_id = fmt::format("segmentEnsureStableIndex<{}> source_segment={}", log->identifier(), segment->simpleInfo()); diff --git a/dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.cpp b/dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.cpp index 97a2e9c71ad..d72ca60ada2 100644 --- a/dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.cpp +++ b/dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.cpp @@ -197,8 +197,9 @@ void DMFilePackFilter::loadIndex( if (info == dmfile_meta->merged_sub_file_infos.end()) { throw Exception( - fmt::format("Unknown index file {}", dmfile->colIndexPath(file_name_base)), - ErrorCodes::LOGICAL_ERROR); + ErrorCodes::LOGICAL_ERROR, + "Unknown index file {}", + dmfile->colIndexPath(file_name_base)); } auto file_path = dmfile->meta->mergedPath(info->second.number); @@ -221,7 +222,7 @@ void DMFilePackFilter::loadIndex( auto buf = ChecksumReadBufferBuilder::build( std::move(raw_data), - dmfile->colDataPath(file_name_base), + dmfile->colIndexPath(file_name_base), // just for debug dmfile->getConfiguration()->getChecksumFrameLength(), dmfile->getConfiguration()->getChecksumAlgorithm(), dmfile->getConfiguration()->getChecksumFrameLength()); diff --git a/dbms/src/Storages/DeltaMerge/File/DMFileV3IncrementWriter.cpp b/dbms/src/Storages/DeltaMerge/File/DMFileV3IncrementWriter.cpp index 9c666d9a3de..c716a0c8ab7 100644 --- a/dbms/src/Storages/DeltaMerge/File/DMFileV3IncrementWriter.cpp +++ b/dbms/src/Storages/DeltaMerge/File/DMFileV3IncrementWriter.cpp @@ -150,7 +150,7 @@ void DMFileV3IncrementWriter::writeAndIncludeMetaFile() options.file_provider, meta_file_path_for_write, // Must not use meta->metaPath(), because DMFile may be a S3 DMFile EncryptionPath(local_path, meta_file_name), - /*create_new_encryption_info*/ true, + /*create_new_encryption_info*/ false, // must be false to reuse the encryption_info of exisiting dmfile options.write_limiter, DMFileMetaV2::meta_buffer_size); diff --git a/dbms/src/Storages/DeltaMerge/ScanContext.cpp b/dbms/src/Storages/DeltaMerge/ScanContext.cpp index 9be10ed8059..64191ac89f9 100644 --- a/dbms/src/Storages/DeltaMerge/ScanContext.cpp +++ b/dbms/src/Storages/DeltaMerge/ScanContext.cpp @@ -119,8 +119,11 @@ String ScanContext::toJson() const json->set("read_bytes", user_read_bytes.load()); - json->set("disagg_cache_hit_size", disagg_read_cache_hit_size.load()); - json->set("disagg_cache_miss_size", disagg_read_cache_miss_size.load()); + if (disagg_read_cache_hit_size.load() > 0 && disagg_read_cache_miss_size.load() > 0) + { + json->set("disagg_cache_hit_size", disagg_read_cache_hit_size.load()); + json->set("disagg_cache_miss_size", disagg_read_cache_miss_size.load()); + } json->set("num_segments", num_segments.load()); json->set("num_read_tasks", num_read_tasks.load()); @@ -164,6 +167,22 @@ String ScanContext::toJson() const }; json->set("region_num_of_instance", to_json_array(region_num_of_instance)); + if (total_vector_idx_load_from_cache.load() // + + total_vector_idx_load_from_disk.load() // + + total_vector_idx_load_from_s3.load() + > 0) + { + Poco::JSON::Object::Ptr vec_idx = new Poco::JSON::Object(); + vec_idx->set("tot_load", total_vector_idx_load_time_ms.load()); + vec_idx->set("load_s3", total_vector_idx_load_from_s3.load()); + vec_idx->set("load_disk", total_vector_idx_load_from_disk.load()); + vec_idx->set("load_cache", total_vector_idx_load_from_cache.load()); + vec_idx->set("tot_search", total_vector_idx_search_time_ms.load()); + vec_idx->set("read_vec", total_vector_idx_read_vec_time_ms.load()); + vec_idx->set("read_others", total_vector_idx_read_others_time_ms.load()); + json->set("vector_idx", vec_idx); + } + std::stringstream buf; json->stringify(buf); return buf.str();