|
|
|
@ -72,8 +72,7 @@ auto ChaoticGoodServerTransport::TransportWriteLoop( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto ChaoticGoodServerTransport::PushFragmentIntoCall( |
|
|
|
|
CallInitiator call_initiator, ClientFragmentFrame frame, |
|
|
|
|
uint32_t stream_id) { |
|
|
|
|
CallInitiator call_initiator, ClientFragmentFrame frame) { |
|
|
|
|
DCHECK(frame.headers == nullptr); |
|
|
|
|
GRPC_TRACE_LOG(chaotic_good, INFO) |
|
|
|
|
<< "CHAOTIC_GOOD: PushFragmentIntoCall: frame=" << frame.ToString(); |
|
|
|
@ -84,17 +83,15 @@ auto ChaoticGoodServerTransport::PushFragmentIntoCall( |
|
|
|
|
std::move(frame.message->message)); |
|
|
|
|
}, |
|
|
|
|
[]() -> StatusFlag { return Success{}; }), |
|
|
|
|
[this, call_initiator, end_of_stream = frame.end_of_stream, |
|
|
|
|
stream_id](StatusFlag status) mutable -> StatusFlag { |
|
|
|
|
[call_initiator, end_of_stream = frame.end_of_stream]( |
|
|
|
|
StatusFlag status) mutable -> StatusFlag { |
|
|
|
|
if (!status.ok() && GRPC_TRACE_FLAG_ENABLED(chaotic_good)) { |
|
|
|
|
LOG(INFO) << "CHAOTIC_GOOD: Failed PushFragmentIntoCall"; |
|
|
|
|
} |
|
|
|
|
if (end_of_stream || !status.ok()) { |
|
|
|
|
call_initiator.FinishSends(); |
|
|
|
|
// We have received end_of_stream. It is now safe to remove
|
|
|
|
|
// the call from the stream map.
|
|
|
|
|
MutexLock lock(&mu_); |
|
|
|
|
stream_map_.erase(stream_id); |
|
|
|
|
// Note that we cannot remove from the stream map yet, as we
|
|
|
|
|
// may yet receive a cancellation.
|
|
|
|
|
} |
|
|
|
|
return Success{}; |
|
|
|
|
}); |
|
|
|
@ -102,17 +99,16 @@ auto ChaoticGoodServerTransport::PushFragmentIntoCall( |
|
|
|
|
|
|
|
|
|
auto ChaoticGoodServerTransport::MaybePushFragmentIntoCall( |
|
|
|
|
absl::optional<CallInitiator> call_initiator, absl::Status error, |
|
|
|
|
ClientFragmentFrame frame, uint32_t stream_id) { |
|
|
|
|
ClientFragmentFrame frame) { |
|
|
|
|
return If( |
|
|
|
|
call_initiator.has_value() && error.ok(), |
|
|
|
|
[this, &call_initiator, &frame, &stream_id]() { |
|
|
|
|
[this, &call_initiator, &frame]() { |
|
|
|
|
return Map( |
|
|
|
|
call_initiator->SpawnWaitable( |
|
|
|
|
"push-fragment", |
|
|
|
|
[call_initiator, frame = std::move(frame), stream_id, |
|
|
|
|
this]() mutable { |
|
|
|
|
return call_initiator->CancelIfFails(PushFragmentIntoCall( |
|
|
|
|
*call_initiator, std::move(frame), stream_id)); |
|
|
|
|
[call_initiator, frame = std::move(frame), this]() mutable { |
|
|
|
|
return call_initiator->CancelIfFails( |
|
|
|
|
PushFragmentIntoCall(*call_initiator, std::move(frame))); |
|
|
|
|
}), |
|
|
|
|
[](StatusFlag status) { return StatusCast<absl::Status>(status); }); |
|
|
|
|
}, |
|
|
|
@ -255,8 +251,7 @@ auto ChaoticGoodServerTransport::DeserializeAndPushFragmentToNewCall( |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return MaybePushFragmentIntoCall(std::move(call_initiator), std::move(status), |
|
|
|
|
std::move(fragment_frame), |
|
|
|
|
frame_header.stream_id); |
|
|
|
|
std::move(fragment_frame)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto ChaoticGoodServerTransport::DeserializeAndPushFragmentToExistingCall( |
|
|
|
@ -271,8 +266,7 @@ auto ChaoticGoodServerTransport::DeserializeAndPushFragmentToExistingCall( |
|
|
|
|
frame_header, std::move(buffers), arena, fragment_frame, |
|
|
|
|
FrameLimits{1024 * 1024 * 1024, aligned_bytes_ - 1}); |
|
|
|
|
return MaybePushFragmentIntoCall(std::move(call_initiator), std::move(status), |
|
|
|
|
std::move(fragment_frame), |
|
|
|
|
frame_header.stream_id); |
|
|
|
|
std::move(fragment_frame)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto ChaoticGoodServerTransport::ReadOneFrame(ChaoticGoodTransport& transport) { |
|
|
|
@ -305,6 +299,10 @@ auto ChaoticGoodServerTransport::ReadOneFrame(ChaoticGoodTransport& transport) { |
|
|
|
|
[this, &frame_header]() { |
|
|
|
|
absl::optional<CallInitiator> call_initiator = |
|
|
|
|
ExtractStream(frame_header.stream_id); |
|
|
|
|
GRPC_TRACE_LOG(chaotic_good, INFO) |
|
|
|
|
<< "Cancel stream " << frame_header.stream_id |
|
|
|
|
<< (call_initiator.has_value() ? " (active)" |
|
|
|
|
: " (not found)"); |
|
|
|
|
return If( |
|
|
|
|
call_initiator.has_value(), |
|
|
|
|
[&call_initiator]() { |
|
|
|
@ -410,6 +408,8 @@ void ChaoticGoodServerTransport::AbortWithError() { |
|
|
|
|
|
|
|
|
|
absl::optional<CallInitiator> ChaoticGoodServerTransport::LookupStream( |
|
|
|
|
uint32_t stream_id) { |
|
|
|
|
GRPC_TRACE_LOG(chaotic_good, INFO) |
|
|
|
|
<< "CHAOTIC_GOOD " << this << " LookupStream " << stream_id; |
|
|
|
|
MutexLock lock(&mu_); |
|
|
|
|
auto it = stream_map_.find(stream_id); |
|
|
|
|
if (it == stream_map_.end()) return absl::nullopt; |
|
|
|
@ -418,6 +418,8 @@ absl::optional<CallInitiator> ChaoticGoodServerTransport::LookupStream( |
|
|
|
|
|
|
|
|
|
absl::optional<CallInitiator> ChaoticGoodServerTransport::ExtractStream( |
|
|
|
|
uint32_t stream_id) { |
|
|
|
|
GRPC_TRACE_LOG(chaotic_good, INFO) |
|
|
|
|
<< "CHAOTIC_GOOD " << this << " ExtractStream " << stream_id; |
|
|
|
|
MutexLock lock(&mu_); |
|
|
|
|
auto it = stream_map_.find(stream_id); |
|
|
|
|
if (it == stream_map_.end()) return absl::nullopt; |
|
|
|
@ -428,6 +430,8 @@ absl::optional<CallInitiator> ChaoticGoodServerTransport::ExtractStream( |
|
|
|
|
|
|
|
|
|
absl::Status ChaoticGoodServerTransport::NewStream( |
|
|
|
|
uint32_t stream_id, CallInitiator call_initiator) { |
|
|
|
|
GRPC_TRACE_LOG(chaotic_good, INFO) |
|
|
|
|
<< "CHAOTIC_GOOD " << this << " NewStream " << stream_id; |
|
|
|
|
MutexLock lock(&mu_); |
|
|
|
|
auto it = stream_map_.find(stream_id); |
|
|
|
|
if (it != stream_map_.end()) { |
|
|
|
@ -437,10 +441,20 @@ absl::Status ChaoticGoodServerTransport::NewStream( |
|
|
|
|
return absl::InternalError("Stream id is not increasing"); |
|
|
|
|
} |
|
|
|
|
stream_map_.emplace(stream_id, call_initiator); |
|
|
|
|
call_initiator.OnDone([this, stream_id]() { |
|
|
|
|
MutexLock lock(&mu_); |
|
|
|
|
stream_map_.erase(stream_id); |
|
|
|
|
}); |
|
|
|
|
call_initiator.OnDone( |
|
|
|
|
[self = RefAsSubclass<ChaoticGoodServerTransport>(), stream_id](bool) { |
|
|
|
|
GRPC_TRACE_LOG(chaotic_good, INFO) |
|
|
|
|
<< "CHAOTIC_GOOD " << self.get() << " OnDone " << stream_id; |
|
|
|
|
absl::optional<CallInitiator> call_initiator = |
|
|
|
|
self->ExtractStream(stream_id); |
|
|
|
|
if (call_initiator.has_value()) { |
|
|
|
|
auto c = std::move(*call_initiator); |
|
|
|
|
c.SpawnInfallible("cancel", [c]() mutable { |
|
|
|
|
c.Cancel(); |
|
|
|
|
return Empty{}; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return absl::OkStatus(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|