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

agate, util: fix varint decode and add header #29

Merged
merged 12 commits into from
Oct 29, 2020
Merged

Conversation

skyzh
Copy link
Member

@skyzh skyzh commented Oct 27, 2020

The implementation of varint decode seems to be wrong, and I've rewritten it from the Golang version.

Encode / decode has been moved to util.rs.

By the way, I also implemented decode / encode of WAL header.

Signed-off-by: Alex Chi <[email protected]>
src/util.rs Outdated Show resolved Hide resolved
@skyzh skyzh changed the title agate: fix varint decode and add header agate, util: fix varint decode and add header Oct 27, 2020
@skyzh skyzh added the status/review Ready for review label Oct 27, 2020
@skyzh skyzh mentioned this pull request Oct 27, 2020
25 tasks
src/util.rs Outdated
c + 1
}

pub unsafe fn decode_varint_uncheck(bytes: &[u8]) -> (u64, usize) {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I copied codec.rs and modified input parameter as BytesMut, plus adapting error type to agatedb.

let encoded_len = self.encoded_len();
bytes.reserve(encoded_len);
let read = unsafe {
let buf = bytes.bytes_mut();
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps adding an if check before entering get_unchecked_mut is better.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added the check assert!(buf.len() >= encoded_len);. Seems that reserve will always ensure the capacity is enough, I'm not sure whether this length check is necessary or not.

src/wal.rs Outdated Show resolved Hide resolved
@skyzh skyzh requested a review from BusyJay October 28, 2020 02:42
src/util/binary.rs Outdated Show resolved Hide resolved
src/wal.rs Show resolved Hide resolved
@@ -1,10 +1,70 @@
use super::Result;
use crate::util::binary::{
Copy link
Member

@Connor1996 Connor1996 Oct 28, 2020

Choose a reason for hiding this comment

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

How about using a crate like https://docs.rs/integer-encoding/2.1.1/integer_encoding/ instead of porting a go binary. /cc @BusyJay

Copy link
Member

Choose a reason for hiding this comment

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

The latest patch seems to copy the implementation from a library written by me. Only three functions are necessary and they are quite simple. I suggest to avoid adding new dependencies and delete unused functions in the futures.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll remove zig-zag functions and signed integer functions from binary.rs

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Now we only retain functions for varint u32 and u64.

@skyzh skyzh requested a review from Connor1996 October 28, 2020 08:10
@skyzh
Copy link
Member Author

skyzh commented Oct 28, 2020

@Connor1996 Now that binary.rs is less than 300 lines. I think it's okay to embed it in this project instead of importing new crates.

@skyzh skyzh merged commit 2ca3853 into master Oct 29, 2020
@skyzh skyzh deleted the change-entry-encode branch October 29, 2020 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/review Ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants