Skip to content

WIP Docs#10

Closed
Hoverbear wants to merge 9 commits intomasterfrom
docs
Closed

WIP Docs#10
Hoverbear wants to merge 9 commits intomasterfrom
docs

Conversation

@Hoverbear
Copy link
Copy Markdown
Contributor

@Hoverbear Hoverbear commented Nov 19, 2018

(This is a WIP!)

Based off #7.

Adds some documentation, along with tested examples.

Copy link
Copy Markdown
Member

@sunxiaoguang sunxiaoguang left a comment

Choose a reason for hiding this comment

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

Wow, you have done all the document part. It's fabulous.

Comment thread src/raw.rs
/// * Write: Where MVCC and index related data are stored. Set by `[rocksdb.writecf]`.
/// * Lock: Where lock information is stored. Set by `[rocksdb.lockcf]`.
///
/// Not providing a call a `ColumnFamily` means it will use the default value of `default`.
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.

Is 'a call' typo?

Comment thread src/lib.rs Outdated
}
}

impl<'a> From<&'a [u8]> for KeyRef<'a> {
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.

How about implement From for reference to sized array smaller than 32. Like what rust std library does for array.
This way people can write code like this

let from_bytes = KeyRef::from(&b"TiKV");

instead of this

let from_bytes = KeyRef::from(&b"TiKV"[..]);

Comment thread src/raw.rs Outdated
type Item = Vec<KvPair>;
impl<'client, 'keys: 'client, Iter> Future for BatchGet<'client, 'keys, Iter>
where Iter: Iterator<Item=KeyRef<'keys>> {
type Item = ();
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.

I guess this is a copy paste error. It is supposed to resolve to key/value pairs isn't it?

Comment thread src/raw.rs Outdated
}

impl<'a> Future for Scan<'a> {
impl<'client, 'keys: 'client, Bounds> Future for Scan<'client, 'keys, Bounds>
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.

Just realized I only made Scanner in transaction api a Stream. Is implementing Stream better than Future?

Comment thread src/raw.rs Outdated
/// ```
pub fn scan<'client, 'keys, Bounds>(&'client self, range: Bounds, limit: impl Into<Option<u32>>) -> Scan<'client, 'keys, Bounds>
where Bounds: RangeBounds<KeyRef<'keys>> {
use std::u32::MAX;
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 the limit could be potentially large, Scan and BatchScan should definitely be Stream so it can do multiple round of scan. Otherwise the default value of MAX will blow up memory.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Unfortunately, the scan rpc returns RepeatedField of KvPair. To make it a Stream, tikv/tikv#3727 needs to be solved first.

Comment thread src/lib.rs
/// ```rust
/// # use tikv_client::Config;
/// let config = Config::new(vec!["192.168.0.100:2379", "192.168.0.101:2379"])
/// .with_security("root.ca", "internal.cert", "internal.key");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Three arguments of the same type means it is easy to put them in the wrong order. I would definitely keep it as one builder though. I would either newtype some of the arguments or take a struct with meaningfully named fields (essentially Rust does not have named arguments). Internally I would also use a struct so there is just one Option instead of three.

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.

Having a dedicated type with constructor is equally tricky as this one. Therefore the type will have to make everything public to make it possible to construct by field name.
How about break it into three methods to set them separately.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Three separate methods doesn't capture the nature of this: there are three arguments, and they must be given as all or none. The concern with the constructor is making it public? Won't any solution need to make something public?

Comment thread src/raw.rs
pub struct BatchScan<'a> {
client: &'a Client,
ranges: Vec<(Key, Key)>,
ranges: Vec<(Bound<Key>, Bound<Key>)>,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's your concern about collecting the iterator into a Vec? Is there any drawback of storing an iterator here (like the previous version)?

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.

I'd like to revisit doing that :)

Signed-off-by: Hoverbear <operator@hoverbear.org>
Signed-off-by: Hoverbear <operator@hoverbear.org>
Signed-off-by: Hoverbear <operator@hoverbear.org>
Signed-off-by: Hoverbear <operator@hoverbear.org>
Comment thread src/lib.rs Outdated
/// The only way to avoid this would be to only accept two `Bound<T>` arguments, not one
/// `RangeBound<T>` argument. This would mean `"abc"..="xyz"` would not be possible.
///
// TODO: If you feel tricky please try to remove this clone!
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I introduce another trait to avoid this clone. Would you please see if this looks good to you?

https://github.com/sticnarf/tikv-client-rust/tree/key-range-trait

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Yea, I think this way is better it can avoid extra clone when bound is already a Key however make it possible to use non Key type which can be converted to Key.

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.

Great idea, I'll integrate this @sticnarf

Comment thread src/errors.rs
use quick_error::quick_error;
use std::{error, result};

quick_error!{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMO, I want to try Failure instead of quick_error :-)

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.

Let me take a look into failure.

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.

I also do! :)

@Hoverbear
Copy link
Copy Markdown
Contributor Author

Closed in favor of #13

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.

5 participants