Transaction::batch_get should return Result<Vec<KvPair>>
Closed this issue · 4 comments
blacktear23 commented
Transaction::batch_get
should return Result<Vec<KvPair>>
as RawClient
do.
Currently Result<impl Iterator<Item = KvPair>>
not implements Copy trait so it cannot compile in tokio::spawn
async block.
ekexium commented
Could you provide an example?
blacktear23 commented
Sample Code:
use tikv_client::TransactionClient;
use tokio::runtime::Runtime;
async fn tikv_test() {
let pd_addrs = vec![String::from("127.0.0.1:2379")];
let conn = TransactionClient::new(pd_addrs).await.unwrap();
let mut txn = conn.begin_pessimistic().await.unwrap();
txn.batch_get(vec![String::from("key1"), String::from("key2")]).await;
}
fn main() {
let runtime = Runtime::new().unwrap();
runtime.spawn(async move {
tikv_test().await;
});
runtime.block_on(async {
tikv_test().await;
});
println!("Hello, world!");
}
Compiling tikvclienttest v0.1.0 (/Users/rain/work/tikvclienttest)
error[E0277]: `dyn Iterator<Item = Key>` cannot be sent between threads safely
--> src/main.rs:13:13
|
13 | runtime.spawn(async move {
| ^^^^^ `dyn Iterator<Item = Key>` cannot be sent between threads safely
|
= help: the trait `Send` is not implemented for `dyn Iterator<Item = Key>`
= note: required because of the requirements on the impl of `Send` for `Unique<dyn Iterator<Item = Key>>`
= note: required because it appears within the type `Box<dyn Iterator<Item = Key>>`
= note: required because it appears within the type `for<'r, 's> {ResumeTy, &'r mut transaction::buffer::Buffer, Map<std::vec::IntoIter<String>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#0}]>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#1}], FilterMap<std::vec::IntoIter<(Key, transaction::buffer::MutationValue)>, [closure@transaction::buffer::Buffer::batch_get_or_else<[closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#1}], impl Future, Map<std::vec::IntoIter<String>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#0}]>>::{closure#0}::{closure#2}]>, Map<std::vec::IntoIter<(Key, transaction::buffer::MutationValue)>, [closure@transaction::buffer::Buffer::batch_get_or_else<[closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#1}], impl Future, Map<std::vec::IntoIter<String>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#0}]>>::{closure#0}::{closure#3}]>, Box<(dyn Iterator<Item = Key> + 's)>, Box<Map<std::vec::IntoIter<(Key, transaction::buffer::MutationValue)>, [closure@transaction::buffer::Buffer::batch_get_or_else<[closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#1}], impl Future, Map<std::vec::IntoIter<String>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#0}]>>::{closure#0}::{closure#3}]>>, impl Future, ()}`
= note: required because it appears within the type `[static generator@transaction::buffer::Buffer::batch_get_or_else<[closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#1}], impl Future, Map<std::vec::IntoIter<String>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#0}]>>::{closure#0}]`
= note: required because it appears within the type `from_generator::GenFuture<[static generator@transaction::buffer::Buffer::batch_get_or_else<[closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#1}], impl Future, Map<std::vec::IntoIter<String>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#0}]>>::{closure#0}]>`
= note: required because it appears within the type `impl Future`
= note: required because it appears within the type `impl Future`
= note: required because it appears within the type `for<'r, 's, 't0, 't1, 't2, 't3, 't4, 't5, 't6, 't7> {ResumeTy, &'r mut Transaction, Vec<String>, &'s Transaction, impl for<'t0> Future, (), Timestamp, Arc<tikv_client::pd::client::PdRpcClient>, RetryOptions, Transaction, &'t1 mut transaction::buffer::Buffer, transaction::buffer::Buffer, std::vec::IntoIter<String>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#0}], Map<std::vec::IntoIter<String>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#0}]>, [closure@Transaction::batch_get<String, Vec<String>>::{closure#0}::{closure#1}], impl for<'t4, 't5, 't6, 't7> Future}`
= note: required because it appears within the type `[static generator@Transaction::batch_get<String, Vec<String>>::{closure#0}]`
= note: required because it appears within the type `from_generator::GenFuture<[static generator@Transaction::batch_get<String, Vec<String>>::{closure#0}]>`
= note: required because it appears within the type `impl Future`
= note: required because it appears within the type `impl Future`
= note: required because it appears within the type `for<'r, 's, 't0, 't1, 't2> {ResumeTy, Vec<String>, impl Future, (), TransactionClient, &'r TransactionClient, impl for<'s> Future, Transaction, &'t0 mut Transaction, &'t1 str, String, [String; 2], Box<[String]>, Box<[String; 2]>, impl for<'t2> Future}`
= note: required because it appears within the type `[static generator@src/main.rs:4:22: 9:2]`
= note: required because it appears within the type `from_generator::GenFuture<[static generator@src/main.rs:4:22: 9:2]>`
= note: required because it appears within the type `impl Future`
= note: required because it appears within the type `impl Future`
= note: required because it appears within the type `{ResumeTy, impl Future, ()}`
= note: required because it appears within the type `[static generator@src/main.rs:13:30: 15:6]`
= note: required because it appears within the type `from_generator::GenFuture<[static generator@src/main.rs:13:30: 15:6]>`
= note: required because it appears within the type `impl Future`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `tikvclienttest` due to previous error
blacktear23 commented
@ekexium It works for master branch. Thanks!