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

Abierto
#374 2 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Tranquilo
Stack tecnológico
rust
Área
databases

Línea de trabajo

Comienza en la llamada a BatchGet de src/store/src/tikv/mod.rs, alrededor de la línea 118, e inspecciona el código de almacenamiento en búfer de transacciones de tikv-client al que se hace referencia en transaction/buffer.rs. Reproduce la prueba inline de tokio::spawn y sigue los requisitos de Send del future; se considera terminado cuando la prueba compila y se ejecuta sin el error de non-Send indicado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Rust
Estrellas
434
Forks
168
Merge medio
4 d 12 h
PR fusionados (30 d)
2

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de tikv/client-rust

Todos los issues de tikv/client-rust

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.