| 294 | |
| 295 | |
| 296 | ThreadPool::Job |
| 297 | DistributedBlockOutputStream::runWritingJob(DistributedBlockOutputStream::JobReplica & job, const Block & current_block, size_t num_shards) |
| 298 | { |
| 299 | auto thread_group = CurrentThread::getGroup(); |
| 300 | return [this, thread_group, &job, ¤t_block, num_shards]() |
| 301 | { |
| 302 | if (thread_group) |
| 303 | CurrentThread::attachToIfDetached(thread_group); |
| 304 | setThreadName("DistrOutStrProc"); |
| 305 | |
| 306 | ++job.blocks_started; |
| 307 | |
| 308 | SCOPE_EXIT({ |
| 309 | ++finished_jobs_count; |
| 310 | |
| 311 | UInt64 elapsed_time_for_block_ms = watch_current_block.elapsedMilliseconds(); |
| 312 | job.elapsed_time_ms += elapsed_time_for_block_ms; |
| 313 | job.max_elapsed_time_for_block_ms = std::max(job.max_elapsed_time_for_block_ms, elapsed_time_for_block_ms); |
| 314 | }); |
| 315 | |
| 316 | const auto & shard_info = cluster->getShardsInfo()[job.shard_index]; |
| 317 | auto & shard_job = per_shard_jobs[job.shard_index]; |
| 318 | const auto & addresses = cluster->getShardsAddresses(); |
| 319 | |
| 320 | /// Generate current shard block |
| 321 | if (num_shards > 1) |
| 322 | { |
| 323 | auto & shard_permutation = shard_job.shard_current_block_permutation; |
| 324 | size_t num_shard_rows = shard_permutation.size(); |
| 325 | |
| 326 | for (size_t j = 0; j < current_block.columns(); ++j) |
| 327 | { |
| 328 | const auto & src_column = current_block.getByPosition(j).column; |
| 329 | auto & dst_column = job.current_shard_block.getByPosition(j).column; |
| 330 | |
| 331 | /// Zero permutation size has special meaning in IColumn::permute |
| 332 | if (num_shard_rows) |
| 333 | dst_column = src_column->permute(shard_permutation, num_shard_rows); |
| 334 | else |
| 335 | dst_column = src_column->cloneEmpty(); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | const Block & shard_block = (num_shards > 1) ? job.current_shard_block : current_block; |
| 340 | const Settings & settings = context->getSettingsRef(); |
| 341 | |
| 342 | /// Do not initiate INSERT for empty block. |
| 343 | if (shard_block.rows() == 0) |
| 344 | return; |
| 345 | |
| 346 | if (!job.is_local_job || !settings.prefer_localhost_replica) |
| 347 | { |
| 348 | if (!job.stream) |
| 349 | { |
| 350 | auto timeouts = ConnectionTimeouts::getTCPTimeoutsWithFailover(settings); |
| 351 | if (shard_info.hasInternalReplication()) |
| 352 | { |
| 353 | /// Skip replica_index in case of internal replication |
nothing calls this directly
no test coverage detected