Bug 1292623 - Only write HTTP cache entries' metadata after shutdown. r=michal

--HG--
extra : rebase_source : 0ad5bde99a6fc969f7ec6033cd7010b425f1504f
This commit is contained in:
Honza Bambas 2016-08-26 05:05:00 -04:00
parent dae1f761d1
commit a7ea3ad127
2 changed files with 32 additions and 1 deletions

View File

@ -45,7 +45,7 @@
namespace mozilla {
namespace net {
#define kOpenHandlesLimit 64
#define kOpenHandlesLimit 128
#define kMetadataWriteDelay 5000
#define kRemoveTrashStartDelay 60000 // in milliseconds
#define kSmartSizeUpdateInterval 60000 // in milliseconds
@ -119,6 +119,7 @@ CacheFileHandle::CacheFileHandle(const SHA1Sum::Hash *aHash, bool aPriority, Pin
, mFileExists(false)
, mDoomWhenFoundPinned(false)
, mDoomWhenFoundNonPinned(false)
, mKilled(false)
, mPinning(aPinning)
, mFileSize(-1)
, mFD(nullptr)
@ -142,6 +143,7 @@ CacheFileHandle::CacheFileHandle(const nsACString &aKey, bool aPriority, Pinning
, mFileExists(false)
, mDoomWhenFoundPinned(false)
, mDoomWhenFoundNonPinned(false)
, mKilled(false)
, mPinning(aPinning)
, mFileSize(-1)
, mFD(nullptr)
@ -1951,6 +1953,17 @@ CacheFileIOManager::WriteInternal(CacheFileHandle *aHandle, int64_t aOffset,
nsresult rv;
if (aHandle->mKilled) {
LOG((" handle already killed, nothing written"));
return NS_OK;
}
if (CacheObserver::ShuttingDown() && (!aValidate || !aHandle->mFD)) {
aHandle->mKilled = true;
LOG((" killing the handle, nothing written"));
return NS_OK;
}
if (CacheObserver::IsPastShutdownIOLag()) {
LOG((" past the shutdown I/O lag, nothing written"));
// Pretend the write has succeeded, otherwise upper layers will doom
@ -2461,6 +2474,17 @@ CacheFileIOManager::TruncateSeekSetEOFInternal(CacheFileHandle *aHandle,
nsresult rv;
if (aHandle->mKilled) {
LOG((" handle already killed, file not truncated"));
return NS_OK;
}
if (CacheObserver::ShuttingDown() && !aHandle->mFD) {
aHandle->mKilled = true;
LOG((" killing the handle, file not truncated"));
return NS_OK;
}
if (!aHandle->mFileExists) {
rv = CreateFile(aHandle);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -105,6 +105,13 @@ private:
// These flags are only accessed on the IO thread.
bool mDoomWhenFoundPinned : 1;
bool mDoomWhenFoundNonPinned : 1;
// Set when after shutdown AND:
// - when writing: writing data (not metadata) OR the physical file handle is not currently open
// - when truncating: the physical file handle is not currently open
// When set it prevents any further writes or truncates on such handles to happen immediately
// after shutdown and gives a chance to write metadata of already open files quickly as possible
// (only that renders them actually usable by the cache.)
bool mKilled : 1;
// For existing files this is always pre-set to UNKNOWN. The status is udpated accordingly
// after the matadata has been parsed.
// For new files the flag is set according to which storage kind is opening