mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 10:08:20 +00:00
core: Don't use Weak reference for connection database
The database object is a way to represent state that's shared across multiple connections. We don't want to release that object until all connections are closed.
This commit is contained in:
parent
9b7b2f6241
commit
dca47f62ea
1 changed files with 23 additions and 16 deletions
39
core/lib.rs
39
core/lib.rs
|
@ -23,7 +23,6 @@ use schema::Schema;
|
|||
use sqlite3_parser::ast;
|
||||
use sqlite3_parser::{ast::Cmd, lexer::sql::Parser};
|
||||
use std::cell::Cell;
|
||||
use std::sync::Weak;
|
||||
use std::sync::{Arc, OnceLock, RwLock};
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use storage::btree::btree_init_page;
|
||||
|
@ -119,27 +118,27 @@ impl Database {
|
|||
_shared_page_cache.clone(),
|
||||
buffer_pool,
|
||||
)?);
|
||||
let bootstrap_schema = Rc::new(RefCell::new(Schema::new()));
|
||||
let conn = Rc::new(Connection {
|
||||
let header = db_header;
|
||||
let schema = Rc::new(RefCell::new(Schema::new()));
|
||||
let db = Arc::new(Database {
|
||||
pager: pager.clone(),
|
||||
schema: bootstrap_schema.clone(),
|
||||
header: db_header.clone(),
|
||||
schema: schema.clone(),
|
||||
header: header.clone(),
|
||||
shared_page_cache,
|
||||
shared_wal,
|
||||
});
|
||||
let conn = Rc::new(Connection {
|
||||
pager: pager,
|
||||
schema: schema.clone(),
|
||||
header,
|
||||
transaction_state: RefCell::new(TransactionState::None),
|
||||
_db: Weak::new(),
|
||||
db: db.clone(),
|
||||
last_insert_rowid: Cell::new(0),
|
||||
});
|
||||
let mut schema = Schema::new();
|
||||
let rows = conn.query("SELECT * FROM sqlite_schema")?;
|
||||
let mut schema = schema.borrow_mut();
|
||||
parse_schema_rows(rows, &mut schema, io)?;
|
||||
let schema = Rc::new(RefCell::new(schema));
|
||||
let header = db_header;
|
||||
Ok(Arc::new(Database {
|
||||
pager,
|
||||
schema,
|
||||
header,
|
||||
_shared_page_cache,
|
||||
_shared_wal: shared_wal,
|
||||
}))
|
||||
Ok(db)
|
||||
}
|
||||
|
||||
pub fn connect(self: &Arc<Database>) -> Rc<Connection> {
|
||||
|
@ -148,7 +147,11 @@ impl Database {
|
|||
schema: self.schema.clone(),
|
||||
header: self.header.clone(),
|
||||
last_insert_rowid: Cell::new(0),
|
||||
<<<<<<< HEAD
|
||||
_db: Arc::downgrade(self),
|
||||
=======
|
||||
db: self.clone(),
|
||||
>>>>>>> 680b321 (core: Don't use Weak reference for connection database)
|
||||
transaction_state: RefCell::new(TransactionState::None),
|
||||
})
|
||||
}
|
||||
|
@ -204,10 +207,14 @@ pub fn maybe_init_database_file(file: &Rc<dyn File>, io: &Arc<dyn IO>) -> Result
|
|||
}
|
||||
|
||||
pub struct Connection {
|
||||
db: Arc<Database>,
|
||||
pager: Rc<Pager>,
|
||||
schema: Rc<RefCell<Schema>>,
|
||||
header: Rc<RefCell<DatabaseHeader>>,
|
||||
<<<<<<< HEAD
|
||||
_db: Weak<Database>, // backpointer to the database holding this connection
|
||||
=======
|
||||
>>>>>>> 680b321 (core: Don't use Weak reference for connection database)
|
||||
transaction_state: RefCell<TransactionState>,
|
||||
last_insert_rowid: Cell<u64>,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue