Skip to content
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

typescript: support chunk indexes with empty message index #1304

Merged
merged 3 commits into from
Jan 14, 2025

Conversation

achim-k
Copy link
Contributor

@achim-k achim-k commented Jan 7, 2025

Changelog

typescript: support chunk indexes with empty message index

Docs

None

Description

When a chunk contains no messages, the corresponding ChunkIndex's message index is empty. Prior to this PR, the typescript lib threw an exception when a chunk index with an empty message index was encountered.
This PR changes this to no longer throw when such a chunk index is encountered. If the message index is empty, the internal method #getSortTime will fallback to the chunk index' start time which is 0n and everything works as expected.

// Fall back to the chunk index' start time or end time.
return this.#reverse ? this.chunkIndex.messageEndTime : this.chunkIndex.messageStartTime;

Note: We could change the McapIndexedReader to exclude such chunk indexes from its internal heap, but I believe that it's not worth adding additional code for improving performance of such a corner case

@@ -38,10 +38,6 @@ export class ChunkCursor {
this.#startTime = params.startTime;
this.#endTime = params.endTime;
this.#reverse = params.reverse;

if (this.chunkIndex.messageIndexLength === 0n) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://mcap.dev/spec#chunk-index-op0x08

I think it would be helpful/pedantic to confirm that the message start/end time are 0 and messageIndexOffsets is also empty? these should all be true if there are indeed no messages. Otherwise we should throw since that would mean there are messages but no message index (or an incorrect length for the index) which indicates malformed file from the POV of our app or spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an extra check in loadMessageIndexes(). I think this is a better place to throw rather than in the constructur

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not throw as early as possible?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes you say it is a better place to throw?

Copy link
Member

@jtbandes jtbandes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 seems that sortTime does not matter (as long as it is stable) if there are no messages. I guess in practice this means that all empty chunks will be processed first.

@@ -38,10 +38,6 @@ export class ChunkCursor {
this.#startTime = params.startTime;
this.#endTime = params.endTime;
this.#reverse = params.reverse;

if (this.chunkIndex.messageIndexLength === 0n) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not throw as early as possible?

@achim-k achim-k merged commit 44485ee into main Jan 14, 2025
23 checks passed
@achim-k achim-k deleted the achim/ts-support-empty-message-index branch January 14, 2025 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants