-
Notifications
You must be signed in to change notification settings - Fork 55
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
feat(PE-2256): define chunk data cache interface and implementation #12
Conversation
f08e06a
to
8cbe7eb
Compare
bf9824d
to
61b969d
Compare
221bbe9
to
38a7e3f
Compare
src/cache/fs-chunk-cache.ts
Outdated
} | ||
|
||
function chunkCachePath(dataRoot: Buffer, relativeOffset: number) { | ||
return `${chunkCacheDir(dataRoot, relativeOffset)}/${relativeOffset}.msgpack`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ticket is intended to only address data caching (see the "Note: ..." at the bottom of the ticket description). We should be storing raw data bytes without any MessagePack encoding.
src/types.d.ts
Outdated
@@ -132,6 +138,16 @@ export interface PartialJsonTransactionCache { | |||
set(tx: PartialJsonTransaction): Promise<void>; | |||
} | |||
|
|||
export interface JsonChunkCache { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above, and we'll likely want a different interface interface for metadata when the time comes for that. I think a combo of my insufficient explanation + taking queues from header caching is leading you astray. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed this here f917a07
src/lib/encoding.ts
Outdated
@@ -194,6 +196,24 @@ export function msgpackTxToJsonTx( | |||
}; | |||
} | |||
|
|||
export function msgpackChunkToJsonChunk( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't technically needed since this ticket is only about data rather than metadata caching, but we may need something similar for upcoming tickets. However, for the metadata use case, they shouldn't include the actual chunk data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
going to remove for now, will add back with that ticket
src/cache/fs-chunk-cache.ts
Outdated
relativeOffset: number, | ||
): Promise<JsonChunk> { | ||
try { | ||
const chunkPromise = this.get(dataRoot, relativeOffset).then( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the caching logic from this and let it always fall through to the network. Metadata caching will be addressed in a future ticket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified in c1de268
src/cache/fs-chunk-cache.ts
Outdated
dataRoot: Buffer, | ||
relativeOffset: number, | ||
): Promise<Readable> { | ||
const { chunk } = await this.getChunkByRelativeOrAbsoluteOffset( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add logic here to cache just the chunk data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now caching only chunk data as unencoded buffer c1de268
5086f07
to
4a704f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is what I was trying to describe in the ticket. Thanks for the update!
eca4c3c
to
c24330f
Compare
c24330f
to
9caa07a
Compare
Details
FsChunkCache
that implementsChunkSource
andChunkDataCache
interfacesdata/chunks/<data_root>/data/<relativeOffset>
for cached chunk dataChunkSource
if chunk data is not found in the cache, then saves them to cache as unencodedBuffer
's for future retrieval