| 426 | } |
| 427 | |
| 428 | Status KrpcDataStreamRecvr::SenderQueue::AddBatchWork(int64_t batch_size, |
| 429 | const RowBatchHeaderPB& header, const kudu::Slice& tuple_offsets, |
| 430 | const kudu::Slice& tuple_data, unique_lock<SpinLock>* lock, |
| 431 | RpcContext* rpc_context) { |
| 432 | DCHECK(lock != nullptr); |
| 433 | DCHECK(lock->owns_lock()); |
| 434 | DCHECK(!is_cancelled_); |
| 435 | |
| 436 | // Reserve queue space before dropping the lock below. |
| 437 | num_buffered_bytes_ += batch_size; |
| 438 | // Bump 'num_pending_enqueue_' to avoid race with Close() when lock is dropped below. |
| 439 | DCHECK_GE(num_pending_enqueue_, 0); |
| 440 | ++num_pending_enqueue_; |
| 441 | |
| 442 | // Deserialization may take some time due to compression and memory allocation. |
| 443 | // Drop the lock so we can deserialize multiple batches in parallel. |
| 444 | lock->unlock(); |
| 445 | TRACE_TO(rpc_context->trace(), "Deserializing batch"); |
| 446 | unique_ptr<RowBatch> batch; |
| 447 | Status status; |
| 448 | { |
| 449 | SCOPED_TIMER(recvr_->deserialize_row_batch_timer_); |
| 450 | status = DebugAction(recvr_->runtime_state_.query_options(), "RECVR_ADD_BATCH"); |
| 451 | if (LIKELY(status.ok())) { |
| 452 | // At this point, a row batch will be inserted into batch_queue_. |
| 453 | // Close() will handle deleting any unconsumed batches from batch_queue_. |
| 454 | // Close() cannot proceed until there are no pending insertion to batch_queue_. |
| 455 | status = RowBatch::FromProtobuf(recvr_->row_desc(), header, tuple_offsets, |
| 456 | tuple_data, recvr_->parent_tracker(), recvr_->buffer_pool_client(), &batch); |
| 457 | } |
| 458 | } |
| 459 | lock->lock(); |
| 460 | |
| 461 | DCHECK_GT(num_pending_enqueue_, 0); |
| 462 | --num_pending_enqueue_; |
| 463 | if (UNLIKELY(!status.ok())) { |
| 464 | num_buffered_bytes_ -= batch_size; |
| 465 | VLOG_QUERY << "Failed to deserialize batch for " |
| 466 | << PrintId(recvr_->fragment_instance_id()); |
| 467 | TRACE_TO(rpc_context->trace(), "Failed to deserialize batch: $0", status.GetDetail()); |
| 468 | MarkErrorStatus(status, *lock); |
| 469 | return status; |
| 470 | } |
| 471 | VLOG_ROW << "added #rows=" << batch->num_rows() << " batch_size=" << batch_size; |
| 472 | TRACE_TO(rpc_context->trace(), "Enqueuing deserialized batch"); |
| 473 | COUNTER_ADD(recvr_->total_enqueued_batches_counter_, 1); |
| 474 | batch_queue_.emplace_back(batch_size, move(batch)); |
| 475 | data_arrival_cv_.notify_one(); |
| 476 | return Status::OK(); |
| 477 | } |
| 478 | |
| 479 | void KrpcDataStreamRecvr::SenderQueue::AddBatch(const TransmitDataRequestPB* request, |
| 480 | TransmitDataResponsePB* response, RpcContext* rpc_context) { |
nothing calls this directly
no test coverage detected