summaryrefslogtreecommitdiff
path: root/src/index.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.rs')
-rw-r--r--src/index.rs72
1 files changed, 6 insertions, 66 deletions
diff --git a/src/index.rs b/src/index.rs
index a3d95fc..11f3480 100644
--- a/src/index.rs
+++ b/src/index.rs
@@ -9,7 +9,7 @@ use std::path::Path;
/// A chunk index stored on the disk.
///
/// A chunk index lets the server quickly find chunks based on a
-/// string key/value pair, or whether they are generations.
+/// string key/value pair.
#[derive(Debug)]
pub struct Index {
conn: Connection,
@@ -66,11 +66,6 @@ impl Index {
sql::find_by_label(&self.conn, label)
}
- /// Find all backup generations.
- pub fn find_generations(&self) -> Result<Vec<ChunkId>, IndexError> {
- sql::find_generations(&self.conn)
- }
-
/// Find all chunks.
pub fn all_chunks(&self) -> Result<Vec<ChunkId>, IndexError> {
sql::find_chunk_ids(&self.conn)
@@ -125,36 +120,6 @@ mod test {
let ids: Vec<ChunkId> = idx.find_by_label("abc").unwrap();
assert_eq!(ids, vec![]);
}
-
- #[test]
- fn has_no_generations_initially() {
- let dir = tempdir().unwrap();
- let idx = new_index(dir.path());
- assert_eq!(idx.find_generations().unwrap(), vec![]);
- }
-
- #[test]
- fn remembers_generation() {
- let id: ChunkId = "id001".parse().unwrap();
- let sum = Checksum::sha256_from_str_unchecked("abc");
- let meta = ChunkMeta::new_generation(&sum, "timestamp");
- let dir = tempdir().unwrap();
- let mut idx = new_index(dir.path());
- idx.insert_meta(id.clone(), meta).unwrap();
- assert_eq!(idx.find_generations().unwrap(), vec![id]);
- }
-
- #[test]
- fn removes_generation() {
- let id: ChunkId = "id001".parse().unwrap();
- let sum = Checksum::sha256_from_str_unchecked("abc");
- let meta = ChunkMeta::new_generation(&sum, "timestamp");
- let dir = tempdir().unwrap();
- let mut idx = new_index(dir.path());
- idx.insert_meta(id.clone(), meta).unwrap();
- idx.remove_meta(&id).unwrap();
- assert_eq!(idx.find_generations().unwrap(), vec![]);
- }
}
mod sql {
@@ -170,14 +135,10 @@ mod sql {
let flags = OpenFlags::SQLITE_OPEN_CREATE | OpenFlags::SQLITE_OPEN_READ_WRITE;
let conn = Connection::open_with_flags(filename, flags)?;
conn.execute(
- "CREATE TABLE chunks (id TEXT PRIMARY KEY, label TEXT, generation INT, ended TEXT)",
+ "CREATE TABLE chunks (id TEXT PRIMARY KEY, label TEXT)",
params![],
)?;
conn.execute("CREATE INDEX label_idx ON chunks (label)", params![])?;
- conn.execute(
- "CREATE INDEX generation_idx ON chunks (generation)",
- params![],
- )?;
conn.pragma_update(None, "journal_mode", &"WAL")?;
Ok(conn)
}
@@ -194,11 +155,9 @@ mod sql {
pub fn insert(t: &Transaction, chunkid: &ChunkId, meta: &ChunkMeta) -> Result<(), IndexError> {
let chunkid = format!("{}", chunkid);
let label = meta.label();
- let generation = if meta.is_generation() { 1 } else { 0 };
- let ended = meta.ended();
t.execute(
- "INSERT INTO chunks (id, label, generation, ended) VALUES (?1, ?2, ?3, ?4)",
- params![chunkid, label, generation, ended],
+ "INSERT INTO chunks (id, label) VALUES (?1, ?2)",
+ params![chunkid, label],
)?;
Ok(())
}
@@ -243,21 +202,9 @@ mod sql {
Ok(ids)
}
- /// Find all generations.
- pub fn find_generations(conn: &Connection) -> Result<Vec<ChunkId>, IndexError> {
- let mut stmt = conn.prepare("SELECT id FROM chunks WHERE generation IS 1")?;
- let iter = stmt.query_map(params![], row_to_id)?;
- let mut ids = vec![];
- for x in iter {
- let x = x?;
- ids.push(x);
- }
- Ok(ids)
- }
-
/// Find ids of all chunks.
pub fn find_chunk_ids(conn: &Connection) -> Result<Vec<ChunkId>, IndexError> {
- let mut stmt = conn.prepare("SELECT id FROM chunks WHERE generation IS 0")?;
+ let mut stmt = conn.prepare("SELECT id FROM chunks")?;
let iter = stmt.query_map(params![], row_to_id)?;
let mut ids = vec![];
for x in iter {
@@ -270,14 +217,7 @@ mod sql {
fn row_to_meta(row: &Row) -> rusqlite::Result<ChunkMeta> {
let hash: String = row.get("label")?;
let sha256 = Checksum::sha256_from_str_unchecked(&hash);
- let generation: i32 = row.get("generation")?;
- let meta = if generation == 0 {
- ChunkMeta::new(&sha256)
- } else {
- let ended: String = row.get("ended")?;
- ChunkMeta::new_generation(&sha256, &ended)
- };
- Ok(meta)
+ Ok(ChunkMeta::new(&sha256))
}
fn row_to_id(row: &Row) -> rusqlite::Result<ChunkId> {