Conversation
sunxiaoguang
left a comment
There was a problem hiding this comment.
Wow, you have done all the document part. It's fabulous.
| /// * 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`. |
| } | ||
| } | ||
|
|
||
| impl<'a> From<&'a [u8]> for KeyRef<'a> { |
There was a problem hiding this comment.
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"[..]);| type Item = Vec<KvPair>; | ||
| impl<'client, 'keys: 'client, Iter> Future for BatchGet<'client, 'keys, Iter> | ||
| where Iter: Iterator<Item=KeyRef<'keys>> { | ||
| type Item = (); |
There was a problem hiding this comment.
I guess this is a copy paste error. It is supposed to resolve to key/value pairs isn't it?
| } | ||
|
|
||
| impl<'a> Future for Scan<'a> { | ||
| impl<'client, 'keys: 'client, Bounds> Future for Scan<'client, 'keys, Bounds> |
There was a problem hiding this comment.
Just realized I only made Scanner in transaction api a Stream. Is implementing Stream better than Future?
| /// ``` | ||
| 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Unfortunately, the scan rpc returns RepeatedField of KvPair. To make it a Stream, tikv/tikv#3727 needs to be solved first.
| /// ```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"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
| pub struct BatchScan<'a> { | ||
| client: &'a Client, | ||
| ranges: Vec<(Key, Key)>, | ||
| ranges: Vec<(Bound<Key>, Bound<Key>)>, |
There was a problem hiding this comment.
What's your concern about collecting the iterator into a Vec? Is there any drawback of storing an iterator here (like the previous version)?
There was a problem hiding this comment.
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>
| /// 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! |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Great idea, I'll integrate this @sticnarf
| use quick_error::quick_error; | ||
| use std::{error, result}; | ||
|
|
||
| quick_error!{ |
There was a problem hiding this comment.
IMO, I want to try Failure instead of quick_error :-)
There was a problem hiding this comment.
Let me take a look into failure.
|
Closed in favor of #13 |
(This is a WIP!)
Based off #7.
Adds some documentation, along with tested examples.