|
| 1 | +<!-- |
| 2 | +
|
| 3 | + Licensed to the Apache Software Foundation (ASF) under one |
| 4 | + or more contributor license agreements. See the NOTICE file |
| 5 | + distributed with this work for additional information |
| 6 | + regarding copyright ownership. The ASF licenses this file |
| 7 | + to you under the Apache License, Version 2.0 (the |
| 8 | + "License"); you may not use this file except in compliance |
| 9 | + with the License. You may obtain a copy of the License at |
| 10 | + |
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + |
| 13 | + Unless required by applicable law or agreed to in writing, |
| 14 | + software distributed under the License is distributed on an |
| 15 | + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | + KIND, either express or implied. See the License for the |
| 17 | + specific language governing permissions and limitations |
| 18 | + under the License. |
| 19 | +
|
| 20 | +--> |
| 21 | + |
| 22 | +## Load Balance |
| 23 | + |
| 24 | +Region migration belongs to advanced operations and maintenance functions, which have certain operational costs. It is recommended to read the entire document before using this function. If you have any questions about the solution design, please contact the IoTDB team for technical support. |
| 25 | + |
| 26 | + |
| 27 | +### Feature introduction |
| 28 | + |
| 29 | +IoTDB is a distributed database, and the balanced distribution of data plays an important role in load balancing the disk space and write pressure of the cluster. Region is the basic unit for distributed storage of data in IoTDB cluster, and the specific concept can be seen in [region](../Background-knowledge/Cluster-Concept.md)。 |
| 30 | + |
| 31 | +Under normal operation of the cluster, IoTDB will automatically perform load balancing on data. However, in scenarios where a new DataNode node is added to the cluster or where the hard disk of the machine where the DataNode is located is damaged and data needs to be recovered, manual region migration can be used to finely adjust the cluster load and operations. |
| 32 | + |
| 33 | +Here is a schematic diagram of the region migration process : |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +### Notes |
| 39 | + |
| 40 | +1. It is recommended to only use the Region Migration feature on IoTDB 1.3.3 and higher versions. |
| 41 | +2. Region migration is only supported when the consensus protocol is IoTConsus or Ratis (in iotdb system. properties, the `schema_region_consensus_protocol_class` and`data_region_consensus_protocol_class`). |
| 42 | +3. Region migration will occupy system resources such as hard drives and network bandwidth, and it is recommended to perform it during low business loads. |
| 43 | +4. The region migration process will occupy WAL files, blocking the deletion of WAL files in this consensus group. If the total number of WAL files reaches `wal_file_size_threshold_in_byte`, writing will be blocked. |
| 44 | + |
| 45 | +### Instructions for use |
| 46 | + |
| 47 | +- **Grammar definition** : |
| 48 | + |
| 49 | + Submit an asynchronous task to migrate a region from one DataNode to another. |
| 50 | + |
| 51 | + |
| 52 | + ```SQL |
| 53 | + migrateRegion |
| 54 | + : MIGRATE REGION regionId=INTEGER_LITERAL FROM fromId=INTEGER_LITERAL TO toId=INTEGER_LITERAL |
| 55 | + ; |
| 56 | + ``` |
| 57 | + |
| 58 | +- **Example** : |
| 59 | + |
| 60 | + Migrating region 1 from DataNode 2 to DataNode 3: |
| 61 | + |
| 62 | + ```SQL |
| 63 | + IoTDB> migrate region 1 from 2 to 3 |
| 64 | + Msg: The statement is executed successfully. |
| 65 | + ``` |
| 66 | + |
| 67 | + "The statement is executed successfully" only represents the successful submission of the region migration task, not the completion of execution. The execution status of the task can be viewed through the CLI command `show regions `. |
| 68 | +- **Related configuration** : |
| 69 | + - Migration speed control : modify `iotdb-system.properties `parameters `region_migration_speed_limit_bytes_per_second `control region migration speed. |
| 70 | +- **Time cost estimation** : |
| 71 | + - If there are no concurrent writes during the migration process, the time consumption can be simply estimated by dividing the region data volume by the data transfer speed. For example, for a 1TB region, the hard disk internet bandwidth and speed limit parameters jointly determine that the data transfer speed is 100MB/s, so it takes about 3 hours to complete the migration. |
| 72 | + - If there are concurrent writes in the migration process, the time consumption will increase, and the specific time consumption depends on various factors such as write pressure and system resources. It can be simply estimated as `no concurrent write time × 1.5 `. |
| 73 | +- **Migration progress observation** : During the migration process, the state changes can be observed through the CLI command `show regions `. Taking the 2 replicas as an example, the state of the consensus group where the region is located will go through the following process: |
| 74 | + - Before migration starts: `Running `, `Running `. |
| 75 | + - Expansion phase: `Running `, `Running `, `Adding `. Due to the large number of file transfers involved, it may take a long time. If using IoTConsensus, the specific file transfer progress can be searched in the DataNode log `[SNAPSHOT TRANSMISSION] `. |
| 76 | + - Stages: `Removing `, `Running `, `Running `. |
| 77 | + - Migration complete: `Running `, `Running `. |
| 78 | + |
| 79 | + Taking the expansion phase as an example, the result of `show regions` may be: |
| 80 | + |
| 81 | + ```Plain |
| 82 | + IoTDB> show regions |
| 83 | + +--------+------------+-------+--------+-------------+-----------+----------+----------+-------+---------------+--------+-----------------------+ |
| 84 | + |RegionId| Type| Status|Database|SeriesSlotNum|TimeSlotNum|DataNodeId|RpcAddress|RpcPort|InternalAddress| Role| CreateTime| |
| 85 | + +--------+------------+-------+--------+-------------+-----------+----------+----------+-------+---------------+--------+-----------------------+ |
| 86 | + | 0|SchemaRegion|Running| root.ln| 1| 0| 1| 0.0.0.0| 6668| 127.0.0.1| Leader|2024-04-15T18:55:17.691| |
| 87 | + | 0|SchemaRegion|Running| root.ln| 1| 0| 2| 0.0.0.0| 6668| 127.0.0.1| Leader|2024-04-15T18:55:17.691| |
| 88 | + | 0|SchemaRegion|Running| root.ln| 1| 0| 3| 0.0.0.0| 6668| 127.0.0.1| Leader|2024-04-15T18:55:17.691| |
| 89 | + | 1| DataRegion|Running| root.ln| 1| 1| 1| 0.0.0.0| 6667| 127.0.0.1| Leader|2024-04-15T18:55:19.457| |
| 90 | + | 1| DataRegion|Running| root.ln| 1| 1| 2| 0.0.0.0| 6668| 127.0.0.1|Follower|2024-04-15T18:55:19.457| |
| 91 | + | 1| DataRegion| Adding| root.ln| 1| 1| 3| 0.0.0.0| 6668| 127.0.0.1|Follower|2024-04-15T18:55:19.457| |
| 92 | + +--------+------------+-------+--------+-------------+-----------+----------+----------+-------+---------------+--------+-----------------------+ |
| 93 | + Total line number = 3 |
| 94 | + It costs 0.003s |
| 95 | + ``` |
0 commit comments