Skip to content

Commit a182a7b

Browse files
committed
tfbuilder: fix merge.stf_fetch_ms metric
1 parent 0a4c864 commit a182a7b

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/TfBuilder/TfBuilderRpc.cxx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -606,25 +606,29 @@ void TfBuilderRpcImpl::StfRequestGrpcThread()
606606
auto &lGrpcReq = lGrpcReqOpt.value();
607607
auto &lStfRequest = lGrpcReq.mStfRequest;
608608

609+
bool lReqFailed = true;
609610
StfDataResponse lStfResponse;
610611
grpc::Status lStatus = StfSenderRpcClients()[lStfRequest.mStfSenderId]->StfDataRequest(lStfRequest.mRequest, lStfResponse);
611612
if (!lStatus.ok()) {
612613
EDDLOG("StfSender gRPC connection problem. stfs_id={} code={} error={} stf_size={}",
613614
lStfRequest.mStfSenderId, lStatus.error_code(), lStatus.error_message(), lStfRequest.mStfDataSize);
614-
{
615-
std::unique_lock lInFlightLock(mNumInFlightLock);
616-
mNumReqInFlight -= 1;
617-
}
618615
} else if (lStfResponse.status() != StfDataResponse::OK) {
619616
EDDLOG("StfSender did not sent data. stfs_id={} reason={}",
620617
lStfRequest.mStfSenderId, StfDataResponse_StfDataStatus_Name(lStfResponse.status()));
621-
{
622-
std::unique_lock lInFlightLock(mNumInFlightLock);
623-
mNumReqInFlight -= 1;
624-
}
625618
} else {
626619
// Update the expected STF count
627620
lGrpcReq.mNumExpectedStfs += 1;
621+
lReqFailed = false;
622+
}
623+
624+
if (lReqFailed) {
625+
std::unique_lock lInFlightLock(mNumInFlightLock);
626+
mNumReqInFlight -= 1;
627+
}
628+
629+
{ // record time of the request to measure total time until STFs is fetched
630+
std::scoped_lock lLock(mStfDurationMapLock);
631+
mStfReqDuration[lStfRequest.mRequest.stf_id()][lStfRequest.mStfSenderId] = std::chrono::steady_clock::now();
628632
}
629633

630634
{ // notify the main request loop

0 commit comments

Comments
 (0)