Merge 'Adding checkpoint result' from Sonny

### What?
adding checkpoint result returning number of pages in wal and num pages
checkpointed.
Part of #696
### Context
SQLite returns in checkpoint result of calling `pragma wal_checkpoint;`
`0|3|3` while limbo returns `0|0|0`.
https://sqlite.org/pragma.html#pragma_wal_checkpoint
- 1st col: 1 (checkpoint SQLITE_BUSY) or 0 (not busy).
- 2nd col: # modified pages written to wal file
- 3rd col: # pages moved to db after checkpoint
This PR aims to add 2nd and 3rd column to the checkpoint result.
SQLite
```
sqlite3 test.db
sqlite> pragma journal_mode=wal;
wal
sqlite> pragma journal_mode;
wal
sqlite> create table t1 (id text);
sqlite> insert into t1(id) values (1),(2);
sqlite> select * from t1;
1
2
sqlite> pragma wal_checkpoint;
0|3|3
```
Limbo
```
./target/debug/limbo test.db
Limbo v0.0.13
Enter ".help" for usage hints.
limbo> pragma journal_mode;
wal
limbo> create table t1(id text);
limbo> insert into t1(id) values (1),(2);
limbo> select * from t1;
1
2
# current the 2nd and 3rd columns are hard coded in limbo to 0
limbo> pragma wal_checkpoint;
0|0|0
```

Closes #827
This commit is contained in:
Pekka Enberg 2025-02-04 18:26:24 +02:00
commit f69804969c
11 changed files with 237 additions and 48 deletions

View file

@ -13,13 +13,17 @@ pub struct TempDatabase {
#[allow(dead_code, clippy::arc_with_non_send_sync)]
impl TempDatabase {
pub fn new_empty() -> Self {
let mut path = TempDir::new().unwrap().into_path();
path.push("test.db");
let io: Arc<dyn limbo_core::IO> = Arc::new(limbo_core::PlatformIO::new().unwrap());
Self::new("test.db")
}
pub fn new(db_name: &str) -> Self {
let mut path = TempDir::new().unwrap().into_path();
path.push(db_name);
let io: Arc<dyn IO> = Arc::new(limbo_core::PlatformIO::new().unwrap());
Self { path, io }
}
pub fn new(table_sql: &str) -> Self {
pub fn new_with_rusqlite(table_sql: &str) -> Self {
let mut path = TempDir::new().unwrap().into_path();
path.push("test.db");
{
@ -47,7 +51,7 @@ impl TempDatabase {
pub(crate) fn do_flush(conn: &Rc<Connection>, tmp_db: &TempDatabase) -> anyhow::Result<()> {
loop {
match conn.cacheflush()? {
CheckpointStatus::Done => {
CheckpointStatus::Done(_) => {
break;
}
CheckpointStatus::IO => {
@ -86,8 +90,9 @@ mod tests {
#[test]
fn test_statement_columns() -> anyhow::Result<()> {
let _ = env_logger::try_init();
let tmp_db =
TempDatabase::new("create table test (foo integer, bar integer, baz integer);");
let tmp_db = TempDatabase::new_with_rusqlite(
"create table test (foo integer, bar integer, baz integer);",
);
let conn = tmp_db.connect_limbo();
let stmt = conn.prepare("select * from test;")?;