| 345 | |
| 346 | Status Start() override { return Status::OK(); } |
| 347 | Status WritePayload(const ipc::IpcPayload& ipc_payload) override { |
| 348 | FlightPayload payload; |
| 349 | payload.ipc_message = ipc_payload; |
| 350 | |
| 351 | if (first_payload_) { |
| 352 | // First Flight message needs to encore the Flight descriptor |
| 353 | if (ipc_payload.type != ipc::MessageType::SCHEMA) { |
| 354 | return Status::Invalid("First IPC message should be schema"); |
| 355 | } |
| 356 | // Write the descriptor to begin with |
| 357 | RETURN_NOT_OK(internal::ToPayload(descriptor_, &payload.descriptor)); |
| 358 | first_payload_ = false; |
| 359 | } else if (ipc_payload.type == ipc::MessageType::RECORD_BATCH && *app_metadata_) { |
| 360 | payload.app_metadata = std::move(*app_metadata_); |
| 361 | } |
| 362 | |
| 363 | if (write_size_limit_bytes_ > 0) { |
| 364 | // Check if the total size is greater than the user-configured |
| 365 | // soft-limit. |
| 366 | int64_t size = ipc_payload.body_length + ipc_payload.metadata->size(); |
| 367 | if (payload.descriptor) { |
| 368 | size += payload.descriptor->size(); |
| 369 | } |
| 370 | if (payload.app_metadata) { |
| 371 | size += payload.app_metadata->size(); |
| 372 | } |
| 373 | if (size > write_size_limit_bytes_) { |
| 374 | return arrow::Status( |
| 375 | arrow::StatusCode::Invalid, "IPC payload size exceeded soft limit", |
| 376 | std::make_shared<FlightWriteSizeStatusDetail>(write_size_limit_bytes_, size)); |
| 377 | } |
| 378 | } |
| 379 | ARROW_ASSIGN_OR_RAISE(auto success, stream_->WriteData(payload)); |
| 380 | if (!success) { |
| 381 | return Status::FromDetailAndArgs( |
| 382 | StatusCode::IOError, std::make_shared<ServerErrorTagStatusDetail>(), |
| 383 | "Could not write record batch to stream (server disconnect?)"); |
| 384 | } |
| 385 | return Status::OK(); |
| 386 | } |
| 387 | Status Close() override { |
| 388 | // Closing is handled one layer up in ClientStreamWriter::Close |
| 389 | return Status::OK(); |