pingcap / tiflash

The analytical engine for TiDB and TiDB Cloud. Try free: https://tidbcloud.com/free-trial
https://docs.pingcap.com/tidb/stable/tiflash-overview
Apache License 2.0
944 stars 410 forks source link

storage: Fix TiFlash system tables cannot query in Keyspace Mode #9370

Closed Lloyd-Pottiger closed 1 month ago

Lloyd-Pottiger commented 1 month ago

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

Side effects

Documentation

Release note

None
JaySon-Huang commented 1 month ago

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

Lloyd-Pottiger commented 1 month ago

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[bot] commented 1 month ago

[LGTM Timeline notifier]

Timeline:

ti-chi-bot[bot] commented 1 month ago

[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](https://github.com/pingcap/tiflash/blob/master/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
ti-chi-bot[bot] commented 1 month ago

@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](https://prow.tidb.net/command-help). If you have questions or suggestions related to my behavior, please file an issue against the [ti-community-infra/tichi](https://github.com/ti-community-infra/tichi/issues/new?title=Prow%20issue:) repository.
Lloyd-Pottiger commented 1 month ago

/retest