物理インポート モードを使用する

このドキュメントでは、設定ファイルの記述やパフォーマンスのチューニングなど、 TiDB Lightningでの物理インポート モードの使用方法を紹介します。

物理インポート モードの構成と使用

次の構成ファイルを使用して、物理インポート モードを使用してデータ インポートを実行できます。

[lightning] # log level = "info" file = "tidb-lightning.log" max-size = 128 # MB max-days = 28 max-backups = 14 # Checks the cluster minimum requirements before start. check-requirements = true [mydumper] # The local data source directory or the external storage URL. data-source-dir = "/data/my_database" [tikv-importer] # Import mode. "local" means using the physical import mode. backend = "local" # The method to resolve the conflicting data. duplicate-resolution = 'remove' # The directory of local KV sorting. sorted-kv-dir = "./some-dir" [tidb] # The information of the target cluster. The address of any tidb-server from the cluster. host = "172.16.31.1" port = 4000 user = "root" # Configure the password to connect to TiDB. Either plaintext or Base64 encoded. password = "" # Required. Table schema information is fetched from TiDB via this status-port. status-port = 10080 # Required. The address of any pd-server from the cluster. pd-addr = "172.16.31.4:2379" # tidb-lightning imports the TiDB library, and generates some logs. # Set the log level of the TiDB library. log-level = "error" [post-restore] # Specifies whether to perform `ADMIN CHECKSUM TABLE <table>` for each table to verify data integrity after importing. # The following options are available: # - "required" (default): Perform admin checksum after importing. If checksum fails, TiDB Lightning will exit with failure. # - "optional": Perform admin checksum. If checksum fails, TiDB Lightning will report a WARN log but ignore any error. # - "off": Do not perform checksum after importing. # Note that since v4.0.8, the default value has changed from "true" to "required". # # Note: # 1. Checksum failure usually means import exception (data loss or data inconsistency), so it is recommended to always enable Checksum. # 2. For backward compatibility, bool values "true" and "false" are also allowed for this field. # "true" is equivalent to "required" and "false" is equivalent to "off". checksum = "required" # Specifies whether to perform `ANALYZE TABLE <table>` for each table after checksum is done. # Options available for this field are the same as `checksum`. However, the default value for this field is "optional". analyze = "optional"

完全な構成ファイルについては、 構成ファイルとコマンド ライン パラメータを参照してください。

競合の検出

競合するデータとは、PK/UK 列のデータが同じである 2 つ以上のレコードを指します。データ ソースに競合するデータが含まれている場合、テーブル内の実際の行数は、一意のインデックスを使用したクエリによって返される合計行数とは異なります。

TiDB Lightningは、競合するデータを検出するための 3 つの戦略を提供します。

  • record : 競合するレコードのみをターゲット TiDB のlightning_task_info.conflict_error_v1テーブルに記録します。ターゲット TiKV の必要なバージョンは v5.2.0 以降のバージョンであることに注意してください。それ以外の場合は、'none' にフォールバックします。
  • remove (推奨): record戦略のように、競合するすべてのレコードを記録します。ただし、競合するすべてのレコードをターゲット テーブルから削除して、ターゲット TiDB で一貫した状態を確保します。
  • none : 重複レコードを検出しません。 noneは 3 つの戦略で最高のパフォーマンスを発揮しますが、ターゲット TiDB でデータの一貫性が失われる可能性があります。

v5.3 より前では、Lightning は競合検出をサポートしていません。競合するデータがある場合、インポート プロセスはチェックサム ステップで失敗します。競合検出が有効になっている場合、戦略recordまたはremoveに関係なく、競合するデータがある場合、Lightning はチェックサム手順をスキップします (常に失敗するため)。

order_lineテーブルに次のスキーマがあるとします。

