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: Fix TiFlash system tables cannot query in Keyspace Mode #9370

Merged
merged 3 commits into from
Aug 27, 2024

Conversation

Lloyd-Pottiger
Copy link
Contributor

What problem does this PR solve?

Issue Number: ref #9032

Problem Summary:

A.

❯ ~/Work/tiflash-cse/cmake-build-Debug/dbms/src/Server/tiflash client --port=9100 --host=127.0.0.1
ClickHouse client version 1.1.54381.
Connecting to 127.0.0.1:9100.
Connected to TiFlash server version 1.1.54381.

TiFlash :) show tables;

SHOW TABLES

Received exception from server (version 1.1.54381):
Code: 49. DB::Exception: Received from 127.0.0.1:9100. DB::Exception: pingcap::Exception code=UnknownError msg=unknown error : abort: "Error(InvalidKeyMode { cmd: get, storage_api_version: V2, key: \"6D536368656D6156FF65FF7273696F6E4BFF6579FF0000000000FF000000F700000000FF0000007300000000FB\" })".

0 rows in set. Elapsed: 0.641 sec.

B:

mysql> select * from information_schema.tiflash_tables;
ERROR 1105 (HY000): rpc error: code = Internal desc = pingcap::Exception code=UnknownError msg=unknown error : abort: "Error(InvalidKeyMode { cmd: get, storage_api_version: V2, key: \"6D536368656D6156FF65FF7273696F6E4BFF6579FF0000000000FF000000F700000000FF0000007300000000FB\" })"

This is because we always try to sync the schema version when querying from CLI client. Under keyspace mode, a KeyspaceID is required for it to work.

What is changed and how it works?

TiFlash's system tables don't need to sync schemas before querying. It does not belong to any keyspace as well. So we just skip sync schemas for these tables.

After this PR:

TiFlash :) show databases;

SHOW DATABASES

┌─name──────┐
│ ks_1_db_1 │
│ ks_1_db_2 │
│ system    │
└───────────┘

3 rows in set. Elapsed: 0.001 sec.

TiFlash :) select * from dt_segments;

SELECT *
FROM dt_segments

┌─database──┬─table─────┬─tidb_database─┬─tidb_table──┬─table_id─┬─is_tombstone─┬─segment_id─┬─range──────────────────────────────────────┬─epoch─┬──rows─┬──────size─┬─delta_rate─┬─delta_memtable_rows─┬─delta_memtable_size─┬─delta_memtable_column_files─┬─delta_memtable_delete_ranges─┬─delta_persisted_page_id─┬─delta_persisted_rows─┬─delta_persisted_size─┬─delta_persisted_column_files─┬─delta_persisted_delete_ranges─┬─delta_cache_size─┬─delta_index_size─┬─stable_page_id─┬─stable_rows─┬─stable_size─┬─stable_dmfiles─┬─stable_dmfiles_id_0─┬─stable_dmfiles_rows─┬─stable_dmfiles_size─┬─stable_dmfiles_size_on_disk─┬─stable_dmfiles_packs─┐
│ ks_1_db_2 │ ks_1_t_96 │ ks_1_test     │ ks_1_sample │       96 │            0 │          1 │ [-9223372036854775808,9223372036854775807) │     5 │ 60000 │ 189900000 │          0 │                   0 │                   0 │                           0 │                            0 │                      42 │                    0 │                    0 │                            0 │                             0 │                0 │             2032 │             43 │       60000 │   189900000 │              1 │                 105 │               60000 │           189900000 │                    53891161 │                    8 │
└───────────┴───────────┴───────────────┴─────────────┴──────────┴──────────────┴────────────┴────────────────────────────────────────────┴───────┴───────┴───────────┴────────────┴─────────────────────┴─────────────────────┴─────────────────────────────┴──────────────────────────────┴─────────────────────────┴──────────────────────┴──────────────────────┴──────────────────────────────┴───────────────────────────────┴──────────────────┴──────────────────┴────────────────┴─────────────┴─────────────┴────────────────┴─────────────────────┴─────────────────────┴─────────────────────┴─────────────────────────────┴──────────────────────┘

