luoluoyuyu opened a new pull request, #18663:
URL: https://github.com/apache/iotdb/pull/18663

   ## Summary
   
   Add a hidden, hot-reloadable DataNode configuration 
`load_tsfile_prefer_local_node` (default `true`). When enabled, LOAD passes the 
current DataNodeId to ConfigNode as `preferredDataNodeId` while creating a 
database or requesting get-or-create data partitions. ConfigNode then prefers 
placing newly created DataRegion replicas on the requesting node without 
modifying the existing region allocation algorithms themselves.
   
   ## Design / How It Works
   
   ### 1. DataNode configuration
   
   - `IoTDBConfig.loadTsFilePreferLocalNode` is a volatile boolean, default 
`true`.
   - `IoTDBDescriptor` loads it both at startup and during hot reload.
   - It is intentionally not added to `iotdb-system.properties.template`, so it 
stays hidden from `SHOW CONFIGURATION`.
   
   ### 2. Database creation path
   
   When LOAD auto-creates a database:
   
   - `TreeSchemaAutoCreatorAndVerifier` sets `preferredDataNodeId` on 
`DatabaseSchemaStatement`.
   - `DatabaseSchemaTask.constructDatabaseSchema` copies it to 
`TDatabaseSchema.preferredDataNodeId`.
   - ConfigNode persists the field and `RegionBalancer` can later read it.
   
   ### 3. Data-partition creation path
   
   This covers the case where the database already exists and LOAD creates 
devices/tables or requests an unassigned series partition, which triggers 
DataRegion extension:
   
   - `LoadTsFileScheduler.DataPartitionBatchFetcher` reads 
`load_tsfile_prefer_local_node`.
   - It calls the new `IPartitionFetcher.getOrCreateDataPartition(..., 
preferredDataNodeId)` overload.
   - `ClusterPartitionFetcher` puts the value into 
`TDataPartitionReq.preferredDataNodeId`.
   - ConfigNode converts it into `GetOrCreateDataPartitionPlan`.
   - `PartitionManager` passes the hint down to DataRegion extension.
   - `RegionBalancer` prefers the request-level hint first, then falls back to 
the database-schema hint.
   
   ### 4. RegionBalancer preference handling
   
   The original allocator is still called first:
   
   ```java
   regionGroupAllocator.generateOptimalRegionReplicasDistribution(...)
   ```
   
   Only after that, `preferDataNodeIfPossible` adjusts the result:
   
   - If the preferred node is unavailable, do nothing.
   - If it is already in the replica set, move it to the first position.
   - If it is absent, replace the last replica with the preferred node.
   
   Replication factor, candidate validity, and region identity are preserved.
   
   ### 5. New time partitions
   
   New time partitions do not create a new DataRegion. A new time slot is 
mapped into an existing DataRegion for the same series-partition slot, so this 
path needs no preference change.
   
   ## Validation
   
   ```bash
   mvn -pl iotdb-core/datanode,iotdb-core/confignode -am -DskipTests 
-Drat.skip=true compile
   ```
   
   Result: `BUILD SUCCESS`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to