wsd: better handling of low storage situation

There is no way to let the user of document currently being
opened, in case of failure, know that disk is low on space.
We check the disk space when forking children after which we try
to alert all users but this would end up doing nothing for
current document because document broker is not registered at
this time (we iterate through doc brokers when alerting). Another
conditional disk check is performed just before opening the
document but this is performed only if last disk check was
performed greater than 60 seconds which would never be the case
because document open is always preceded by a child fork (when
rebalancing children).

Lets not cache the disk check when forking the children to
prevent above mentioned situation while still minimizing the
number of disk checks performed.

Change-Id: Id3add998f94e23f9f8c144f09e5efe9f0b63821c
This commit is contained in:
Pranav Kant 2017-01-04 11:59:45 +05:30
parent fe1fe65e44
commit 62a666c06a
3 changed files with 11 additions and 6 deletions

View file

@ -158,7 +158,7 @@ namespace FileUtil
}
}
std::string checkDiskSpaceOnRegisteredFileSystems()
std::string checkDiskSpaceOnRegisteredFileSystems(const bool cacheLastCheck)
{
std::lock_guard<std::mutex> lock(fsmutex);
@ -169,7 +169,8 @@ namespace FileUtil
if (std::chrono::duration_cast<std::chrono::seconds>(now - lastCheck).count() < 60)
return std::string();
lastCheck = now;
if (cacheLastCheck)
lastCheck = now;
for (auto& i: filesystems)
{

View file

@ -50,8 +50,8 @@ namespace FileUtil
// Perform the check. If the free space on any of the registered file systems is below 5%, call
// 'alertAllUsers("internal", "diskfull")'. The check will be made no more often than once a
// minute.
std::string checkDiskSpaceOnRegisteredFileSystems();
// minute if cacheLastCheck is set to true.
std::string checkDiskSpaceOnRegisteredFileSystems(const bool cacheLastCheck = true);
// Check disk space on a specific file system, the one where 'path' is located. This does not
// add that file system to the list used by 'registerFileSystemForDiskSpaceChecks'. If the free

View file

@ -314,7 +314,7 @@ static bool forkChildren(const int number)
if (number > 0)
{
const std::string fs = FileUtil::checkDiskSpaceOnRegisteredFileSystems();
const std::string fs = FileUtil::checkDiskSpaceOnRegisteredFileSystems(false);
if (!fs.empty())
{
LOG_WRN("File system of " << fs << " dangerously low on disk space");
@ -1027,7 +1027,11 @@ private:
if (!fs.empty())
{
LOG_WRN("File system of [" << fs << "] is dangerously low on disk space.");
Util::alertAllUsers("error: cmd=internal kind=diskfull");
const std::string diskfullMsg = "error: cmd=internal kind=diskfull";
// Alert the session currently being opened
ws->sendFrame(diskfullMsg.data(), diskfullMsg.size());
// Alert all other existing sessions also
Util::alertAllUsers(diskfullMsg);
}
LOOLWSD::dumpEventTrace(docBroker->getJailId(), id, "NewSession: " + uri);