Extend region migration speed limit to transfers and deletion#18118
Extend region migration speed limit to transfers and deletion#18118CRZbulabula wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #18118 +/- ##
============================================
- Coverage 41.84% 41.73% -0.11%
Complexity 318 318
============================================
Files 5296 5301 +5
Lines 373593 373684 +91
Branches 48234 48234
============================================
- Hits 156313 155960 -353
- Misses 217280 217724 +444 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
There was a problem hiding this comment.
Pull request overview
This PR broadens the existing region_migration_speed_limit_bytes_per_second throttling so it applies not only to region-migration transfer traffic (across IoTConsensus/IoTConsensusV2/Ratis paths), but also to region-related file deletions during cleanup, using a shared singleton rate limiter in node-commons.
Changes:
- Introduces a shared
RegionMigrationRateLimiterand wires it into IoTConsensus snapshot transfer, IoTConsensusV2 transfer requests/file-piece transfer, and Ratis install-snapshot chunk sending. - Adds rate-limited deletion helpers in
FileUtilsand updates DataRegion/SchemaRegion/WAL/consensus peer cleanup paths to use them. - Updates the config template description and adds unit tests for rate-limited deletion and transfer-size calculations.
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/utils/FileUtilsTest.java | Adds unit tests validating the new rate-limited deletion helpers accumulate expected byte/file counts. |
| iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/RegionMigrationRateLimiter.java | Adds the shared singleton rate limiter implementation backing both transfer and deletion throttling. |
| iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/FileUtils.java | Adds rate-limited deletion entry points and threads a LongConsumer through recursive deletion. |
| iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template | Updates the config description to reflect throttling applies to transfers and deletions. |
| iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/sink/protocol/iotconsensusv2/IoTConsensusV2RateLimiterTest.java | Adds unit tests for IoTConsensusV2 transfer body/batch size calculation. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/StorageEngine.java | Uses rate-limited deletion for region snapshot directory cleanup. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/allocation/FirstCreateStrategy.java | Uses rate-limited deletion when removing WAL node directories. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/allocation/ElasticStrategy.java | Uses rate-limited deletion when removing WAL node directories. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java | Uses rate-limited deletion for region system/data/object folder cleanup. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/SchemaRegionUtils.java | Adds overload to accept a delete-rate-limiter callback and accounts file sizes before deletion. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionPBTreeImpl.java | Wires schema region folder deletion through the shared limiter. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionMemoryImpl.java | Wires schema region folder deletion through the shared limiter. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/iotconsensusv2/IoTConsensusV2SyncSink.java | Rate-limits IoTConsensusV2 batch/transfer requests and file-piece reads before sending. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/iotconsensusv2/IoTConsensusV2RateLimiter.java | Adds helper to compute transfer payload sizes and acquire shared limiter accordingly. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/iotconsensusv2/handler/IoTConsensusV2TsFileInsertionEventHandler.java | Rate-limits TsFile piece transfer by acquired bytes before issuing async transfer. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/iotconsensusv2/handler/IoTConsensusV2TabletInsertionEventHandler.java | Rate-limits tablet insertion transfer requests before sending. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/iotconsensusv2/handler/IoTConsensusV2TabletBatchEventHandler.java | Rate-limits batch transfer requests before sending. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/iotconsensusv2/handler/IoTConsensusV2DeleteEventHandler.java | Rate-limits delete-event transfer requests before sending. |
| iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java | Initializes the shared RegionMigrationRateLimiter from region_migration_speed_limit_bytes_per_second. |
| iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcLogAppenderTest.java | Adds unit tests for Ratis snapshot chunk size calculation and RPC type resolution. |
| iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/simple/SimpleConsensus.java | Uses rate-limited deletion for local peer directory cleanup. |
| iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java | Forces Ratis to use the custom rate-limited gRPC RPC type. |
| iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcRpcType.java | Introduces a custom Ratis RpcType that returns a rate-limited gRPC factory. |
| iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcLogAppender.java | Hooks limiter acquisition into install-snapshot chunk iteration. |
| iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RateLimitedGrpcFactory.java | Provides a gRPC factory that installs the rate-limited log appender. |
| iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/pipe/IoTConsensusV2.java | Uses rate-limited deletion for IoTConsensusV2 local peer directory cleanup. |
| iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/snapshot/IoTConsensusRateLimiter.java | Switches IoTConsensus snapshot throttling to the shared RegionMigrationRateLimiter. |
| iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java | Uses rate-limited deletion for IoTConsensus local peer directory cleanup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private static void deleteDirectoryAndEmptyParent(File folder, LongConsumer deleteRateLimiter) { | ||
| deleteFileOrDirectory(folder, false, deleteRateLimiter); | ||
| final File parentFolder = folder.getParentFile(); | ||
| File[] files = parentFolder.listFiles(); | ||
| if (parentFolder.isDirectory() && (files == null || files.length == 0)) { |
| private static void deleteFileOrDirectory( | ||
| File file, boolean quietForNoSuchFile, LongConsumer deleteRateLimiter) { | ||
| if (file.isDirectory()) { | ||
| File[] files = file.listFiles(); | ||
| if (files != null) { | ||
| for (File subfile : files) { | ||
| deleteFileOrDirectory(subfile, quietForNoSuchFile); | ||
| deleteFileOrDirectory(subfile, quietForNoSuchFile, deleteRateLimiter); | ||
| } | ||
| } | ||
| } else if (deleteRateLimiter != null && file.isFile()) { | ||
| deleteRateLimiter.accept(file.length()); | ||
| } |
There was a problem hiding this comment.
Deleting a file only involves some file system metadata modification and inode reclaim, which will not introduce such io.
The rate-limiting step may slow down the migration significantly.



Summary
region_migration_speed_limit_bytes_per_secondto throttle region migration transfer across consensus protocols that have real transfer paths.Protocol coverage
Tests
mvn spotless:apply -pl iotdb-core/node-commons,iotdb-core/consensus,iotdb-core/datanodemvn test -pl iotdb-core/node-commons -am -Dtest=FileUtilsTest -DfailIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=falsemvn test -pl iotdb-core/consensus -am -Dtest=RateLimitedGrpcLogAppenderTest -DfailIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=falsemvn test -pl iotdb-core/datanode -am -Dtest=IoTConsensusV2RateLimiterTest -DfailIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=falsemvn compile -pl iotdb-core/consensus,iotdb-core/datanode -am -DskipTestsmvn test-compile -DskipTests -P with-zh-locale -pl iotdb-core/consensus,iotdb-core/datanode -amNote: full reactor
mvn test-compile -DskipTestsreaches the distribution module and fails to resolve existing 2.0.11-SNAPSHOT zip artifacts for iotdb-server, iotdb-cli, and iotdb-confignode. The changed modules compile successfully.