tikv / tikv/client-rust

BatchGet with tokio::spawn test error the trait `std::marker::Send` is not implemented for `dyn Iterator<Item = tikv_client::Key>`

Open
#374 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
425
Forks
163
Avg merge
10h 51m
Merged PRs (30d)
3

Description

test code

#[tokio::test]
    async fn spawn_test(){

        use crate::tikv::*;
        use tikv_client::{Config, Key,TransactionClient as Client, Value};

        tokio::spawn(async {
            let config = Config::default();
            let client = Client::new_with_config(vec![PD_ADDR], config).await.unwrap();

            let tikv_client = TikvClient::new(vec![PD_ADDR.to_string()]).await;

            let key1: Key = b"key1".to_vec().into();
            let value1: Value = b"value1".to_vec();
            let key2: Key = b"key2".to_vec().into();
            let value2: Value = b"value2".to_vec();

            let mut txn = client.begin_optimistic().await.unwrap();
            // batch get
            let result: HashMap<Key,Value> = txn
                .batch_get(vec![key1,key2])
                .await.unwrap()
                .map(|pair| (pair.0, pair.1))
                .collect();
            txn.commit().await.unwrap();
            print!("{:?}",result);
        });

    }

error:

error: future cannot be sent between threads safely
--> src/store/src/tikv/mod.rs:118:9
|
118 | tokio::spawn(async {
| ^^^^^^^^^^^^ future created by async block is not Send
|
= help: the trait std::marker::Send is not implemented for dyn Iterator<Item = tikv_client::Key>
note: future is not Send as this value is used across an await
--> /home/yuchao/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/tikv-client-0.1.0/src/transaction/buffer.rs:97:61
|
97 | let fetched_results = f(Box::new(undetermined_keys)).await?;
| --------------------------- ^^^^^^ await occurs here, with Box::new(undetermined_keys) maybe used later
| |
| has type Box<dyn Iterator<Item = tikv_client::Key>> which is not Send
note: Box::new(undetermined_keys) is later dropped here
--> /home/yuchao/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/tikv-client-0.1.0/src/transaction/buffer.rs:97:68
|
97 | let fetched_results = f(Box::new(undetermined_keys)).await?;
| ^
note: required by a bound in tokio::spawn
--> /home/yuchao/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/tokio-1.21.0/src/task/spawn.rs:127:21
|
127 | T: Future + Send + 'static,
| ^^^^ required by this bound in tokio::spawn

error: could not compile store due to previous error

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the BatchGet call in src/store/src/tikv/mod.rs around line 118 and inspect the tikv-client transaction buffering code referenced in transaction/buffer.rs. Reproduce the inline tokio::spawn test and trace the future's Send requirements; done means the test compiles and runs without the reported non-Send error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.