Local db get nuked when syncing from remote if dev server restarted
メンテナーはふだん 11 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 38/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- rust, sqlite
調査の方向性
Builder::new_remote_replica、local.db、remote.db、db.sync()を使用してRustクライアントで問題を再現し、その後、説明されているとおりに両方のturso devサーバーを再起動します。リモートレプリカの同期パスを調査し、cargo runを再実行するとusersテーブルとlocal.db内の行が復元され、空のままにならないことを確認します。
索引モデルが issue の本文から書いたものです。
説明
Steps to reproduce:
-
Run the dev server
$ turso dev -f remote.db sqld listening on port 8080. Use the following URL to configure your libSQL client SDK for local development: http://127.0.0.1:8080 By default, no auth token is required when sqld is running locally. If you want to require authentication, use --auth-jwt-key-file to specify a file containing the JWT key. Using database file remote.db. -
Create a rust client
cargo new client cd client cargo add libsql -F remote,replication,sync cargo add tokio -F full cat <<"EOF" >src/main.rs use libsql::{Builder, Result}; const CREATE_USERS_TABLE: &str = "\ CREATE TABLE IF NOT EXISTS users (\ id INTEGER PRIMARY KEY, \ name TEXT UNIQUE NOT NULL, \ email TEXT UNIQUE NOT NULL\ )"; const SELECT_USER: &str = "SELECT * FROM users WHERE name = ?1 AND email = ?2"; const INSERT_USER: &str = "INSERT INTO users (name, email) VALUES (?1, ?2)"; const SELECT_USERS: &str = "SELECT * FROM users"; #[tokio::main] async fn main() -> Result<()> { let local_path = "local.db"; // let local_path = ":memory:"; let remote_url = "http://127.0.0.1:8080"; let remote_auth = ""; print!("Builder (path={local_path:?}, url={remote_url:?}, auth_token={remote_auth:?})... "); let db = Builder::new_remote_replica( local_path.to_string(), remote_url.to_string(), remote_auth.to_string(), ) .build() .await?; println!("Done"); print!("Syncing... "); let f = db.sync().await?; println!("{f:?}"); print!("Connecting... "); let conn = db.connect()?; println!("{conn:?}"); print!("Syncing... "); let f = db.sync().await?; println!("{f:?}"); print!("Create users table (if doesn't already exist)... "); conn.execute(CREATE_USERS_TABLE, ()).await?; println!("Done"); println!("Insert users..."); for (name, email) in &[ ("Alice", "[email protected]"), ("Bob", "[email protected]"), ("Charlie", "[email protected]"), ] { let mut rows = conn.query(SELECT_USER, (*name, *email)).await?; if let Some(row) = rows.next().await? { println!("* User {name:?} {email:?} already exists! `row = {row:?}`"); } else { println!("* Inserting user {name:?} {email:?}"); conn.execute(INSERT_USER, [*name, *email]).await?; print!("\n Syncing... "); let f = db.sync().await?; println!("{f:?}\n"); } } println!("Select all users..."); let mut rows = conn.query(SELECT_USERS, ()).await?; print!("\n```json\n{{\"users\": ["); let mut count = 0; while let Some(row) = rows.next().await? { count += 1; let id = row.get_value(0)?; let name = row.get_value(1)?; let email = row.get_value(2)?; let id = id.as_integer().unwrap(); let name = name.as_text().unwrap(); let email = email.as_text().unwrap(); if count > 1 { print!(","); } print!("\n {{\"id\": {id:?}, \"name\": {name:?}, \"email\": {email:?}}}"); } println!("\n]}}\n```\n"); Ok(()) } EOF -
Build and run it:
$ cargo run ... Builder (path="local.db", url="http://127.0.0.1:8080", auth_token="")... Done Syncing... Replicated { frame_no: Some(0), frames_synced: 1 } Connecting... Connection Syncing... Replicated { frame_no: Some(0), frames_synced: 0 } Create users table (if doesn't already exist)... Done Insert users... * Inserting user "Alice" "[email protected]" Syncing... Replicated { frame_no: Some(7), frames_synced: 0 } * Inserting user "Bob" "[email protected]" Syncing... Replicated { frame_no: Some(10), frames_synced: 0 } * Inserting user "Charlie" "[email protected]" Syncing... Replicated { frame_no: Some(13), frames_synced: 0 } Select all users... ```json {"users": [ {"id": 1, "name": "Alice", "email": "[email protected]"}, {"id": 2, "name": "Bob", "email": "[email protected]"}, {"id": 3, "name": "Charlie", "email": "[email protected]"} ]} ``` -
Check that it wrote to the remote db:
$ turso db shell http://127.0.0.1:8080 .dump PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT UNIQUE NOT NULL, email TEXT UNIQUE NOT NULL); INSERT INTO users VALUES(1,'Alice','[email protected]'); INSERT INTO users VALUES(2,'Bob','[email protected]'); INSERT INTO users VALUES(3,'Charlie','[email protected]'); COMMIT; -
Check that it wrote to the local db:
$ turso dev -f local.db -p 8081 sqld listening on port 8081. Use the following URL to configure your libSQL client SDK for local development: http://127.0.0.1:8081 By default, no auth token is required when sqld is running locally. If you want to require authentication, use --auth-jwt-key-file to specify a file containing the JWT key. Using database file local.db.$ turso db shell http://127.0.0.1:8081 .dump PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT UNIQUE NOT NULL, email TEXT UNIQUE NOT NULL); INSERT INTO users VALUES(1,'Alice','[email protected]'); INSERT INTO users VALUES(2,'Bob','[email protected]'); INSERT INTO users VALUES(3,'Charlie','[email protected]'); COMMIT; -
Ctrl+C the dev servers started in steps 1 and 4.
-
Up arrow to restart the dev server and run
turso db -f remote.dbagain. -
Confirm data persisted in remote:
turso db shell http://127.0.0.1:8080 .dump$ turso db shell http://127.0.0.1:8080 .dump PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT UNIQUE NOT NULL, email TEXT UNIQUE NOT NULL); INSERT INTO users VALUES(1,'Alice','[email protected]'); INSERT INTO users VALUES(2,'Bob','[email protected]'); INSERT INTO users VALUES(3,'Charlie','[email protected]'); COMMIT; -
Rerun the client:
cargo run$ cargo run ... Builder (path="local.db", url="http://127.0.0.1:8080", auth_token="")... Done Syncing... Replicated { frame_no: Some(0), frames_synced: 0 } Connecting... Connection Syncing... Replicated { frame_no: Some(0), frames_synced: 0 } Create users table (if doesn't already exist)... Done Insert users... Error: SqliteFailure(1, "no such table: users")Fails and says the users table doesn't exist.
-
Check state of the local db:
$ turso dev -f local.db -p 8081 sqld listening on port 8081. Use the following URL to configure your libSQL client SDK for local development: http://127.0.0.1:8081 By default, no auth token is required when sqld is running locally. If you want to require authentication, use --auth-jwt-key-file to specify a file containing the JWT key. Using database file local.db.$ turso db shell http://127.0.0.1:8081 .dump PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; COMMIT;
DATA IS GONE!
It's in the remote... but how can the local db sync it???
rm local.db* and rerunning cargo run doesn't work...
Any ideas?
- 主要言語
- C
- スター
- 17.3k
- フォーク
- 562
- 平均マージ
- 10日 15時間
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
tursodatabase/libsql のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
tursodatabase/libsql#2320 ·
メンテナーはふだん 11 日以内に返信
-
`cloudflare` feature: hrana streams are never closed対応中かも @pcbeingused333 が 4 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
tursodatabase/libsql#2312 ·
メンテナーはふだん 11 日以内に返信
-
bottomless: finished S3 upload tasks are never reaped, so sqld memory grows by ~10 KB per WAL batch対応中かも @pavanmanishd が 25 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
tursodatabase/libsql#2298 · コメント 1 件 ·
メンテナーはふだん 11 日以内に返信
-
Rust local Row::get_value truncates embedded NUL TEXT and panics on malformed UTF-8 (0.9.30)対応中かも @Sanjays2402 が 35 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
tursodatabase/libsql#2285 ·
メンテナーはふだん 11 日以内に返信
-
libsql-ffi: broken builds under Nix on macOS対応中かも @frectonz が 85 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
tursodatabase/libsql#2275 ·
メンテナーはふだん 11 日以内に返信
tursodatabase/libsql の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
JulianKemmerer/PipelineC#395 ·
-
upstream-blocked
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
libretro/parallel-n64#858 ·