1 rows in set. Elapsed: 0.003 sec.
mysql> select * from information_schema.tiflash_tables;
+-----------+-----------+---------------+-------------+----------+--------------+---------------+------------+------------+---------------------+-----------------+---------------------+-------------------+------------------+------------------+-------------------------+------------------+------------------+------------------+-------------+------------------+------------------+----------------+----------------+-------------------------+--------------+-------------------+-------------------+---------------------------+-----------------+-----------------+---------------------------+-------------------------+-------------------------+------------------------+------------------------+----------------------------+--------------------------+-------------------------+-------------------------+------------------------------+-----------------------------------------+------------------------------------------+-------------------------------------------+-----------------------------+----------------------------------------+-----------------------------------------+------------------------------------------+----------------------------+---------------------------------------+----------------------------------------+-----------------------------------------+-------------------------+------------------+
| DATABASE  | TABLE     | TIDB_DATABASE | TIDB_TABLE  | TABLE_ID | IS_TOMBSTONE | SEGMENT_COUNT | TOTAL_ROWS | TOTAL_SIZE | TOTAL_DELETE_RANGES | DELTA_RATE_ROWS | DELTA_RATE_SEGMENTS | DELTA_PLACED_RATE | DELTA_CACHE_SIZE | DELTA_CACHE_RATE | DELTA_CACHE_WASTED_RATE | DELTA_INDEX_SIZE | AVG_SEGMENT_ROWS | AVG_SEGMENT_SIZE | DELTA_COUNT | TOTAL_DELTA_ROWS | TOTAL_DELTA_SIZE | AVG_DELTA_ROWS | AVG_DELTA_SIZE | AVG_DELTA_DELETE_RANGES | STABLE_COUNT | TOTAL_STABLE_ROWS | TOTAL_STABLE_SIZE | TOTAL_STABLE_SIZE_ON_DISK | AVG_STABLE_ROWS | AVG_STABLE_SIZE | TOTAL_PACK_COUNT_IN_DELTA | MAX_PACK_COUNT_IN_DELTA | AVG_PACK_COUNT_IN_DELTA | AVG_PACK_ROWS_IN_DELTA | AVG_PACK_SIZE_IN_DELTA | TOTAL_PACK_COUNT_IN_STABLE | AVG_PACK_COUNT_IN_STABLE | AVG_PACK_ROWS_IN_STABLE | AVG_PACK_SIZE_IN_STABLE | STORAGE_STABLE_NUM_SNAPSHOTS | STORAGE_STABLE_OLDEST_SNAPSHOT_LIFETIME | STORAGE_STABLE_OLDEST_SNAPSHOT_THREAD_ID | STORAGE_STABLE_OLDEST_SNAPSHOT_TRACING_ID | STORAGE_DELTA_NUM_SNAPSHOTS | STORAGE_DELTA_OLDEST_SNAPSHOT_LIFETIME | STORAGE_DELTA_OLDEST_SNAPSHOT_THREAD_ID | STORAGE_DELTA_OLDEST_SNAPSHOT_TRACING_ID | STORAGE_META_NUM_SNAPSHOTS | STORAGE_META_OLDEST_SNAPSHOT_LIFETIME | STORAGE_META_OLDEST_SNAPSHOT_THREAD_ID | STORAGE_META_OLDEST_SNAPSHOT_TRACING_ID | BACKGROUND_TASKS_LENGTH | TIFLASH_INSTANCE |
+-----------+-----------+---------------+-------------+----------+--------------+---------------+------------+------------+---------------------+-----------------+---------------------+-------------------+------------------+------------------+-------------------------+------------------+------------------+------------------+-------------+------------------+------------------+----------------+----------------+-------------------------+--------------+-------------------+-------------------+---------------------------+-----------------+-----------------+---------------------------+-------------------------+-------------------------+------------------------+------------------------+----------------------------+--------------------------+-------------------------+-------------------------+------------------------------+-----------------------------------------+------------------------------------------+-------------------------------------------+-----------------------------+----------------------------------------+-----------------------------------------+------------------------------------------+----------------------------+---------------------------------------+----------------------------------------+-----------------------------------------+-------------------------+------------------+
| ks_1_db_2 | ks_1_t_96 | ks_1_test     | ks_1_sample |       96 |            0 |             1 |      60000 |  189900000 |                   0 |               0 |                   0 |              NULL |                0 |             NULL |                    NULL |                0 |            60000 |        189900000 |           0 |                0 |                0 |           NULL |           NULL |                    NULL |            1 |             60000 |         189900000 |                  53891161 |           60000 |       189900000 |                         0 |                       0 |                    NULL |                   NULL |                   NULL |                          8 |                        8 |                    7500 |                23737500 |                            0 |                                       0 |                                        0 |                                           |                           0 |                                      0 |                                       0 |                                          |                          0 |                                     0 |                                      0 |                                         |                       0 | 127.0.0.1:3930   |
+-----------+-----------+---------------+-------------+----------+--------------+---------------+------------+------------+---------------------+-----------------+---------------------+-------------------+------------------+------------------+-------------------------+------------------+------------------+------------------+-------------+------------------+------------------+----------------+----------------+-------------------------+--------------+-------------------+-------------------+---------------------------+-----------------+-----------------+---------------------------+-------------------------+-------------------------+------------------------+------------------------+----------------------------+--------------------------+-------------------------+-------------------------+------------------------------+-----------------------------------------+------------------------------------------+-------------------------------------------+-----------------------------+----------------------------------------+-----------------------------------------+------------------------------------------+----------------------------+---------------------------------------+----------------------------------------+-----------------------------------------+-------------------------+------------------+
1 row in set (0.00 sec)

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/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 26, 2024
@JaySon-Huang
Copy link
Contributor

Why querying information_schema.tiflash_tables in v7.5.x/v8.1.x are not affected?

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 27, 2024
@Lloyd-Pottiger
Copy link
Contributor Author

Why querying information_schema.tiflash_tables in v7.5.x/v8.1.x are not affected?

Only affects keyspace mode. In v7.5.x/v8.1.x, keyspace is always equal to NullspaceID.

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 27, 2024
Copy link
Contributor

ti-chi-bot bot commented Aug 27, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-08-27 02:27:18.821671488 +0000 UTC m=+837233.956121604: ☑️ agreed by breezewish.
  • 2024-08-27 02:58:18.466310205 +0000 UTC m=+839093.600760346: ☑️ agreed by JaySon-Huang.

Copy link
Contributor

ti-chi-bot bot commented Aug 27, 2024

[APPROVALNOTIFIER] This PR is APPROVED

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

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 [JaySon-Huang,JinheLin,breezewish]

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

Copy link
Contributor

ti-chi-bot bot commented Aug 27, 2024

@Lloyd-Pottiger: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

trigger some heavy tests which will not run always when PR updated.

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@Lloyd-Pottiger
Copy link
Contributor Author

/retest

@ti-chi-bot ti-chi-bot bot merged commit d94b18a into pingcap:master Aug 27, 2024
4 of 5 checks passed
@Lloyd-Pottiger Lloyd-Pottiger deleted the fix-system-table branch August 28, 2024 02:34
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/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants