Skip to content

Fix LiteFileStream.SetReadStreamPosition#2459

Merged
JKamsker merged 10 commits intolitedb-org:masterfrom
SpaceCheetah:FixSeek
Jun 11, 2024
Merged

Fix LiteFileStream.SetReadStreamPosition#2459
JKamsker merged 10 commits intolitedb-org:masterfrom
SpaceCheetah:FixSeek

Conversation

@SpaceCheetah
Copy link
Contributor

Fix for issue #2458. Not a great solution, since it makes seeking much more expensive, but it works in my situation. I don't think there's a way to make it significantly faster without making chunks uniform length, which would require changes on the write side and not work for existing databases.

@bnuzhouwei
Copy link

What version can use this fix?

@SpaceCheetah
Copy link
Contributor Author

What version can use this fix?

Looking at the git blame, should be valid for basically any version from the last five years or so, though you'd have to apply the commit from my branch to that version. There's no released version with it, so no matter what you'd have to build it yourself.
That said, file streams need some pretty big fixes, this is just a patch to fix it for my use cases.

int loadedChunk = _currentChunkIndex;
int newChunkIndex = 0;
while (seekStreamPosition <= _streamPosition) {
if (!_chunkLengths.ContainsKey(newChunkIndex)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing an opportunity of using trygetvalue ;)

@JKamsker
Copy link
Collaborator

JKamsker commented Jun 4, 2024

I would like to see some unitttests for this pr as i currently don't fully understand the issue.

@JKamsker JKamsker self-assigned this Jun 11, 2024
private byte[] _currentChunkData = null;
private int _positionInChunk = 0;
private MemoryStream _buffer;
private Dictionary<int, long> _chunkLengths = new Dictionary<int, long>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not trying to force you change this, but are you sure sure separating fields from their main use is a good idea? I mean if it would be used by many different partials, this would imo the best place but you are only using it in the .Read partial.

What do you think? Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a big deal to me, whatever works best with the style for the repository.

seekStreamPosition += _currentChunkData.Length;
}
newChunkIndex++;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

While you are at it, add a new line here

@JKamsker JKamsker merged commit 409f6d5 into litedb-org:master Jun 11, 2024
@JKamsker
Copy link
Collaborator

Thank you for your contribution and bearing with me :D

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