Closed Bug 1733107 Opened 3 years ago Closed 1 year ago

Avoid repository traversal during simple origin clearing

Categories

(Core :: Storage: Quota Manager, task, P1)

task

Tracking

()

RESOLVED FIXED
120 Branch
Tracking Status
firefox-esr102 --- wontfix
firefox-esr115 --- wontfix
firefox113 --- wontfix
firefox114 --- wontfix
firefox115 --- wontfix
firefox116 --- wontfix
firefox118 --- wontfix
firefox119 --- wontfix
firefox120 --- fixed

People

(Reporter: janv, Assigned: janv)

References

(Blocks 1 open bug)

Details

Attachments

(7 files, 2 obsolete files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

nsIQuotaManagerService::clearStoragesForPrincipal has an option to set "clearAll". Clear all here means that an origin prefix will be used, so a full repository traversal is needed in that case.

However, when we clear exact origin (clearAll=false), we don't have to traverse entire repository.

I checked current callers in JS:
https://searchfox.org/mozilla-central/search?q=clearstoragesforprincipal%28&path=&case=false&regexp=false

SiteDataManager passes clearAll=true
https://searchfox.org/mozilla-central/rev/79f93e7a8b9aa1903f1349f2dd46fb71596f2ae9/browser/modules/SiteDataManager.jsm#448
but that shouldn't be used during shutdown

ClearDataService passes clearAll=false
https://searchfox.org/mozilla-central/rev/79f93e7a8b9aa1903f1349f2dd46fb71596f2ae9/toolkit/components/cleardata/ClearDataService.jsm#515

I believe the latter is used during shutdown in some cases, so if we can avoid the repository traversal, it should help with reducing shutdown hangs (but not only that, some clear origin operations will be faster in general).

I think we should split clearStoragesForPrincipal into two separate methods (and split also the operation in the parent process which handles it), one for simple/exact origin clearing and another one for the clearing by prefix.

In this patch, clearStoragesForPrincipal is split into two methods: one with same name, which only clear the storage under that exact origin, the other named clearStoragesForPrincipalWithPrefix clears all the storage prefixed with that origin.

Keywords: leave-open

The leave-open keyword is there and there is no activity for 6 months.
:jstutte, maybe it's time to close this bug?
For more information, please visit auto_nag documentation.

Flags: needinfo?(jstutte)

Hi Jan, I saw you took the two pending patches here.

Assignee: hxu → jvarga
Flags: needinfo?(jstutte)
Assignee: jvarga → hsingh

I now have time for this. It seems this can help to reduce shutdown hangs as well.

Assignee: hsingh → jvarga
Status: NEW → ASSIGNED
Keywords: leave-open
Priority: P2 → P1

Tracking for 114 as we need a fix for this cycle due to spiking crashes in bug 1588498

The bug is marked as tracked for firefox114 (beta). However, the bug still has low severity.

:jstutte, could you please increase the severity for this tracked bug? If you disagree with the tracking decision, please talk with the release managers.

For more information, please visit BugBot documentation.

Flags: needinfo?(jstutte)
Severity: S3 → S2
Flags: needinfo?(jstutte)

(In reply to Pascal Chevrel:pascalc from comment #6)

Tracking for 114 as we need a fix for this cycle due to spiking crashes in bug 1588498

I'm focusing on this bug too, but I just found out the root cause of the spike in crashes.
It's described in bug 1833810.

Depends on: 1824075
Depends on: 1749504

ClearRequestBase currently provides generic directory locking based on generic
member variables. It's not totally clear what derived classes do in terms of
directory locking and work on the QuotaManager IO thread. It would be better if
ClearRequestBase only provided a generic DeleteFiles function instead.

Changed done in this patch:

  • moved implementation of directory locking methods to derived classes of
    ClearRequestBase
  • moved implementation of DoDirectoryWork to derived classes as well
  • adjusted member variables

Depends on D186208

QuotaManagerService::ClearStoragesForOriginAttributesPattern and
QuotaManagerService::ClearStoragesForPrincipal still create sub actors which
makes it hard to add new clearing operations which would use async IPC messages
and which would inherit from the ClearRequestBase class as well.

Changes done in this patch:

  • added QuotaManager::ClearStoragesForOrigin
  • added QuotaManager::ClearStoragesForOriginAttributesPattern
  • changed ClearRequestBase to inherit from ResolvableNormalOriginOp
  • QuotaManagerService::ClearStoragesForOriginAttributesPattern reworked to use
    an asynchronous message instead of a sub actor
  • QuotaManagerService::ClearStoragesForPrincipal reworked to use an
    asynchronous message instead of a sub actor
  • added a new mactor QM_CUF_AND_IPC_FAIL similar to QM_IPC_FAIL

creating a sub actor

Depends on D186627

nsIQuotaManagerService::ClearStoragesForPrincipal currently supports both
clearing storages for a specific origin only and clearing storages for a group
of origins sharing the same prefix. It would be better to have separate methods
for this.

Changes done in this patch:

  • added nsIQuotaManagerService::ClearStoragesForOriginPrefix
  • added a new helper for testing clearOriginsByPrefix
  • changed verifyStorage to accept an optional shared key name
  • added thorough testing for the new method

Depends on D186628

There's now a dedicated nsIQuotaManagerService::ClearStoragesForOriginPrefix
method for clearing storages for origin prefix. All callers of
nsIQuotaManagerService::ClearStoragesForPrincipal which want to clear all
storages for given origin prefix can be now converted to call the new method.

Changed done in this patch:

  • replaced some nsIQuotaManagerService::ClearStoragesForPrincipal calls with
    nsIQuotaManagerService::ClearStoragesForOriginPrefix

Depends on D186777

There are now no callers of nsIQuotaManagerService::ClearStoragesForPrincipal
which would request clearing of all storages for given prefix. The support for
that can be removed.

Changed done in this patch:

  • removed the aClearAll argument from
    nsIQuotaManagerService::ClearStoragesForPrincipal
  • removed the aClearAll argument from the async IPC message
  • removed the aClearAll argument from QuotaManager::ClearStoragesForOrigin
  • changed ClearOriginOp to support clearing of exact origins only

Depends on D186778

The removing of an origin directory became a bit more complex because when the
app shutdown already started, origin directories shouldn't be fully removed
from disk. They need to be only moved to a special directory. All this
complexity should be covered by a dedicated QuotaManager method.

Changes done in this patch:

  • added a new method QuotaManager::RemoveOriginDirectory
  • added a prefilled string for the special to-be-removed directory
  • adjusted ClearRequestBase::DeleteFiles to use the new
    QuotaManager::RemoveOriginDirectory method

Depends on D186779

ClearRequestBase::DeleteFiles currently provides a way to clear origins for any
combination of persistence type, origin scope and client type. All origin
directiories need to be traversed to find relevant matches. This can be slow if
there are many origin directories. Fortunately, the traversal can be completely
avoided when exact origin is being cleared.

Changed done in this patch:

  • added a dedicated ClearRequestBase::DeleteFiles method for clearing of exact
    origins
  • changed ClearOriginOp::DoDirectoryWork to use the new variant of
    ClearRequestBase::DeleteFiles

Depends on D186780

Attachment #9243933 - Attachment is obsolete: true
Attachment #9249857 - Attachment is obsolete: true
Pushed by jvarga@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/e01641c5e0fb Move directory locking to derived classes of ClearRequestBase; r=dom-storage-reviewers,jstutte https://hg.mozilla.org/integration/autoland/rev/d1257bed6024 Rework remaining QuotaManagerService clearing methods to use asynchronous messages instead of creating sub actors; r=dom-storage-reviewers,jstutte https://hg.mozilla.org/integration/autoland/rev/490c2555afd1 Add nsIQuotaManagerService::ClearStoragesForOriginPrefix; r=dom-storage-reviewers,asuth,jstutte https://hg.mozilla.org/integration/autoland/rev/f57bf101a4d7 Replace some nsIQuotaManagerService::ClearStoragesForPrincipal calls with nsIQuotaManagerService::ClearStoragesForOriginPrefix; r=dom-storage-reviewers,pbz,asuth https://hg.mozilla.org/integration/autoland/rev/01a294b6bd17 Change nsIQuotaManagerService::ClearStoragesForPrincipal to support clearing of exact origins only; r=dom-storage-reviewers,asuth https://hg.mozilla.org/integration/autoland/rev/e9af992a25bf Add QuotaManager::RemoveOriginDirectory; r=dom-storage-reviewers,asuth https://hg.mozilla.org/integration/autoland/rev/988cc1efe8f1 Avoid repository traversals during clearing of exact origins; r=dom-storage-reviewers,asuth
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/42180 for changes under testing/web-platform/tests
Upstream PR merged by moz-wptsync-bot
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: