Skip to content

Commit d60aa16

Browse files
Merge pull request #133 from JakeRoggenbuck/feat-merge-tables
Feat merge tables
2 parents 8602a32 + 41d5c71 commit d60aa16

File tree

10 files changed

+921
-253
lines changed

10 files changed

+921
-253
lines changed

python/lstore/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class ReturnRecord:
66
def __init__(self, columns: List[int]):
7-
self.columns = columns[3:]
7+
self.columns = columns[4:]
88

99
def __str__(self):
1010
return f"Record({self.columns})"

src/bufferpool.rs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,50 @@
1+
use super::page::PhysicalPage;
2+
use serde::{Deserialize, Serialize};
3+
use std::fs::File;
4+
use std::io::{BufReader, BufWriter, Write};
15
use std::sync::{Arc, Mutex};
26

7+
#[derive(Deserialize, Serialize, Debug)]
38
pub struct BufferPool {
49
// The physical directory on disk that data will be written to
5-
pub physical_directory: Arc<Mutex<String>>,
10+
pub physical_directory: String,
611
}
712

813
impl BufferPool {
914
pub fn new(directory: &str) -> Self {
1015
BufferPool {
11-
physical_directory: Arc::new(Mutex::new(directory.to_string())),
16+
physical_directory: directory.to_string(),
1217
}
1318
}
1419

15-
pub fn write_page(_page_id: usize) {
16-
// Figure out if the page is in memory or saved in a file
17-
// ?? Keep track of where the physical memory should be if it needs to read it again
18-
todo!();
20+
pub fn write_page(page: Arc<Mutex<PhysicalPage>>, value: i64) {
21+
let mut m = page.lock().unwrap();
22+
m.write(value);
1923
}
2024

21-
pub fn read_page(_page_id: usize) {
22-
// Figure out if the page is in memory or saved in a file
23-
// If it's not in memory, we load it into memory (probably LRU)
25+
pub fn read_page(page: Arc<Mutex<PhysicalPage>>, offset: i64) -> Option<i64> {
26+
let m = page.lock().unwrap();
27+
return m.read(offset as usize);
28+
}
29+
30+
pub fn save_state(&self) {
31+
let hardcoded_filename = "./redoxdata/bufferpull.data";
2432

25-
// TODO: How does it know the page id? Page ID being a name for knowing where the page is
26-
todo!();
33+
let bufferpool_bytes: Vec<u8> = bincode::serialize(self).expect("Should serialize.");
34+
35+
let mut file = BufWriter::new(File::create(hardcoded_filename).expect("Should open file."));
36+
file.write_all(&bufferpool_bytes)
37+
.expect("Should serialize.");
2738
}
2839

29-
pub fn save_state(&self) {}
40+
pub fn load_state(&self, _directory: &str) -> BufferPool {
41+
let hardcoded_filename = "./redoxdata/bufferpull.data";
3042

31-
pub fn load_state(&self, directory: &str) -> BufferPool {
32-
BufferPool {
33-
physical_directory: Arc::new(Mutex::new(directory.to_string())),
34-
}
43+
let file = BufReader::new(File::open(hardcoded_filename).expect("Should open file."));
44+
45+
let bufferpool: BufferPool = bincode::deserialize_from(file).expect("Should deserialize.");
46+
47+
return bufferpool;
3548
}
3649
}
3750

@@ -48,8 +61,8 @@ mod tests {
4861
let new_b = b.load_state("/data");
4962

5063
assert_eq!(
51-
b.physical_directory.lock().unwrap().to_string(),
52-
new_b.physical_directory.lock().unwrap().to_string()
64+
b.physical_directory.to_string(),
65+
new_b.physical_directory.to_string()
5366
);
5467
}
5568

0 commit comments

Comments
 (0)