| 242 | } |
| 243 | |
| 244 | void DistributedAsyncInsertBatch::sendBatch(const SettingsChanges & settings_changes) |
| 245 | { |
| 246 | IConnectionPool::Entry connection; |
| 247 | std::unique_ptr<RemoteInserter> remote; |
| 248 | bool compression_expected = false; |
| 249 | |
| 250 | /// Since the batch is sent as a whole (in case of failure, the whole batch |
| 251 | /// will be repeated), we need to mark the whole batch as failed in case of |
| 252 | /// error). |
| 253 | std::vector<OpenTelemetry::TracingContextHolderPtr> tracing_contexts; |
| 254 | UInt64 batch_start_time = clock_gettime_ns(); |
| 255 | |
| 256 | try |
| 257 | { |
| 258 | for (const auto & file : files) |
| 259 | { |
| 260 | ReadBufferFromFile in(file); |
| 261 | const auto & distributed_header = DistributedAsyncInsertHeader::read(in, parent.log); |
| 262 | |
| 263 | tracing_contexts.emplace_back(distributed_header.createTracingContextHolder( |
| 264 | __PRETTY_FUNCTION__, |
| 265 | parent.storage.getContext()->getOpenTelemetrySpanLog())); |
| 266 | tracing_contexts.back()->root_span.addAttribute("clickhouse.distributed_batch_start_time", batch_start_time); |
| 267 | |
| 268 | if (!remote) |
| 269 | { |
| 270 | Settings insert_settings = *distributed_header.insert_settings; |
| 271 | insert_settings.applyChanges(settings_changes); |
| 272 | |
| 273 | auto timeouts = ConnectionTimeouts::getTCPTimeoutsWithFailover(insert_settings); |
| 274 | auto results = parent.pool->getManyCheckedForInsert(timeouts, insert_settings, PoolMode::GET_ONE, parent.storage.remote_storage.getQualifiedName()); |
| 275 | auto result = parent.pool->getValidTryResult(results, insert_settings[Setting::distributed_insert_skip_read_only_replicas]); |
| 276 | connection = std::move(result.entry); |
| 277 | compression_expected = connection->getCompression() == Protocol::Compression::Enable; |
| 278 | |
| 279 | LOG_DEBUG(parent.log, "Sending a batch of {} files to {} ({} rows, {} bytes).", |
| 280 | files.size(), |
| 281 | connection->getDescription(), |
| 282 | formatReadableQuantity(total_rows), |
| 283 | formatReadableSizeWithBinarySuffix(total_bytes)); |
| 284 | |
| 285 | remote = std::make_unique<RemoteInserter>(*connection, timeouts, |
| 286 | distributed_header.insert_query, |
| 287 | insert_settings, |
| 288 | distributed_header.client_info); |
| 289 | remote->initialize(); |
| 290 | } |
| 291 | writeRemoteConvert(distributed_header, *remote, compression_expected, in, parent.log); |
| 292 | } |
| 293 | |
| 294 | if (remote) |
| 295 | remote->onFinish(); |
| 296 | } |
| 297 | catch (...) |
| 298 | { |
| 299 | try |
| 300 | { |
| 301 | for (auto & tracing_context : tracing_contexts) |
nothing calls this directly
no test coverage detected