CREATE TABLE IF NOT EXISTS `order_line` ( `ol_o_id` int(11) NOT NULL, `ol_d_id` int(11) NOT NULL, `ol_w_id` int(11) NOT NULL, `ol_number` int(11) NOT NULL, `ol_i_id` int(11) NOT NULL, `ol_supply_w_id` int(11) DEFAULT NULL, `ol_delivery_d` datetime DEFAULT NULL, `ol_quantity` int(11) DEFAULT NULL, `ol_amount` decimal(6,2) DEFAULT NULL, `ol_dist_info` char(24) DEFAULT NULL, PRIMARY KEY (`ol_w_id`,`ol_d_id`,`ol_o_id`,`ol_number`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

インポート中に Lightning が競合するデータを検出した場合、次のようにlightning_task_info.conflict_error_v1テーブルをクエリできます。

mysql> select table_name,index_name,key_data,row_data from conflict_error_v1 limit 10; +---------------------+------------+----------+-----------------------------------------------------------------------------+ | table_name | index_name | key_data | row_data | +---------------------+------------+----------+-----------------------------------------------------------------------------+ | `tpcc`.`order_line` | PRIMARY | 21829216 | (2677, 10, 10, 11, 75656, 10, NULL, 5, 5831.97, "HT5DN3EVb6kWTd4L37bsbogj") | | `tpcc`.`order_line` | PRIMARY | 49931672 | (2677, 10, 10, 11, 75656, 10, NULL, 5, 5831.97, "HT5DN3EVb6kWTd4L37bsbogj") | | `tpcc`.`order_line` | PRIMARY | 21829217 | (2677, 10, 10, 12, 76007, 10, NULL, 5, 9644.36, "bHuVoRfidQ0q2rJ6ZC9Hd12E") | | `tpcc`.`order_line` | PRIMARY | 49931673 | (2677, 10, 10, 12, 76007, 10, NULL, 5, 9644.36, "bHuVoRfidQ0q2rJ6ZC9Hd12E") | | `tpcc`.`order_line` | PRIMARY | 21829218 | (2677, 10, 10, 13, 85618, 10, NULL, 5, 7427.98, "t3rsesgi9rVAKi9tf6an5Rpv") | | `tpcc`.`order_line` | PRIMARY | 49931674 | (2677, 10, 10, 13, 85618, 10, NULL, 5, 7427.98, "t3rsesgi9rVAKi9tf6an5Rpv") | | `tpcc`.`order_line` | PRIMARY | 21829219 | (2677, 10, 10, 14, 15873, 10, NULL, 5, 133.21, "z1vH0e31tQydJGhfNYNa4ScD") | | `tpcc`.`order_line` | PRIMARY | 49931675 | (2677, 10, 10, 14, 15873, 10, NULL, 5, 133.21, "z1vH0e31tQydJGhfNYNa4ScD") | | `tpcc`.`order_line` | PRIMARY | 21829220 | (2678, 10, 10, 1, 44644, 10, NULL, 5, 8463.76, "TWKJBt5iJA4eF7FIVxnugNmz") | | `tpcc`.`order_line` | PRIMARY | 49931676 | (2678, 10, 10, 1, 44644, 10, NULL, 5, 8463.76, "TWKJBt5iJA4eF7FIVxnugNmz") | +---------------------+------------+----------------------------------------------------------------------------------------+ 10 rows in set (0.14 sec)

保持する必要があるレコードを手動で識別し、これらのレコードをテーブルに挿入できます。

性能調整

物理インポート モードのインポート パフォーマンスを向上させる最も直接的で効果的な方法は、次のとおりです。

  • Lightning がデプロイされているノードのハードウェア、特に CPU とsorted-key-dirのストレージ デバイスをアップグレードします。
  • 並行インポート機能を使用して、水平スケーリングを実現します。

TiDB Lightningは、物理インポート モードでのインポート パフォーマンスに影響を与える、いくつかの同時実行関連の構成を提供します。ただし、長年の経験から、次の 4 つの構成項目はデフォルト値のままにしておくことをお勧めします。 4 つの構成項目を調整しても、パフォーマンスが大幅に向上するわけではありません。

[lightning] # The maximum concurrency of engine files. # Each table is split into one "index engine" to store indices, and multiple # "data engines" to store row data. These settings control the maximum # concurrent number for each type of engines. # The two settings controls the maximum concurrency of the two engine files. index-concurrency = 2 table-concurrency = 6 # The concurrency of data. The default value is the number of logical CPUs. region-concurrency = # The maximum concurrency of I/O. When the concurrency is too high, the disk # cache may be frequently refreshed, causing the cache miss and read speed # to slow down. For different storage mediums, this parameter may need to be # adjusted to achieve the best performance. io-concurrency = 5

インポート中、各テーブルは、インデックスを格納する 1 つの "インデックス エンジン" と、行データを格納する複数の "データ エンジン" に分割されます。

index-concurrencyは、インデックス エンジンの最大同時実行数を制御します。 index-concurrencyを調整するときは、CPU が完全に使用されるようにindex-concurrency * the number of source files of each table > region-concurrencyを確認してください。比率は通常 1.5 ~ 2 ですindex-concurrencyを高く設定しすぎたり、2 より低く設定したりしないでください (デフォルト)。 index-concurrencyが高すぎると、構築されるパイプラインが多すぎて、インデックス エンジンのインポート ステージが積み重なってしまいます。

table-concurrencyについても同様です。 CPU が完全に使用されていることを確認するためにtable-concurrency * the number of source files of each table > region-concurrencyを確認してください。推奨値は約region-concurrency * 4 / the number of source files of each tableで、4 以上です。

テーブルが大きい場合、Lightning はテーブルを 100 GiB の複数のバッチに分割します。同時実行性はtable-concurrencyによって制御されます。

index-concurrencytable-concurrencyはインポート速度にほとんど影響しません。デフォルト値のままにしておくことができます。

io-concurrencyは、ファイル読み取りの並行性を制御します。デフォルト値は 5 です。常に、5 つのハンドルのみが読み取り操作を実行しています。通常、ファイルの読み取り速度はボトルネックにはならないため、この構成はデフォルト値のままにしておくことができます。

ファイルデータが読み取られた後、Lightning はデータのエンコードやローカルでの並べ替えなどの後処理を行う必要があります。これらの操作の並行性はregion-concurrencyによって制御されます。デフォルト値は CPU コアの数です。この構成はデフォルト値のままにしておくことができます。他のコンポーネントとは別のサーバーに Lightning をデプロイすることをお勧めします。 Lightning を他のコンポーネントと一緒にデプロイする必要がある場合は、負荷に応じてregion-concurrencyの値を下げる必要があります。

TiKV のnum-threads構成もパフォーマンスに影響を与える可能性があります。新しいクラスターの場合、CPU コアの数にnum-threadsを設定することをお勧めします。

このページは役に立ちましたか?

Playground
登録なしで TiDB の機能をワンストップでインタラクティブに体験できます。
製品
TiDB Dedicated
TiDB Serverless
TiDB
価格
PoC お問い合わせ
エコシステム
TiKV
TiFlash
OSS Insight
© 2024 PingCAP. All Rights Reserved.
Privacy Policy.