wsd: improve DocBroker state dumping logic

We dump the state of a DocBroker when we
detect data-loss, or when running a
unit-test that failed.

This simplifies the logic and improves it
by avoiding duplicate dumps and unnecessary
dumps.

Change-Id: I1cf2199d35073a762937ce2cf2377061e40b06b5
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
This commit is contained in:
Ashod Nakashian 2022-11-16 07:58:42 -05:00 committed by Ashod Nakashian
parent 19b6633625
commit 21dd54086c

View file

@ -510,29 +510,29 @@ void DocumentBroker::pollThread()
_poll->continuePolling() << ", ShutdownRequestFlag: " << SigUtil::getShutdownRequestFlag() <<
", TerminationFlag: " << SigUtil::getTerminationFlag() << ", closeReason: " << _closeReason << ". Flushing socket.");
// Check for data-loss.
std::string reason;
if (isModified() || isStorageOutdated())
{
// If we are exiting because the owner discarded conflict changes, don't detect data loss.
if (!(_docState.isCloseRequested() && _documentChangedInStorage))
{
// If the document is modified, or not uploaded, at exit, dump the state and warn.
const std::string reason = isModified() ? "flagged as modified"
: isStorageOutdated() ? "not uploaded to storage"
: "";
if (!reason.empty())
reason = isModified() ? "flagged as modified" : "not uploaded to storage";
// The test may override (if it was expected).
if (UnitWSD::isUnitTesting() &&
!_unitWsd.onDataLoss("Data-loss detected while exiting [" + _docKey + ']'))
reason.clear();
}
}
if (!reason.empty() || (UnitWSD::isUnitTesting() && _unitWsd.isFinished() && _unitWsd.failed()))
{
std::stringstream state;
state << "DocBroker [" << _docKey << " stopped "
<< (reason.empty() ? "because of test failure" : ("although " + reason)) << ": ";
dumpState(state);
LOG_WRN("DocumentBroker stopping although " << reason << ". State: " << state.str());
if (UnitWSD::isUnitTesting())
{
_unitWsd.onDataLoss("Data-loss detected while exiting DocBroker [" + _docKey + ']');
}
}
}
else if (UnitWSD::isUnitTesting() && _unitWsd.isFinished() && _unitWsd.failed())
{
std::stringstream state;
dumpState(state);
LOG_WRN("Test failed with doc [" << _docKey << "]: " << state.str());
LOG_WRN(state.str());
}
// Flush socket data first.