Closed Bug 742822 Opened 12 years ago Closed 2 years ago

make localStorage and indexedDB share quota mechanisms

Categories

(Core :: Storage: localStorage & sessionStorage, defect, P2)

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: froydnj, Unassigned)

References

(Depends on 1 open bug, Blocks 4 open bugs)

Details

(Keywords: dev-doc-needed)

Attachments

(6 files, 12 obsolete files)

45.13 KB, patch
Details | Diff | Splinter Review
30.02 KB, patch
Details | Diff | Splinter Review
86.77 KB, patch
Details | Diff | Splinter Review
16.69 KB, patch
Details | Diff | Splinter Review
41.64 KB, patch
Details | Diff | Splinter Review
233.56 KB, image/jpeg
Details
This bug is a prerequisite to removing the indexedDB first usage prompt.

My understanding of the steps necessary to do this are:

1. Move localStorage DBs underneath $PROFILE/indexedDB/ so that SQLite quota mechanisms kick in for them too. 
2. Move the quota initialization mechanisms from IndexedDatabaseManager up the stack somewhat, so they can be freely called from the localStorage bits.

The SQLite quota mechanism can only track DBs in a single directory and its children.  It is possible to add individual plain files, but those files have to live int he aforementioned directory hierarchy.  I suppose we could tweak the SQLite quota bits to be able to manage things in several hierarchies simultaneously; that might be an easier plan, though it would make upstream merges more difficult.

This is a perf team Q2 goal.
We can't make localStorage store it's data under $PROFILE/indexedDB until we've changed the policy used there to not prompt but rather use the new caching behavior. Currently the IndexedDB code puts up a prompt when we start writing files, we can't do that for localStorage, even temporarily, since it'll "break" a lot of websites.

I think it's fine to have all files that we manage using this new policy live under the single $PROFILE/indexedDB directory (though the name isn't ideal, but we can deal with that separately). So we shouldn't need to handle separate hierarchies. In fact, it seems nice for several reasons if all files for a given directory under $PROFILE/indexedDB/
(In reply to Jonas Sicking (:sicking) from comment #1)
> We can't make localStorage store it's data under $PROFILE/indexedDB until
> we've changed the policy used there to not prompt but rather use the new
> caching behavior. Currently the IndexedDB code puts up a prompt when we
> start writing files, we can't do that for localStorage, even temporarily,
> since it'll "break" a lot of websites.

I am dense...what is the "new caching behavior" here?

And why does indexedDB prompt in the first place?  We already have quota mechanisms in place to make sure it doesn't overrun the disk.  I can totally get "this website has written 50MB of stuff to your drive, would you like to let it write  more", but what's the point of the first-run prompt with quotas?
Because even if you restrict the per-origin limit to a finite value, there are an infinite number of origins.
For the reason that Kyle mentioned, but also because we didn't want to leave permanent data on the users disk which may never get cleaned up (i.e. one of the problems that we are having with localStorage).

Regarding "the new caching behavior":

Currently we have a policy for both localStorage and IndexedDB to write files basically permanently to disk. They are not deleted unless the site does so intentionally. (Because of this permanence the IndexedDB implementation puts up a prompt). We also don't have a global limit for how much localStorage/IndexedDB data we can accumulate, we only have a per-site limit.

We want to switch to treating this data more like a cache. I.e. that we have have a global limit for how much data all of IndexedDB/localStorage can produce. Once we reach that limit, we throw out the IndexedDB/localStorage data for one of the domains according to some eviction policy (likely LRE for now).

So maybe "new caching behavior" is a bad description since there is no actual cache involved on our side. More like "use an eviction policy" :)
(In reply to Jonas Sicking (:sicking) from comment #4)
> For the reason that Kyle mentioned, but also because we didn't want to leave
> permanent data on the users disk which may never get cleaned up (i.e. one of
> the problems that we are having with localStorage).

Do we think we are having a problem, or do we have data about this (e.g. Telemetry)?

> Currently we have a policy for both localStorage and IndexedDB to write
> files basically permanently to disk. They are not deleted unless the site
> does so intentionally. (Because of this permanence the IndexedDB
> implementation puts up a prompt). We also don't have a global limit for how
> much localStorage/IndexedDB data we can accumulate, we only have a per-site
> limit.
> 
> We want to switch to treating this data more like a cache. I.e. that we have
> have a global limit for how much data all of IndexedDB/localStorage can
> produce. Once we reach that limit, we throw out the IndexedDB/localStorage
> data for one of the domains according to some eviction policy (likely LRE
> for now).

You mean LRU?

Thanks for the explanation.  So this bug is tied up with bug 735415?  (IIUC, that bug is mistitled, then.)
And tied up with bug 729320 also.
I don't think we have telemetry data on how much data users are actually lugging around currently. But this was enough of a concern that we decided to put in the prompt in IndexedDB. This prompt is something that we really need to remove in order for IndexedDB to be a plausible alternative to localStorage.
Opps, submitted too quickly.

Yes, I meant LRU :-)

