Skip to content

Commit

Permalink
Storage: Abort adding vector index if encryption enabled (#9504)
Browse files Browse the repository at this point in the history
ref #9032, close #9505

Storage: Abort adding vector index if encryption enabled
  • Loading branch information
JaySon-Huang authored Oct 10, 2024
1 parent 02784a4 commit cea728d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <Common/Exception.h>
#include <Common/SyncPoint/SyncPoint.h>
#include <Common/TiFlashMetrics.h>
#include <IO/FileProvider/FileProvider.h>
#include <Interpreters/Context.h>
#include <Storages/DeltaMerge/DMContext.h>
#include <Storages/DeltaMerge/DeltaMergeStore.h>
Expand Down Expand Up @@ -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());
Expand Down
7 changes: 4 additions & 3 deletions dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
23 changes: 21 additions & 2 deletions dbms/src/Storages/DeltaMerge/ScanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit cea728d

Please sign in to comment.