-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storages: support building vector index for ColumnFileTiny (Part 1) #9534
Open
Lloyd-Pottiger
wants to merge
5
commits into
pingcap:master
Choose a base branch
from
Lloyd-Pottiger:cf-tiny-vector-index
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+424
−99
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
624b577
Storages: support building vector index for ColumnFileTiny (Part 1)
Lloyd-Pottiger 5136336
add unit test
Lloyd-Pottiger 919d531
Update dbms/src/Storages/DeltaMerge/tests/gtest_column_file_clone.cpp
Lloyd-Pottiger 9a8b341
acquire lock
Lloyd-Pottiger 1c84e18
Merge branch 'master' into cf-tiny-vector-index
ti-chi-bot[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
#include <Storages/DeltaMerge/DMContext_fwd.h> | ||
#include <Storages/DeltaMerge/Remote/Serializer_fwd.h> | ||
#include <Storages/DeltaMerge/dtpb/column_file.pb.h> | ||
#include <Storages/DeltaMerge/dtpb/vector_index.pb.h> | ||
#include <Storages/Page/PageStorage_fwd.h> | ||
|
||
namespace DB::DM | ||
|
@@ -34,9 +35,18 @@ using ColumnFileTinyPtr = std::shared_ptr<ColumnFileTiny>; | |
/// 2. created when flushed `ColumnFileInMemory` to disk | ||
class ColumnFileTiny : public ColumnFilePersisted | ||
{ | ||
public: | ||
friend class ColumnFileTinyReader; | ||
friend struct Remote::Serializer; | ||
|
||
struct IndexInfo | ||
{ | ||
PageIdU64 index_page_id{}; | ||
std::optional<dtpb::VectorIndexFileProps> vector_index = std::nullopt; | ||
breezewish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
using IndexInfos = std::vector<IndexInfo>; | ||
using IndexInfosPtr = std::shared_ptr<IndexInfos>; | ||
|
||
private: | ||
ColumnFileSchemaPtr schema; | ||
|
||
|
@@ -51,6 +61,9 @@ class ColumnFileTiny : public ColumnFilePersisted | |
/// Maybe we should just drop this field, and store the data_page_size in somewhere else. | ||
UInt64 data_page_size = 0; | ||
|
||
/// The index information of this file. | ||
IndexInfosPtr index_infos; | ||
|
||
/// The id of the keyspace which this ColumnFileTiny belongs to. | ||
KeyspaceID keyspace_id; | ||
/// The global file_provider | ||
|
@@ -87,17 +100,29 @@ class ColumnFileTiny : public ColumnFilePersisted | |
UInt64 bytes_, | ||
PageIdU64 data_page_id_, | ||
const DMContext & dm_context, | ||
const IndexInfosPtr & index_infos_ = nullptr, | ||
const CachePtr & cache_ = nullptr); | ||
|
||
Type getType() const override { return Type::TINY_FILE; } | ||
|
||
size_t getRows() const override { return rows; } | ||
size_t getBytes() const override { return bytes; } | ||
|
||
IndexInfosPtr getIndexInfos() const { return index_infos; } | ||
bool hasIndex(Int64 index_id) const | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
if (!index_infos) | ||
return false; | ||
return std::any_of(index_infos->cbegin(), index_infos->cend(), [index_id](const auto & info) { | ||
if (!info.vector_index) | ||
return false; | ||
return info.vector_index->index_id() == index_id; | ||
}); | ||
} | ||
|
||
auto getCache() const { return cache; } | ||
void clearCache() { cache = {}; } | ||
|
||
/// The schema of this pack. Could be empty, i.e. a DeleteRange does not have a schema. | ||
ColumnFileSchemaPtr getSchema() const { return schema; } | ||
|
||
ColumnFileTinyPtr cloneWith(PageIdU64 new_data_page_id) | ||
|
@@ -107,6 +132,14 @@ class ColumnFileTiny : public ColumnFilePersisted | |
return new_tiny_file; | ||
} | ||
|
||
ColumnFileTinyPtr cloneWith(PageIdU64 new_data_page_id, const IndexInfosPtr & index_infos_) const | ||
{ | ||
auto new_tiny_file = std::make_shared<ColumnFileTiny>(*this); | ||
new_tiny_file->data_page_id = new_data_page_id; | ||
new_tiny_file->index_infos = index_infos_; | ||
return new_tiny_file; | ||
} | ||
|
||
ColumnFileReaderPtr getReader( | ||
const DMContext &, | ||
const IColumnFileDataProviderPtr & data_provider, | ||
|
@@ -165,7 +198,8 @@ class ColumnFileTiny : public ColumnFilePersisted | |
BlockPtr schema, | ||
PageIdU64 data_page_id, | ||
size_t rows, | ||
size_t bytes); | ||
size_t bytes, | ||
IndexInfosPtr index_infos); | ||
static std::tuple<ColumnFilePersistedPtr, BlockPtr> createFromCheckpoint( | ||
const LoggerPtr & parent_log, | ||
const DMContext & context, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How to ensure that the page must exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workflow is
So if new meta page was uploaded, the new log page must be uploaded.