| 330 | } |
| 331 | |
| 332 | void TAcceptQueueServer::serve() { |
| 333 | // Start the server listening |
| 334 | serverTransport_->listen(); |
| 335 | |
| 336 | // Run the preServe event |
| 337 | if (eventHandler_ != nullptr) { |
| 338 | eventHandler_->preServe(); |
| 339 | } |
| 340 | |
| 341 | if (FLAGS_accepted_cnxn_setup_thread_pool_size > 1) { |
| 342 | LOG(INFO) << "connection_setup_thread_pool_size is set to " |
| 343 | << FLAGS_accepted_cnxn_setup_thread_pool_size; |
| 344 | } |
| 345 | |
| 346 | // New - this is the thread pool used to process the internal accept queue. |
| 347 | ThreadPool<shared_ptr<TAcceptQueueEntry>> connection_setup_pool("setup-server", |
| 348 | "setup-worker", FLAGS_accepted_cnxn_setup_thread_pool_size, |
| 349 | FLAGS_accepted_cnxn_queue_depth, |
| 350 | [this](int tid, const shared_ptr<TAcceptQueueEntry>& item) { |
| 351 | this->SetupConnection(item.get()); |
| 352 | }); |
| 353 | // Initialize the thread pool |
| 354 | Status status = connection_setup_pool.Init(); |
| 355 | if (!status.ok()) { |
| 356 | status.AddDetail("TAcceptQueueServer: thread pool could not start."); |
| 357 | string errStr = status.GetDetail(); |
| 358 | GlobalOutput(errStr.c_str()); |
| 359 | stop_ = true; |
| 360 | } |
| 361 | |
| 362 | while (!stop_) { |
| 363 | try { |
| 364 | // Fetch client from server |
| 365 | shared_ptr<TTransport> client = serverTransport_->accept(); |
| 366 | |
| 367 | TSocket* socket = reinterpret_cast<TSocket*>(client.get()); |
| 368 | VLOG(1) << Substitute("New connection to server $0 from client $1", |
| 369 | name_, socket->getSocketInfo()); |
| 370 | |
| 371 | shared_ptr<TAcceptQueueEntry> entry{new TAcceptQueueEntry}; |
| 372 | entry->client_ = client; |
| 373 | if (queue_timeout_ms_ > 0) { |
| 374 | entry->expiration_time_ = MonotonicMillis() + queue_timeout_ms_; |
| 375 | } |
| 376 | |
| 377 | // New - the work done to set up the connection has been moved to SetupConnection. |
| 378 | // Note that we move() entry so it's owned by SetupConnection thread. |
| 379 | if (!connection_setup_pool.Offer(std::move(entry))) { |
| 380 | string errStr = string("TAcceptQueueServer: thread pool unexpectedly shut down."); |
| 381 | GlobalOutput(errStr.c_str()); |
| 382 | stop_ = true; |
| 383 | break; |
| 384 | } |
| 385 | if (metrics_enabled_) queue_size_metric_->Increment(1); |
| 386 | } catch (const TTransportException& ttx) { |
| 387 | if (!stop_ || ttx.getType() != TTransportException::INTERRUPTED) { |
| 388 | string errStr = |
| 389 | string("TAcceptQueueServer: TServerTransport died on accept: ") + ttx.what(); |
no test coverage detected