0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2024-12-15 10:59:47 +00:00
Avinash Sajjanshetty aeb9a9c538
Use max_frame_no for transaction reads and writes (#1507)
* Add basic tonic error handling

Added a simple error to handle `WriteConflict`s

* Improve the way we handle Foundation DB keys

Foundation DB keys support tuples. Earlier we used plain strings. For
example to store page 5, which had frame no 8, we did `ns/f/5/8`.
However this breaks lexicographic sorting. For e.g. we want `ns/f/5/8`
to be smaller than `ns/f/5/18`, but since we store as a plain string
the comparison breaks.

So we let FDB handle encoding with the `pack` API which encodes the
key properly as tuple `(ns, f, 5, 8)`

* Send `max_frame_no` while doing inserts and find frame

Whenever a txn is started, we keep the current `max_frame_no` in the
transaction's state. For the subsequent find and insert requests, we
send this value to storage server.

For a read txn, it should not read any frames greater than it's
max_frame_no. For a write txn, if the max_frame_no has changed
meanwhile, then txn should be aborted.

* Allow multiple writers at the storage server

This patch has two important changes:
- Storage server now uses `max_frame_no` from the txn to read frames
  It will make sure to not read any frames beyond the `max_frame_no`
  of the transaction. This fixes the bug in isolation level.
- Storage server now checks `max_frame_no` before inserting. If it
  has changed meanwhile, then it rejects the insertion request.

This lets us have multiple (non concurrent) writers or even multiple
logical primary instances.

* minor cargo fmt fixes
2024-06-28 13:38:02 +00:00

39 lines
1.1 KiB
TOML

[package]
name = "libsql-storage-server"
version = "0.0.1"
edition = "2021"
description = "libSQL Storage Server"
repository = "https://github.com/tursodatabase/libsql"
license = "MIT"
publish = false
default-run = "libsql-storage-server"
[[bin]]
name = "libsql-storage-server"
path = "src/main.rs"
[dependencies]
anyhow = "1.0.66"
bytes = "1.5.0"
clap = { version = "4.0.23", features = ["derive", "env", "string"] }
foundationdb = { version = "0.9.0", features = ["embedded-fdb-include", "fdb-7_3"], optional = true }
futures = "0.3.30"
libsql-storage = { path = "../libsql-storage" }
redis = "0.25.3"
tokio = { version = "1.22.2", features = ["rt-multi-thread", "net", "io-std", "io-util", "time", "macros", "sync", "fs", "signal"] }
tonic = { version = "0.10.0", features = ["tls"] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
async-trait = "0.1.80"
serde = "1.0.203"
thiserror = "1.0.61"
[features]
foundation-db = ["foundationdb"]
[dev-dependencies]
[build-dependencies]
vergen = { version = "8", features = ["build", "git", "gitcl"] }