Skip to content

ORC-614: Implement efficient seek() in decompression streams - #499

Closed
luksan47 wants to merge 3 commits into
apache:mainfrom
luksan47:ORC-614
Closed

luksan47 wants to merge 3 commits into
apache:mainfrom
luksan47:ORC-614

Conversation

@luksan47

Copy link
Copy Markdown
Contributor

The current implementation of ZlibDecompressionStream::seek and
BlockDecompressionStream::seek resets the state of the decompressor
and the underlying file reader and throws away their buffers.

This commit introduces two optimizations which rely on reusing
the buffers that still contain useful data, and therefore reducing
the time spent reading/uncompressing the buffers again.

The first case is when the seeked position is already read
and decompressed into the output stream.

The second case is when the seeked position is already read from
the input stream, but has not been decompressed yet, ie. it's
not in the output stream.

Tests:

The current implementation of ZlibDecompressionStream::seek and
BlockDecompressionStream::seek resets the state of the decompressor
and the underlying file reader and throws away their buffers.

This commit introduces two optimizations which rely on reusing
the buffers that still contain useful data, and therefore reducing
the time spent reading/uncompressing the buffers again.

The first case is when the seeked position is already read
and decompressed into the output stream.

The second case is when the seeked position is already read from
the input stream, but has not been decompressed yet, ie. it's
not in the output stream.

Tests:
 - Run the ORC tests, and the Impala tests working on ORC tables.
 - The regression that apache#476 would cause is not present anymore.
@luksan47

Copy link
Copy Markdown
Contributor Author

FYI, I also opened since there is a lot of duplicate code: https://issues.apache.org/jira/browse/ORC-615

@luksan47

Copy link
Copy Markdown
Contributor Author

Sent in #500, if you could review it first, that would reduce the amount of code change (and possible mistakes) here as well.

@wgtmac

wgtmac commented Mar 26, 2020

Copy link
Copy Markdown
Member

@luksan47 I am working on it. Will finish reviewing this PR by the end of this week.

@luksan47

Copy link
Copy Markdown
Contributor Author

Thanks, @wgtmac!

@wgtmac wgtmac left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@luksan47 The overall fix looks good to me except there is a possible correctness issue. Please see the detail in the comments.

Comment thread c++/src/Compression.cc
DecompressState state;

// the start of the current buffer
// This pointer is not owned by us. It is either owned by zstream or

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

keep this comment to ease the understanding

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK. Changed the comment a bit, since it is not owned by zstream.

Comment thread c++/src/Compression.cc Outdated
}
if (state == DECOMPRESS_HEADER || remainingLength == 0) {
readHeader();
headerPosition

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Name of headerPosition is confusing since it actually means the position of the 1st byte after the 3-byte compressed block header.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Kept the name since we look up this position, changed the value instead.

Comment thread c++/src/Compression.cc
// seeked position.
position.next(); // Skip the input level position.
inputBuffer
= inputBufferStart + (seekedPosition - inputBufferStartPosition);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If seekedPosition is smaller than inputBufferStartPosition, the inputBufferStart does not contain the data we need. This can happen when users call RowReader::seekToRow() in a reverse order.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added condition.

@wgtmac

wgtmac commented Mar 31, 2020

Copy link
Copy Markdown
Member

@luksan47 Please fix the travis build. It would be more confident if you can test cases for all 3 scenarios under seek.

@pgaref

pgaref commented Feb 17, 2021

Copy link
Copy Markdown
Contributor

Was reviewing #476 and bump into this -- shall we revive this? @luksan47 @wgtmac

@wgtmac

wgtmac commented Feb 19, 2021

Copy link
Copy Markdown
Member

Was reviewing #476 and bump into this -- shall we revive this? @luksan47 @wgtmac

Thanks for pinging me. I will try to do that.

@wgtmac

wgtmac commented Apr 20, 2021

Copy link
Copy Markdown
Member

Hey @luksan47, are you still interested in this patch?

@luksan47

Copy link
Copy Markdown
Contributor Author

Hey @wgtmac, sorry but I don't have the capacity at the moment to work on this PR :(
You can use/copy my commits if you'd like to merge this.

@wgtmac

wgtmac commented May 5, 2021

Copy link
Copy Markdown
Member

Opened a new PR #695 and thus closed this one. Thanks @luksan47

@wgtmac wgtmac closed this May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants