-
Notifications
You must be signed in to change notification settings - Fork 948
Memory LRU GC #6943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory LRU GC #6943
Changes from 9 commits
e8b53c6
3a922f1
107a051
14ed4f3
7b9d18d
2ea1fad
92b1cac
4ed6691
48d5077
7d0b186
d651d88
880bd55
c36e96f
85ea128
28215da
36715cd
4bbcbe1
3d22995
5b16efd
2b9d3b8
89f78c7
93738f3
1d5c82f
04f85ab
e53ae7f
2489fc6
70b742f
95f537e
a49b8a5
bb616a8
0c1c12e
1d0af2e
de64910
9771e74
f05a45e
57c64c7
faf7aca
8e62300
b83a723
6e5767d
c20f61f
68e2f21
5303e16
5bf4ec8
fc4bb55
85483bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ import { LruParams } from '../local/lru_garbage_collector'; | |
import { LruScheduler } from '../local/lru_garbage_collector_impl'; | ||
import { | ||
MemoryEagerDelegate, | ||
MemoryLruDelegate, | ||
MemoryPersistence | ||
} from '../local/memory_persistence'; | ||
import { Scheduler, Persistence } from '../local/persistence'; | ||
|
@@ -53,6 +54,7 @@ import { | |
remoteStoreShutdown | ||
} from '../remote/remote_store'; | ||
import { JsonProtoSerializer } from '../remote/serializer'; | ||
import { hardAssert } from '../util/assert'; | ||
import { AsyncQueue } from '../util/async_queue'; | ||
import { Code, FirestoreError } from '../util/error'; | ||
|
||
|
@@ -172,6 +174,37 @@ export class MemoryOfflineComponentProvider | |
} | ||
} | ||
|
||
export class LruGcMemoryOfflineComponentProvider extends MemoryOfflineComponentProvider { | ||
constructor(protected readonly cacheSizeBytes: number | undefined) { | ||
super(); | ||
} | ||
|
||
createGarbageCollectionScheduler( | ||
cfg: ComponentConfiguration, | ||
localStore: LocalStore | ||
): Scheduler | null { | ||
hardAssert( | ||
this.persistence.referenceDelegate instanceof MemoryLruDelegate, | ||
'referenceDelegate is expected to be an instance of MemoryLruDelegate.' | ||
); | ||
|
||
const garbageCollector = | ||
this.persistence.referenceDelegate.garbageCollector; | ||
return new LruScheduler(garbageCollector, cfg.asyncQueue, localStore); | ||
} | ||
|
||
createPersistence(cfg: ComponentConfiguration): Persistence { | ||
const lruParams = | ||
this.cacheSizeBytes !== undefined | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wondering if we need a range check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This actually won't work because we use -1 to disable GC. I really do not like this approach, we should do something similar to the new cache config API, using a dedicated enum branch to disable GC. Maybe something for the fixit week. |
||
? LruParams.withCacheSize(this.cacheSizeBytes) | ||
: LruParams.DEFAULT; | ||
return new MemoryPersistence( | ||
p => MemoryLruDelegate.factory(p, lruParams), | ||
this.serializer | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Provides all components needed for Firestore with IndexedDB persistence. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -353,6 +353,13 @@ export class MemoryLruDelegate implements ReferenceDelegate, LruDelegate { | |
this.garbageCollector = newLruGarbageCollector(this, lruParams); | ||
} | ||
|
||
static factory( | ||
persistence: MemoryPersistence, | ||
lruParams: LruParams | null | ||
): MemoryLruDelegate { | ||
return new MemoryLruDelegate(persistence, lruParams!!); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the double exclamation at the end of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It tells complier that you are sure this is a |
||
} | ||
|
||
// No-ops, present so memory persistence doesn't have to care which delegate | ||
// it has. | ||
onTransactionStarted(): void {} | ||
|
Uh oh!
There was an error while loading. Please reload this page.