Skip to content

Commit

Permalink
Remove the single db connection limit (some tests failing)
Browse files Browse the repository at this point in the history
Temporary use a fork of sqlx until the necessary changes (launchbadge/sqlx#1658) are merged upstream.
  • Loading branch information
madadam committed Feb 1, 2022
1 parent 434a659 commit 23ab954
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

members = ["bindgen", "cli", "lib"]

[patch.crates-io]
sqlx = { git = "https://github.com/madadam/sqlx/", branch = "sqlite-unlock-notify" }
7 changes: 0 additions & 7 deletions lib/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@ pub(crate) async fn open_or_create(store: &Store) -> Result<Pool> {

async fn create_pool(options: SqliteConnectOptions) -> Result<Pool> {
PoolOptions::new()
// HACK: Using only one connection turns the pool effectively into a mutex over a single
// connection. This is a heavy-handed fix that prevents the "table is locked" errors that
// sometimes happen when multiple tasks try to access the same table and at least one of
// them mutably. The downside is that this means only one task can access the database at
// any given time which might affect performance.
// TODO: find a more fine-grained way to solve this issue.
.max_connections(1)
.connect_with(options)
.await
.map_err(Error::ConnectToDb)
Expand Down
6 changes: 2 additions & 4 deletions lib/src/index/branch_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,8 @@ impl BranchData {

/// Retrieve `BlockId` of a block with the given encoded `Locator`.
pub async fn get(&self, conn: &mut db::Connection, encoded_locator: &Hash) -> Result<BlockId> {
let root_node = self.root_node.read().await;
let path = self
.get_path(conn, &root_node.proof.hash, encoded_locator)
.await?;
let root_hash = self.root_node.read().await.proof.hash;
let path = self.get_path(conn, &root_hash, encoded_locator).await?;

match path.get_leaf() {
Some(block_id) => Ok(block_id),
Expand Down
18 changes: 10 additions & 8 deletions lib/src/repository/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,20 @@ async fn concurrent_write_and_read_file() {

async move {
loop {
let file = match repo.open_file("test.txt").await {
Ok(file) => file,
Err(Error::EntryNotFound) => {
sleep(Duration::from_millis(10)).await;
continue;
match repo.open_file("test.txt").await {
Ok(file) => {
let actual_len = file.len().await;
let expected_len = (chunk_count * chunk_size) as u64;

if actual_len == expected_len {
break;
}
}
Err(Error::EntryNotFound) => (),
Err(error) => panic!("unexpected error: {:?}", error),
};

if file.len().await == (chunk_count * chunk_size) as u64 {
break;
}
sleep(Duration::from_millis(10)).await;
}
}
});
Expand Down

0 comments on commit 23ab954

Please sign in to comment.