Part 2: Make partition
include an allow_excision
flag.
This is leading up to the implementation of https://github.com/mozilla/mentat/issues/21.
This commit is contained in:
parent
c0ddc2ca70
commit
82610f17f8
3 changed files with 15 additions and 13 deletions
|
@ -85,10 +85,10 @@ lazy_static! {
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
pub static ref V1_PARTS: [(symbols::Keyword, i64, i64, i64); 3] = {
|
pub static ref V1_PARTS: [(symbols::Keyword, i64, i64, i64, bool); 3] = {
|
||||||
[(ns_keyword!("db.part", "db"), 0, USER0 - 1, (1 + V1_IDENTS.len()) as i64),
|
[(ns_keyword!("db.part", "db"), 0, USER0 - 1, (1 + V1_IDENTS.len()) as i64, false),
|
||||||
(ns_keyword!("db.part", "user"), USER0, TX0 - 1, USER0),
|
(ns_keyword!("db.part", "user"), USER0, TX0 - 1, USER0, true),
|
||||||
(ns_keyword!("db.part", "tx"), TX0, i64::max_value(), TX0),
|
(ns_keyword!("db.part", "tx"), TX0, i64::max_value(), TX0, false),
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ fn symbolic_schema_to_assertions(symbolic_schema: &Value) -> Result<Vec<Value>>
|
||||||
|
|
||||||
pub(crate) fn bootstrap_partition_map() -> PartitionMap {
|
pub(crate) fn bootstrap_partition_map() -> PartitionMap {
|
||||||
V1_PARTS.iter()
|
V1_PARTS.iter()
|
||||||
.map(|&(ref part, start, end, index)| (part.to_string(), Partition::new(start, end, index)))
|
.map(|&(ref part, start, end, index, allow_excision)| (part.to_string(), Partition::new(start, end, index, allow_excision)))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
db/src/db.rs
10
db/src/db.rs
|
@ -247,7 +247,7 @@ lazy_static! {
|
||||||
r#"CREATE TABLE schema (e INTEGER NOT NULL, a SMALLINT NOT NULL, v BLOB NOT NULL, value_type_tag SMALLINT NOT NULL)"#,
|
r#"CREATE TABLE schema (e INTEGER NOT NULL, a SMALLINT NOT NULL, v BLOB NOT NULL, value_type_tag SMALLINT NOT NULL)"#,
|
||||||
r#"CREATE INDEX idx_schema_unique ON schema (e, a, v, value_type_tag)"#,
|
r#"CREATE INDEX idx_schema_unique ON schema (e, a, v, value_type_tag)"#,
|
||||||
// TODO: store entid instead of ident for partition name.
|
// TODO: store entid instead of ident for partition name.
|
||||||
r#"CREATE TABLE parts (part TEXT NOT NULL PRIMARY KEY, start INTEGER NOT NULL, end INTEGER NOT NULL, idx INTEGER NOT NULL)"#,
|
r#"CREATE TABLE parts (part TEXT NOT NULL PRIMARY KEY, start INTEGER NOT NULL, end INTEGER NOT NULL, idx INTEGER NOT NULL, allow_excision SMALLINT NOT NULL)"#,
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -299,7 +299,7 @@ pub fn create_current_version(conn: &mut rusqlite::Connection) -> Result<DB> {
|
||||||
// This is necessary: `transact` will only UPDATE parts, not INSERT them if they're missing.
|
// This is necessary: `transact` will only UPDATE parts, not INSERT them if they're missing.
|
||||||
for (part, partition) in db.partition_map.iter() {
|
for (part, partition) in db.partition_map.iter() {
|
||||||
// TODO: Convert "keyword" part to SQL using Value conversion.
|
// TODO: Convert "keyword" part to SQL using Value conversion.
|
||||||
tx.execute("INSERT INTO parts (part, start, end, idx) VALUES (?, ?, ?, ?)", &[part, &partition.start, &partition.end, &partition.index])?;
|
tx.execute("INSERT INTO parts (part, start, end, idx, allow_excision) VALUES (?, ?, ?, ?, ?)", &[part, &partition.start, &partition.end, &partition.index, &partition.allow_excision])?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: return to transact_internal to self-manage the encompassing SQLite transaction.
|
// TODO: return to transact_internal to self-manage the encompassing SQLite transaction.
|
||||||
|
@ -441,9 +441,9 @@ fn read_materialized_view(conn: &rusqlite::Connection, table: &str) -> Result<Ve
|
||||||
|
|
||||||
/// Read the partition map materialized view from the given SQL store.
|
/// Read the partition map materialized view from the given SQL store.
|
||||||
fn read_partition_map(conn: &rusqlite::Connection) -> Result<PartitionMap> {
|
fn read_partition_map(conn: &rusqlite::Connection) -> Result<PartitionMap> {
|
||||||
let mut stmt: rusqlite::Statement = conn.prepare("SELECT part, start, end, idx FROM parts")?;
|
let mut stmt: rusqlite::Statement = conn.prepare("SELECT part, start, end, idx, allow_excision FROM parts")?;
|
||||||
let m = stmt.query_and_then(&[], |row| -> Result<(String, Partition)> {
|
let m = stmt.query_and_then(&[], |row| -> Result<(String, Partition)> {
|
||||||
Ok((row.get_checked(0)?, Partition::new(row.get_checked(1)?, row.get_checked(2)?, row.get_checked(3)?)))
|
Ok((row.get_checked(0)?, Partition::new(row.get_checked(1)?, row.get_checked(2)?, row.get_checked(3)?, row.get_checked(4)?)))
|
||||||
})?.collect();
|
})?.collect();
|
||||||
m
|
m
|
||||||
}
|
}
|
||||||
|
@ -1280,7 +1280,7 @@ mod tests {
|
||||||
// Add a fake partition to allow tests to do things like
|
// Add a fake partition to allow tests to do things like
|
||||||
// [:db/add 111 :foo/bar 222]
|
// [:db/add 111 :foo/bar 222]
|
||||||
{
|
{
|
||||||
let fake_partition = Partition { start: 100, end: 2000, index: 1000 };
|
let fake_partition = Partition { start: 100, end: 2000, index: 1000, allow_excision: true };
|
||||||
parts.insert(":db.part/fake".into(), fake_partition);
|
parts.insert(":db.part/fake".into(), fake_partition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,12 +45,14 @@ pub struct Partition {
|
||||||
pub end: i64,
|
pub end: i64,
|
||||||
/// The next entid to be allocated in the partition.
|
/// The next entid to be allocated in the partition.
|
||||||
pub index: i64,
|
pub index: i64,
|
||||||
|
/// `true` if entids in the partition can be excised with `:db/excise`.
|
||||||
|
pub allow_excision: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Partition {
|
impl Partition {
|
||||||
pub fn new(start: i64, end: i64, next: i64) -> Partition {
|
pub fn new(start: i64, end: i64, index: i64, allow_excision: bool) -> Partition {
|
||||||
assert!(start <= next, "A partition represents a monotonic increasing sequence of entids.");
|
assert!(start <= index, "A partition represents a monotonic increasing sequence of entids.");
|
||||||
Partition { start: start, end: end, index: next }
|
Partition { start, end, index, allow_excision }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn contains_entid(&self, e: i64) -> bool {
|
pub fn contains_entid(&self, e: i64) -> bool {
|
||||||
|
|
Loading…
Reference in a new issue