Skip to content

Extend region migration speed limit to transfers and deletion#18118

Open
CRZbulabula wants to merge 4 commits into
masterfrom
feat-region-delete-speed-limit
Open

Extend region migration speed limit to transfers and deletion#18118
CRZbulabula wants to merge 4 commits into
masterfrom
feat-region-delete-speed-limit

Conversation

@CRZbulabula

@CRZbulabula CRZbulabula commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Extend region_migration_speed_limit_bytes_per_second to throttle region migration transfer across consensus protocols that have real transfer paths.
  • Keep IoTConsensus AddPeer snapshot transfer covered by the shared limiter, and add coverage for IoTConsensusV2 consensus pipe transfer and Ratis install snapshot transfer.
  • Share the same limiter with region file deletion and wire DataRegion, SchemaRegion, WAL, snapshot, and consensus peer cleanup paths through rate-limited deletion helpers.
  • Update the config template description and add unit coverage for rate-limited deletion, IoTConsensusV2 transfer size calculation, and Ratis snapshot chunk size calculation.

Protocol coverage

  • IoTConsensus: AddPeer snapshot transfer is rate-limited.
  • IoTConsensusV2: tablet, tablet batch, delete event, and TsFile piece transfer requests are rate-limited.
  • Ratis: install snapshot file chunks are rate-limited before sending.
  • SimpleConsensus: no remote region migration transfer path; local region deletion cleanup remains rate-limited.

Tests

  • mvn spotless:apply -pl iotdb-core/node-commons,iotdb-core/consensus,iotdb-core/datanode
  • mvn test -pl iotdb-core/node-commons -am -Dtest=FileUtilsTest -DfailIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false
  • mvn test -pl iotdb-core/consensus -am -Dtest=RateLimitedGrpcLogAppenderTest -DfailIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false
  • mvn test -pl iotdb-core/datanode -am -Dtest=IoTConsensusV2RateLimiterTest -DfailIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false
  • mvn compile -pl iotdb-core/consensus,iotdb-core/datanode -am -DskipTests
  • mvn test-compile -DskipTests -P with-zh-locale -pl iotdb-core/consensus,iotdb-core/datanode -am

Note: full reactor mvn test-compile -DskipTests reaches 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.

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.04580% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.90%. Comparing base (8940ba0) to head (e89a1a9).
⚠️ Report is 19 commits behind head on master.

Files with missing lines Patch % Lines
...rotocol/iotconsensusv2/IoTConsensusV2SyncSink.java 0.00% 10 Missing ⚠️
...b/schemaengine/schemaregion/SchemaRegionUtils.java 0.00% 6 Missing ⚠️
...java/org/apache/iotdb/commons/utils/FileUtils.java 80.00% 4 Missing ⚠️
...otdb/commons/utils/RegionMigrationRateLimiter.java 75.00% 4 Missing ⚠️
...rg/apache/iotdb/consensus/pipe/IoTConsensusV2.java 0.00% 3 Missing ⚠️
...ns/utils/RegionMigrationFileRemoveRateLimiter.java 82.35% 3 Missing ⚠️
...gine/schemaregion/impl/SchemaRegionMemoryImpl.java 0.00% 2 Missing ⚠️
...gine/schemaregion/impl/SchemaRegionPBTreeImpl.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #18118      +/-   ##
============================================
+ Coverage     41.84%   41.90%   +0.06%     
  Complexity      318      318              
============================================
  Files          5296     5302       +6     
  Lines        373593   374331     +738     
  Branches      48234    48319      +85     
============================================
+ Hits         156313   156865     +552     
- Misses       217280   217466     +186     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@CRZbulabula CRZbulabula changed the title Limit region deletion with migration speed limit Extend region migration speed limit to transfers and deletion Jul 6, 2026
@CRZbulabula CRZbulabula requested a review from Copilot July 8, 2026 04:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 RegionMigrationRateLimiter and wires it into IoTConsensus snapshot transfer, IoTConsensusV2 transfer requests/file-piece transfer, and Ratis install-snapshot chunk sending.
  • Adds rate-limited deletion helpers in FileUtils and 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.

Comment on lines +190 to 194
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)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e84fe31. deleteDirectoryAndEmptyParent(...) now treats parentFolder == null as no parent to clean up, and I added testDeleteDirectoryAndEmptyParentWithRateLimiterAndNoParent to cover the relative-path/no-parent case.

Comment on lines +128 to 139
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());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, using the real file size for delete throttling is too conservative because removal is mostly metadata work. Fixed in e84fe31 by moving cleanup to an independent region_migration_file_remove_speed_limit_bytes_per_second limiter and charging fixed estimated remove costs instead: 64 KiB per regular file and 4 KiB per directory. I also removed the IoTConsensusV2 transfer limiter so regular consensus pipe replication is not throttled by the migration transfer limit.

@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants