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

未关闭
#374 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
冷清
技术栈
rust
领域
databases

调研方向

从 src/store/src/tikv/mod.rs 大约第 118 行的 BatchGet 调用开始,检查 transaction/buffer.rs 中引用的 tikv-client 事务缓冲代码。复现 inline tokio::spawn 测试,并跟踪 future 的 Send 要求;完成的标准是测试能够编译并运行,且不会出现报告中的 non-Send 错误。

由索引模型根据 Issue 内容生成。

描述

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

主要语言
Rust
星标
434
派生
168
平均合并
4 天 12 小时
30 天内合并 PR
2

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

tikv/client-rust 的其他 Issue

查看 tikv/client-rust 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。