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

Aperta
#374 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Tranquilla
Stack tecnologico
rust
Ambito
databases

Direzione di ricerca

Inizia dalla chiamata a BatchGet in src/store/src/tikv/mod.rs, intorno alla riga 118, e analizza il codice di buffering delle transazioni di tikv-client a cui si fa riferimento in transaction/buffer.rs. Riproduci il test inline tokio::spawn e traccia i requisiti Send della future; il lavoro è completato quando il test compila e viene eseguito senza l’errore non-Send segnalato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Rust
Stelle
434
Fork
168
Merge medio
4g 12h
PR unite (30g)
2

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tikv/client-rust

Tutte le issue di tikv/client-rust

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.