And yes, bug 735415 and bug 729320 were early explorations which has become our current thinking. I.e. into what is described in comment 4.

I don't particularly care which bug the work is done in. I'm happy to close out the other bugs and just have this one be where we focus our efforts.
JFTR, I think that you are setting too high a bar for what needs to be done before the prompt gets removed.  I understand the finite quota x infinite domains argument and agree that global limits should be put into place; I just don't think they need to be done prior to prompt removal.  Let's ditch the clunky UI first; some of the plumbing (for a feature that is still in draft) can be worked out later.

Working out the details of expiry, especially expiry between localStorage and indexedDB and/or expiry across domains for indexedDB databases, seems pretty ugly.  I suppose one could just subsume the localStorage entries into the .sqlite file for indexedDB for each domain for the former.
(In reply to Nathan Froyd (:froydnj) from comment #9)
> JFTR, I think that you are setting too high a bar for what needs to be done
> before the prompt gets removed.  I understand the finite quota x infinite
> domains argument and agree that global limits should be put into place; I
> just don't think they need to be done prior to prompt removal.  Let's ditch
> the clunky UI first; some of the plumbing (for a feature that is still in
> draft) can be worked out later.

I think that's how we should proceed.
taking
Assignee: nobody → Jan.Varga
Depends on: 758357
Depends on: 763854
Depends on: 786769
Depends on: 787804
Depends on: 785884
No longer depends on: 763854, 787804
Status: NEW → ASSIGNED
Depends on: 942542
Depends on: 961049
No longer depends on: 942542
Blocks: 1147820
Attachment #8698938 - Flags: review?(jvarga)
Attached patch patch 2 - indentation (obsolete) — Splinter Review
Attachment #8702022 - Flags: review?(jvarga)
Attached patch patch 3 - remove ShouldPreload (obsolete) — Splinter Review
If we split the database in multiple files, this operation cannot be done anymore.
Attachment #8702023 - Flags: review?(jvarga)
Currently, with 1 DOMStorageDBChild per process, we send notifications using PStorage. But in the future we will have 1 DOMStorageDBChild per window, and that means that we must have a different way to dispatch notifications.
With this patch we do it using PContent.
Attachment #8702024 - Flags: review?(jvarga)
The previous version broke some xpcshell tests.
Attachment #8698938 - Attachment is obsolete: true
Attachment #8698938 - Flags: review?(jvarga)
Attachment #8702550 - Flags: review?(jvarga)
Attachment #8702024 - Attachment is obsolete: true
Attachment #8702024 - Flags: review?(jvarga)
Attachment #8702559 - Flags: review?(jvarga)
Comment on attachment 8702550 [details] [diff] [review]
patch 1 - getDirectoryForOrigin static

Review of attachment 8702550 [details] [diff] [review]:
-----------------------------------------------------------------

::: toolkit/forgetaboutsite/test/unit/head_forgetaboutsite.js
@@ +6,5 @@
>  var Ci = Components.interfaces;
>  var Cu = Components.utils;
>  
>  var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
> +var profileDir = do_get_profile(true);

Similar changes has been done also in:

dom/indexedDB/test/unit/test_globalObjects_other.js
dom/indexedDB/test/unit/test_sandbox.js
dom/indexedDB/test/unit/xpcshell-head-child-process.js
dom/indexedDB/test/unit/xpcshell-head-parent-process.js
dom/push/test/xpcshell/test_register_error_http2.js
> patch 3 - remove ShouldPreload
> 
> If we split the database in multiple files, this operation cannot be done
> anymore.

Does that mean that we can't preload any more? The preload is pretty important for performance. We need to make sure that we make the correct tradeoffs here.
(In reply to Jonas Sicking (:sicking) from comment #19)
> > patch 3 - remove ShouldPreload
> > 
> > If we split the database in multiple files, this operation cannot be done
> > anymore.
> 
> Does that mean that we can't preload any more? The preload is pretty
> important for performance. We need to make sure that we make the correct
> tradeoffs here.

Exactly.  What are rationals for these patches?  Preload is a killing feature and I really don't understand why it should be removed according migration to the QM.
Flags: needinfo?(amarchesini)
(In reply to Honza Bambas (:mayhemer) from comment #21)
> (In reply to Jonas Sicking (:sicking) from comment #19)
> > > patch 3 - remove ShouldPreload
> > > 
> > > If we split the database in multiple files, this operation cannot be done
> > > anymore.
> > 
> > Does that mean that we can't preload any more? The preload is pretty
> > important for performance. We need to make sure that we make the correct
> > tradeoffs here.
> 
> Exactly.  What are rationals for these patches?  Preload is a killing
> feature and I really don't understand why it should be removed according
> migration to the QM.

I already spoke with Andrea about this, he removed the preload just temporarily to make coding/reviewing easier. He/we will reintroduce it in another patch.
Flags: needinfo?(amarchesini)
Hmm... it seems you want to preload all the time, right?  If so, you will perform preloads where it's not needed (and LS is never touched).  It means waste of IPC rounds.

Unless really critical, I would leave the preloads implementation as is.
> Unless really critical, I would leave the preloads implementation as is.

If the plan is to split the database in multiple ones per origin, the current preload implementation cannot work as it is.
I disabled it because my plan is to reintroduce it later in a separate patch to land at the same time.
The 'new' preload implementation will use QM to iterate between all the origins and check if there is something to preload.
(In reply to Andrea Marchesini (:baku) from comment #24)
> > Unless really critical, I would leave the preloads implementation as is.
> 
> If the plan is to split the database in multiple ones per origin, the
> current preload implementation cannot work as it is.
> I disabled it because my plan is to reintroduce it later in a separate patch
> to land at the same time.
> The 'new' preload implementation will use QM to iterate between all the
> origins and check if there is something to preload.

Just interested: do you really need to remove it now?  Cannot you rather replace it when your new implementation is done?
> Just interested: do you really need to remove it now?  Cannot you rather
> replace it when your new implementation is done?

This is exactly what I want to do :)
These patches are not ready to land. I uploaded them in order to receive the first feedback from janv, but I want to land all together and not in intermediate steps.
(In reply to Andrea Marchesini (:baku) from comment #26)
> > Just interested: do you really need to remove it now?  Cannot you rather
> > replace it when your new implementation is done?
> 
> This is exactly what I want to do :)
> These patches are not ready to land. I uploaded them in order to receive the
> first feedback from janv, but I want to land all together and not in
> intermediate steps.

Sounds good, thanks!
Janv, can you give me a quick feedback (maybe not a fully review) of the first patches?
In order to know if I'm going in the right direction. Thanks!
Flags: needinfo?(jvarga)
baku, can you give me a few days ? I need to finish a patch for bug 1182987
Flags: needinfo?(jvarga)
Blocks: 1064466
Attachment #8702550 - Attachment is obsolete: true
Attachment #8702550 - Flags: review?(jvarga)
Attachment #8712182 - Flags: review?(jvarga)
Attached patch patch 2 - indentation (obsolete) — Splinter Review
Attachment #8702022 - Attachment is obsolete: true
Attachment #8702022 - Flags: review?(jvarga)
Attachment #8712184 - Flags: review?(jvarga)
Attached patch patch 3 - remove ShouldPreload (obsolete) — Splinter Review
Attachment #8702023 - Attachment is obsolete: true
Attachment #8702023 - Flags: review?(jvarga)
Attachment #8712185 - Flags: review?(jvarga)
Attachment #8702559 - Attachment is obsolete: true
Attachment #8702559 - Flags: review?(jvarga)
Attachment #8712186 - Flags: review?(jvarga)
Attachment #8712182 - Attachment is obsolete: true
Attachment #8712182 - Flags: review?(jvarga)
Attachment #8720308 - Flags: review?(jvarga)
Attached patch patch 2 - indentation (obsolete) — Splinter Review
Attachment #8712184 - Attachment is obsolete: true
Attachment #8712184 - Flags: review?(jvarga)
Attachment #8720309 - Flags: review?(jvarga)
Attached patch patch 3 - remove ShouldPreload (obsolete) — Splinter Review
Attachment #8712185 - Attachment is obsolete: true
Attachment #8712185 - Flags: review?(jvarga)
Attachment #8720310 - Flags: review?(jvarga)
Blocks: 857888
Attachment #8720309 - Attachment is obsolete: true
Attachment #8720309 - Flags: review?(jvarga)
Attachment #8728872 - Flags: review?(jvarga)
Attachment #8720310 - Attachment is obsolete: true
Attachment #8720310 - Flags: review?(jvarga)
Attachment #8729009 - Flags: review?(jvarga)
Attachment #8712186 - Attachment is obsolete: true
Attachment #8712186 - Flags: review?(jvarga)
Attachment #8729010 - Flags: review?(jvarga)
Depends on: 1286798
Attachment #8720308 - Flags: review?(jvarga)
Attachment #8728872 - Flags: review?(jvarga)
Attachment #8729009 - Flags: review?(jvarga)
Attachment #8729010 - Flags: review?(jvarga)
I'm working on a new architecture in bug 1286798. However, it seems I might be able to reuse some of the work done here.
See Also: → 1318713
hi,
this bug still happens, so the data manageris bugging : long script...
my webappsstore.sqlite is only 25MB....
so i delete it, then data manager works fine again.
Attached image Image1.jpg
the data manager frozen until this error box
Priority: -- → P2
:Janv can you give a text update on the bug here?
Flags: needinfo?(jvarga)
Yeah, this will be fixed by bug 1286798, no need to do anything special here.
Flags: needinfo?(jvarga)
Component: DOM → DOM: Web Storage
Assignee: jvarga → nobody
Status: ASSIGNED → NEW
Blocks: 1504142

LSNG has been enabled on Release in bug 1599979, so this can be finally resolved as fixed.

Here are some LSNG features relevant for this bug:

  • Quota checks and usage reporting for LS is shared with IDB and Cache API (and will be shared with any future quota clients like OPFS)
  • There’s no 5MB for entire eTLD+1 group as in the old implementation, the group limit is now 10GB (given/managed by QM).
  • The size of LS data is included in navigator.storage.estimate()
  • The logical size of LS data is tracked (this is different from all other quota clients like IDB and Cache API which track the physical size of files on disk)
  • LS data is evicted along with IDB and Cache API (the new caching behavior with LRU eviction, no prompts asking for a permission are required)
  • Alll data is stored under $PROFILE/storage (under the same directory hierarchy)
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: