Support sequential consistency in SQLite implementation (#64)

This is a bit tricky because the `Storage` trait is `Send + Sync`, but
an SQLite connection is neither. Since this is not intended for
large-scale use, the simple solution is just to open a new SQLite
connection for each transaction. More complex alternatives include
thread-local connection pools or a "worker thread" that owns the
connection and communicates with other threads via channels.

This also updates the InMemoryStorage implementation to be a bit more
strict about transactional integrity, which led to a number of test
changes.
This commit is contained in:
Dustin J. Mitchell 2024-11-26 16:22:35 -05:00 committed by GitHub
parent 75f384d4ec
commit 4029c03479
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 182 additions and 85 deletions

View file

@ -73,6 +73,7 @@ mod test {
let mut txn = storage.txn().unwrap();
txn.new_client(client_id, version_id).unwrap();
txn.add_version(client_id, version_id, NIL_VERSION_ID, vec![])?;
txn.commit()?;
}
let server = WebServer::new(Default::default(), None, storage);
@ -115,6 +116,7 @@ mod test {
{
let mut txn = storage.txn().unwrap();
txn.new_client(client_id, NIL_VERSION_ID).unwrap();
txn.commit().unwrap();
}
let server = WebServer::new(Default::default(), None, storage);

View file

@ -113,6 +113,7 @@ mod test {
{
let mut txn = storage.txn().unwrap();
txn.new_client(client_id, Uuid::nil()).unwrap();
txn.commit().unwrap();
}
let server = WebServer::new(Default::default(), None, storage);
@ -198,6 +199,7 @@ mod test {
{
let mut txn = storage.txn().unwrap();
txn.new_client(client_id, version_id).unwrap();
txn.commit().unwrap();
}
let server = WebServer::new(Default::default(), None, storage);

View file

@ -68,6 +68,7 @@ mod test {
txn.new_client(client_id, Uuid::new_v4()).unwrap();
txn.add_version(client_id, version_id, parent_version_id, b"abcd".to_vec())
.unwrap();
txn.commit().unwrap();
}
let server = WebServer::new(Default::default(), None, storage);
@ -131,6 +132,7 @@ mod test {
txn.new_client(client_id, Uuid::new_v4()).unwrap();
txn.add_version(client_id, test_version_id, NIL_VERSION_ID, b"vers".to_vec())
.unwrap();
txn.commit().unwrap();
}
let server = WebServer::new(Default::default(), None, storage);
let app = App::new().configure(|sc| server.config(sc));

View file

@ -50,6 +50,7 @@ mod test {
{
let mut txn = storage.txn().unwrap();
txn.new_client(client_id, Uuid::new_v4()).unwrap();
txn.commit().unwrap();
}
let server = WebServer::new(Default::default(), None, storage);
@ -86,6 +87,7 @@ mod test {
snapshot_data.clone(),
)
.unwrap();
txn.commit().unwrap();
}
let server = WebServer::new(Default::default(), None, storage);