mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-17 08:34:19 +01:00
adjust cacheflush calls outside of pager
This commit is contained in:
@@ -333,7 +333,11 @@ impl Connection {
|
|||||||
.inner
|
.inner
|
||||||
.lock()
|
.lock()
|
||||||
.map_err(|e| Error::MutexError(e.to_string()))?;
|
.map_err(|e| Error::MutexError(e.to_string()))?;
|
||||||
let _res = conn.cacheflush()?;
|
let completions = conn.cacheflush()?;
|
||||||
|
let pager = conn.get_pager();
|
||||||
|
for c in completions {
|
||||||
|
pager.io.wait_for_completion(c)?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1380,7 +1380,7 @@ impl Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Flush dirty pages to disk.
|
/// Flush dirty pages to disk.
|
||||||
pub fn cacheflush(&self) -> Result<IOResult<()>> {
|
pub fn cacheflush(&self) -> Result<Vec<Completion>> {
|
||||||
if self.closed.get() {
|
if self.closed.get() {
|
||||||
return Err(LimboError::InternalError("Connection closed".to_string()));
|
return Err(LimboError::InternalError("Connection closed".to_string()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use std::path::{Path, PathBuf};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
|
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
|
||||||
use turso_core::IOExt;
|
|
||||||
use turso_core::{Connection, Database, IO};
|
use turso_core::{Connection, Database, IO};
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@@ -116,10 +115,11 @@ impl TempDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn do_flush(conn: &Arc<Connection>, tmp_db: &TempDatabase) -> anyhow::Result<()> {
|
pub(crate) fn do_flush(conn: &Arc<Connection>, tmp_db: &TempDatabase) -> anyhow::Result<()> {
|
||||||
tmp_db
|
let completions = conn.cacheflush()?;
|
||||||
.io
|
for c in completions {
|
||||||
.block(|| conn.cacheflush())
|
tmp_db.io.wait_for_completion(c)?;
|
||||||
.map_err(anyhow::Error::from)
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compare_string(a: impl AsRef<str>, b: impl AsRef<str>) {
|
pub(crate) fn compare_string(a: impl AsRef<str>, b: impl AsRef<str>) {
|
||||||
@@ -249,7 +249,9 @@ pub(crate) fn rng_from_time() -> (ChaCha8Rng, u64) {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::{sync::Arc, vec};
|
use std::{sync::Arc, vec};
|
||||||
use tempfile::{NamedTempFile, TempDir};
|
use tempfile::{NamedTempFile, TempDir};
|
||||||
use turso_core::{types::IOResult, Database, StepResult, IO};
|
use turso_core::{Database, StepResult, IO};
|
||||||
|
|
||||||
|
use crate::common::do_flush;
|
||||||
|
|
||||||
use super::{limbo_exec_rows, limbo_exec_rows_error, TempDatabase};
|
use super::{limbo_exec_rows, limbo_exec_rows_error, TempDatabase};
|
||||||
use rusqlite::types::Value;
|
use rusqlite::types::Value;
|
||||||
@@ -411,9 +413,7 @@ mod tests {
|
|||||||
// Begin transaction on first connection and insert a value
|
// Begin transaction on first connection and insert a value
|
||||||
let _ = limbo_exec_rows(&db, &conn1, "BEGIN");
|
let _ = limbo_exec_rows(&db, &conn1, "BEGIN");
|
||||||
let _ = limbo_exec_rows(&db, &conn1, "INSERT INTO t VALUES (42)");
|
let _ = limbo_exec_rows(&db, &conn1, "INSERT INTO t VALUES (42)");
|
||||||
while matches!(conn1.cacheflush().unwrap(), IOResult::IO) {
|
do_flush(&conn1, &db)?;
|
||||||
db.io.run_once().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Second connection should not see uncommitted changes
|
// Second connection should not see uncommitted changes
|
||||||
let conn2 = db.connect_limbo();
|
let conn2 = db.connect_limbo();
|
||||||
@@ -480,9 +480,7 @@ mod tests {
|
|||||||
// Begin transaction on first connection and insert a value
|
// Begin transaction on first connection and insert a value
|
||||||
let _ = limbo_exec_rows(&db, &conn, "BEGIN");
|
let _ = limbo_exec_rows(&db, &conn, "BEGIN");
|
||||||
let _ = limbo_exec_rows(&db, &conn, "INSERT INTO t VALUES (42)");
|
let _ = limbo_exec_rows(&db, &conn, "INSERT INTO t VALUES (42)");
|
||||||
while matches!(conn.cacheflush().unwrap(), IOResult::IO) {
|
do_flush(&conn, &db)?;
|
||||||
db.io.run_once().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rollback the transaction
|
// Rollback the transaction
|
||||||
let _ = limbo_exec_rows(&db, &conn, "ROLLBACK");
|
let _ = limbo_exec_rows(&db, &conn, "ROLLBACK");
|
||||||
@@ -524,9 +522,7 @@ mod tests {
|
|||||||
let _ = limbo_exec_rows(&db, &conn, "INSERT INTO t VALUES (42)");
|
let _ = limbo_exec_rows(&db, &conn, "INSERT INTO t VALUES (42)");
|
||||||
|
|
||||||
// Flush to WAL but don't commit
|
// Flush to WAL but don't commit
|
||||||
while matches!(conn.cacheflush().unwrap(), IOResult::IO) {
|
do_flush(&conn, &db)?;
|
||||||
db.io.run_once().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reopen the database without committing
|
// Reopen the database without committing
|
||||||
let db = TempDatabase::new_with_existent(&path, true);
|
let db = TempDatabase::new_with_existent(&path, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user