1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-08-08 09:42:06 +03:00

DebugState -> WriteDebugState

Summary: prepare for read support

Reviewed By: lnicco

Differential Revision: D20120444

fbshipit-source-id: 2a78448750ea1ba13ddb285fa55df98713a90d41
This commit is contained in:
Yang Chi
2020-03-03 18:48:49 -08:00
committed by Facebook Github Bot
parent 0fe2030305
commit 5bbbd964c8
4 changed files with 31 additions and 29 deletions

View File

@@ -1142,7 +1142,7 @@ void QuicTransportBase::updateWriteLooper(bool thisIteration) {
<< *this; << *this;
writeLooper_->run(thisIteration); writeLooper_->run(thisIteration);
if (conn_->loopDetectorCallback) { if (conn_->loopDetectorCallback) {
conn_->debugState.needsWriteLoopDetect = conn_->writeDebugState.needsWriteLoopDetect =
(conn_->loopDetectorCallback != nullptr); (conn_->loopDetectorCallback != nullptr);
} }
} else { } else {
@@ -1150,12 +1150,12 @@ void QuicTransportBase::updateWriteLooper(bool thisIteration) {
<< *this; << *this;
writeLooper_->stop(); writeLooper_->stop();
if (conn_->loopDetectorCallback) { if (conn_->loopDetectorCallback) {
conn_->debugState.needsWriteLoopDetect = false; conn_->writeDebugState.needsWriteLoopDetect = false;
conn_->debugState.currentEmptyLoopCount = 0; conn_->writeDebugState.currentEmptyLoopCount = 0;
} }
} }
if (conn_->loopDetectorCallback) { if (conn_->loopDetectorCallback) {
conn_->debugState.writeDataReason = writeDataReason; conn_->writeDebugState.writeDataReason = writeDataReason;
} }
} }
@@ -2292,18 +2292,18 @@ void QuicTransportBase::writeSocketData() {
auto packetsAfter = conn_->outstandingPackets.size(); auto packetsAfter = conn_->outstandingPackets.size();
bool packetWritten = (packetsAfter > packetsBefore); bool packetWritten = (packetsAfter > packetsBefore);
if (conn_->loopDetectorCallback && packetWritten) { if (conn_->loopDetectorCallback && packetWritten) {
conn_->debugState.currentEmptyLoopCount = 0; conn_->writeDebugState.currentEmptyLoopCount = 0;
} else if ( } else if (
conn_->debugState.needsWriteLoopDetect && conn_->writeDebugState.needsWriteLoopDetect &&
conn_->loopDetectorCallback) { conn_->loopDetectorCallback) {
// TODO: Currently we will to get some stats first. Then we may filter // TODO: Currently we will to get some stats first. Then we may filter
// out some errors here. For example, socket fail to write might be a // out some errors here. For example, socket fail to write might be a
// legit case to filter out. // legit case to filter out.
conn_->loopDetectorCallback->onSuspiciousWriteLoops( conn_->loopDetectorCallback->onSuspiciousWriteLoops(
++conn_->debugState.currentEmptyLoopCount, ++conn_->writeDebugState.currentEmptyLoopCount,
conn_->debugState.writeDataReason, conn_->writeDebugState.writeDataReason,
conn_->debugState.noWriteReason, conn_->writeDebugState.noWriteReason,
conn_->debugState.schedulerName); conn_->writeDebugState.schedulerName);
} }
// If we sent a new packet and the new packet was either the first // If we sent a new packet and the new packet was either the first
// packet // packet

View File

@@ -911,10 +911,10 @@ uint64_t writeConnectionDataToSocket(
connection.transportSettings.continueOnNetworkUnreachable); connection.transportSettings.continueOnNetworkUnreachable);
if (connection.loopDetectorCallback) { if (connection.loopDetectorCallback) {
connection.debugState.schedulerName = scheduler.name(); connection.writeDebugState.schedulerName = scheduler.name();
connection.debugState.noWriteReason = NoWriteReason::WRITE_OK; connection.writeDebugState.noWriteReason = NoWriteReason::WRITE_OK;
if (!scheduler.hasData()) { if (!scheduler.hasData()) {
connection.debugState.noWriteReason = NoWriteReason::EMPTY_SCHEDULER; connection.writeDebugState.noWriteReason = NoWriteReason::EMPTY_SCHEDULER;
} }
} }
auto writeLoopBeginTime = Clock::now(); auto writeLoopBeginTime = Clock::now();
@@ -954,7 +954,7 @@ uint64_t writeConnectionDataToSocket(
if (!packet || packet->packet.frames.empty()) { if (!packet || packet->packet.frames.empty()) {
ioBufBatch.flush(); ioBufBatch.flush();
if (connection.loopDetectorCallback) { if (connection.loopDetectorCallback) {
connection.debugState.noWriteReason = NoWriteReason::NO_FRAME; connection.writeDebugState.noWriteReason = NoWriteReason::NO_FRAME;
} }
return ioBufBatch.getPktSent(); return ioBufBatch.getPktSent();
} }
@@ -962,7 +962,7 @@ uint64_t writeConnectionDataToSocket(
// No more space remaining. // No more space remaining.
ioBufBatch.flush(); ioBufBatch.flush();
if (connection.loopDetectorCallback) { if (connection.loopDetectorCallback) {
connection.debugState.noWriteReason = NoWriteReason::NO_BODY; connection.writeDebugState.noWriteReason = NoWriteReason::NO_BODY;
} }
return ioBufBatch.getPktSent(); return ioBufBatch.getPktSent();
} }
@@ -1011,7 +1011,8 @@ uint64_t writeConnectionDataToSocket(
// it is because a flush() call failed // it is because a flush() call failed
if (!ret) { if (!ret) {
if (connection.loopDetectorCallback) { if (connection.loopDetectorCallback) {
connection.debugState.noWriteReason = NoWriteReason::SOCKET_FAILURE; connection.writeDebugState.noWriteReason =
NoWriteReason::SOCKET_FAILURE;
} }
return ioBufBatch.getPktSent(); return ioBufBatch.getPktSent();
} }

View File

@@ -1321,8 +1321,8 @@ TEST_F(QuicTransportTest, BusyWriteLoopDetection) {
auto mockLoopDetectorCallback = std::make_unique<MockLoopDetectorCallback>(); auto mockLoopDetectorCallback = std::make_unique<MockLoopDetectorCallback>();
auto rawLoopDetectorCallback = mockLoopDetectorCallback.get(); auto rawLoopDetectorCallback = mockLoopDetectorCallback.get();
conn.loopDetectorCallback = std::move(mockLoopDetectorCallback); conn.loopDetectorCallback = std::move(mockLoopDetectorCallback);
ASSERT_FALSE(conn.debugState.needsWriteLoopDetect); ASSERT_FALSE(conn.writeDebugState.needsWriteLoopDetect);
ASSERT_EQ(0, conn.debugState.currentEmptyLoopCount); ASSERT_EQ(0, conn.writeDebugState.currentEmptyLoopCount);
auto mockCongestionController = auto mockCongestionController =
std::make_unique<NiceMock<MockCongestionController>>(); std::make_unique<NiceMock<MockCongestionController>>();
auto rawCongestionController = mockCongestionController.get(); auto rawCongestionController = mockCongestionController.get();
@@ -1332,28 +1332,29 @@ TEST_F(QuicTransportTest, BusyWriteLoopDetection) {
// There should be no data to send at this point // There should be no data to send at this point
transport_->updateWriteLooper(true); transport_->updateWriteLooper(true);
EXPECT_FALSE(conn.debugState.needsWriteLoopDetect); EXPECT_FALSE(conn.writeDebugState.needsWriteLoopDetect);
EXPECT_EQ(WriteDataReason::NO_WRITE, conn.debugState.writeDataReason); EXPECT_EQ(WriteDataReason::NO_WRITE, conn.writeDebugState.writeDataReason);
EXPECT_EQ(0, conn.debugState.currentEmptyLoopCount); EXPECT_EQ(0, conn.writeDebugState.currentEmptyLoopCount);
loopForWrites(); loopForWrites();
auto stream = transport_->createBidirectionalStream().value(); auto stream = transport_->createBidirectionalStream().value();
auto buf = buildRandomInputData(100); auto buf = buildRandomInputData(100);
transport_->writeChain(stream, buf->clone(), true, false); transport_->writeChain(stream, buf->clone(), true, false);
transport_->updateWriteLooper(true); transport_->updateWriteLooper(true);
EXPECT_TRUE(conn.debugState.needsWriteLoopDetect); EXPECT_TRUE(conn.writeDebugState.needsWriteLoopDetect);
EXPECT_EQ(0, conn.debugState.currentEmptyLoopCount); EXPECT_EQ(0, conn.writeDebugState.currentEmptyLoopCount);
EXPECT_EQ(WriteDataReason::STREAM, conn.debugState.writeDataReason); EXPECT_EQ(WriteDataReason::STREAM, conn.writeDebugState.writeDataReason);
EXPECT_CALL(*socket_, write(_, _)).WillOnce(Return(1000)); EXPECT_CALL(*socket_, write(_, _)).WillOnce(Return(1000));
loopForWrites(); loopForWrites();
EXPECT_EQ(1, conn.outstandingPackets.size()); EXPECT_EQ(1, conn.outstandingPackets.size());
EXPECT_EQ(0, conn.debugState.currentEmptyLoopCount); EXPECT_EQ(0, conn.writeDebugState.currentEmptyLoopCount);
// Queue a window update for a stream doesn't exist // Queue a window update for a stream doesn't exist
conn.streamManager->queueWindowUpdate(stream + 1); conn.streamManager->queueWindowUpdate(stream + 1);
transport_->updateWriteLooper(true); transport_->updateWriteLooper(true);
EXPECT_TRUE( EXPECT_TRUE(
WriteDataReason::STREAM_WINDOW_UPDATE == conn.debugState.writeDataReason); WriteDataReason::STREAM_WINDOW_UPDATE ==
conn.writeDebugState.writeDataReason);
EXPECT_CALL(*socket_, write(_, _)).Times(0); EXPECT_CALL(*socket_, write(_, _)).Times(0);
EXPECT_CALL( EXPECT_CALL(
*rawLoopDetectorCallback, *rawLoopDetectorCallback,
@@ -1361,7 +1362,7 @@ TEST_F(QuicTransportTest, BusyWriteLoopDetection) {
.Times(1); .Times(1);
loopForWrites(); loopForWrites();
EXPECT_EQ(1, conn.outstandingPackets.size()); EXPECT_EQ(1, conn.outstandingPackets.size());
EXPECT_EQ(1, conn.debugState.currentEmptyLoopCount); EXPECT_EQ(1, conn.writeDebugState.currentEmptyLoopCount);
transport_->close(folly::none); transport_->close(folly::none);
} }

View File

@@ -786,7 +786,7 @@ struct QuicConnectionStateBase : public folly::DelayedDestruction {
// Debug information. Currently only used to debug busy loop of Transport // Debug information. Currently only used to debug busy loop of Transport
// WriteLooper. // WriteLooper.
struct DebugState { struct WriteDebugState {
bool needsWriteLoopDetect{false}; bool needsWriteLoopDetect{false};
uint64_t currentEmptyLoopCount{0}; uint64_t currentEmptyLoopCount{0};
WriteDataReason writeDataReason{WriteDataReason::NO_WRITE}; WriteDataReason writeDataReason{WriteDataReason::NO_WRITE};
@@ -794,7 +794,7 @@ struct QuicConnectionStateBase : public folly::DelayedDestruction {
std::string schedulerName; std::string schedulerName;
}; };
DebugState debugState; WriteDebugState writeDebugState;
std::shared_ptr<LoopDetectorCallback> loopDetectorCallback; std::shared_ptr<LoopDetectorCallback> loopDetectorCallback;