Skip to content
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

storage: Use mmap to view vector index #9313

Merged
merged 18 commits into from
Aug 26, 2024

Conversation

Lloyd-Pottiger
Copy link
Contributor

What problem does this PR solve?

Issue Number: ref #9032

Problem Summary:

What is changed and how it works?

Pick https://github.com/tidbcloud/tiflash-cse/pull/165, https://github.com/tidbcloud/tiflash-cse/pull/166 and https://github.com/tidbcloud/tiflash-cse/pull/175.

storage: Use mmap to view vector index

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 12, 2024
@@ -1385,16 +1385,16 @@ void Context::dropMinMaxIndexCache() const
{
auto lock = getLock();
if (shared->minmax_index_cache)
shared->minmax_index_cache->reset();
shared->minmax_index_cache.reset();
Copy link
Contributor

@JinheLin JinheLin Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change it to call shared_ptr::reset()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to destroy the instance. shared_ptr::reset() let reference count - 1.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we destroy the instance, getMinMaxIndexCache and getVectorIndexCache will not re-create the cache. Is it as expected?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original ->reset() is calling LRUCache::reset() to release all cached objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is implemented but not used. Since it is called drop rather than clear, I think destroying the instance is more acceptable.

Copy link
Contributor

@JaySon-Huang JaySon-Huang Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used for testing now. I think what the test expected is "clear" but not drop and not able to use vector index cache/min-max index cache again.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it is drop rather than clear. After TearDown, all statuses should be reset so that all cases start from the same statuses.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think TearDown just want to clear the data in cache instread of destroy the cache.

Otherwise, the remaining cases will not go to the cache.

Normally, a query should run to the first branch shown in the screenshot below.

If the shared pointer index_cache is reset, it will go to the else branch, which means 'no cache'.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

dbms/src/TiDB/Schema/TiDB.cpp Outdated Show resolved Hide resolved
dbms/src/Server/Server.cpp Show resolved Hide resolved
dbms/src/Storages/DeltaMerge/File/dtpb/dmfile.proto Outdated Show resolved Hide resolved
dbms/src/Storages/S3/FileCache.cpp Outdated Show resolved Hide resolved
dbms/src/Storages/S3/FileCache.cpp Outdated Show resolved Hide resolved
@CalvinNeo
Copy link
Member

I have tried to use @coderabbitai to review this PR. And it outputs the following recommendations, some of which is reasonable IMO. Could you also check CalvinNeo#9 for those suggestions? @Lloyd-Pottiger

@Lloyd-Pottiger
Copy link
Contributor Author

I have tried to use @coderabbitai to review this PR. And it outputs the following recommendations, some of which is reasonable IMO. Could you also check CalvinNeo#9 for those suggestions? @Lloyd-Pottiger

fixed typo

{
// Space not enough.
GET_METRIC(tiflash_storage_remote_cache, type_dtfile_full).Increment();
LOG_DEBUG(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this log level is DEBUG here? It throws later, why not append this log into exception itself, or change to INFO level?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception will be caught by the caller, will not print to log.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the caller hits i <= 1, then it will be thrown?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the log is necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the exception is thrown, and the log level is INFO which is normal, then we can get no information like (capacity={} used={} estimzted_size={})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 28 to 31
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need these macros?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Signed-off-by: Lloyd-Pottiger <[email protected]>
Copy link
Contributor

@JaySon-Huang JaySon-Huang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Aug 22, 2024
void cleanOutdatedLoop();

// TODO(vector-index): Use task on BackgroundProcessingPool instead of a raw thread
std::thread cleaner_thread;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this change be in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no

Copy link
Member

@CalvinNeo CalvinNeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ti-chi-bot ti-chi-bot bot added the lgtm label Aug 26, 2024
Copy link
Contributor

ti-chi-bot bot commented Aug 26, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CalvinNeo, JaySon-Huang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [CalvinNeo,JaySon-Huang]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Aug 26, 2024
Copy link
Contributor

ti-chi-bot bot commented Aug 26, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-08-22 13:28:58.46193956 +0000 UTC m=+444933.596389674: ☑️ agreed by JaySon-Huang.
  • 2024-08-26 02:57:01.719399418 +0000 UTC m=+752616.853849537: ☑️ agreed by CalvinNeo.

@ti-chi-bot ti-chi-bot bot merged commit d6abc70 into pingcap:feature/vector-index Aug 26, 2024
5 checks passed
@Lloyd-Pottiger Lloyd-Pottiger deleted the cherry-pick-2 branch August 26, 2024 03:02
@JaySon-Huang JaySon-Huang mentioned this pull request Sep 30, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants