mirror of
https://github.com/tursodatabase/libsql.git
synced 2025-05-20 06:48:19 +00:00
This PR adds a new internal metadata store for namespace configuration. This internally uses a normal namespace so that the replica also get's synchronized. This is just initial work there are a few more issues to solve regarding replica's getting updated configs and some internal hardening that needs to be done. Tracking issue for follow up work #768. Closes #501
89 lines
2.2 KiB
Rust
89 lines
2.2 KiB
Rust
use libsql::Database;
|
|
use serde_json::json;
|
|
use tempfile::tempdir;
|
|
use turmoil::Builder;
|
|
|
|
use crate::common::{http::Client, net::TurmoilConnector};
|
|
|
|
use super::make_primary;
|
|
|
|
#[test]
|
|
fn meta_store() {
|
|
let mut sim = Builder::new().build();
|
|
let tmp = tempdir().unwrap();
|
|
make_primary(&mut sim, tmp.path().to_path_buf());
|
|
|
|
sim.client("client", async {
|
|
let client = Client::new();
|
|
|
|
// STEP 1: create namespace and check that it can be read from
|
|
client
|
|
.post(
|
|
"http://primary:9090/v1/namespaces/foo/create",
|
|
json!({
|
|
"max_db_size": "5mb"
|
|
}),
|
|
)
|
|
.await?;
|
|
|
|
{
|
|
let foo = Database::open_remote_with_connector(
|
|
"http://foo.primary:8080",
|
|
"",
|
|
TurmoilConnector,
|
|
)?;
|
|
let foo_conn = foo.connect()?;
|
|
|
|
foo_conn.execute("select 1", ()).await.unwrap();
|
|
}
|
|
|
|
// STEP 2: update namespace config to block reads
|
|
client
|
|
.post(
|
|
"http://primary:9090/v1/namespaces/foo/config",
|
|
json!({
|
|
"block_reads": true,
|
|
"block_writes": false,
|
|
}),
|
|
)
|
|
.await?;
|
|
|
|
{
|
|
let foo = Database::open_remote_with_connector(
|
|
"http://foo.primary:8080",
|
|
"",
|
|
TurmoilConnector,
|
|
)?;
|
|
let foo_conn = foo.connect()?;
|
|
|
|
foo_conn.execute("select 1", ()).await.unwrap_err();
|
|
}
|
|
|
|
// STEP 3: update config again to un-block reads
|
|
client
|
|
.post(
|
|
"http://primary:9090/v1/namespaces/foo/config",
|
|
json!({
|
|
"block_reads": false,
|
|
"block_writes": false,
|
|
}),
|
|
)
|
|
.await?;
|
|
|
|
{
|
|
let foo = Database::open_remote_with_connector(
|
|
"http://foo.primary:8080",
|
|
"",
|
|
TurmoilConnector,
|
|
)?;
|
|
let foo_conn = foo.connect()?;
|
|
|
|
foo_conn.execute("select 1", ()).await.unwrap();
|
|
}
|
|
|
|
Ok(())
|
|
});
|
|
|
|
sim.run().unwrap();
|
|
}
|