Skip to content

Commit

Permalink
add more tracing functionality and extra test
Browse files Browse the repository at this point in the history
  • Loading branch information
connortsui20 committed Apr 20, 2024
1 parent e1f1e84 commit f66b7d8
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/page/page_guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ impl<'a> WritePageGuard<'a> {
}

pub async fn flush(&mut self) {
debug!("Flushing {}", self.pid);

if self.guard.is_none() {
// There is nothing for us to flush
return;
Expand Down
77 changes: 76 additions & 1 deletion tests/bpm_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tracing::Level;
#[test]
#[ignore]
fn test_bpm_threads() {
let log_file = File::create("bpm_test.log").unwrap();
let log_file = File::create("test_bpm_threads.log").unwrap();

let stdout_subscriber = tracing_subscriber::fmt()
.compact()
Expand Down Expand Up @@ -101,3 +101,78 @@ fn test_bpm_threads() {
// run eviction thread
});
}

#[test]
#[ignore]
fn test_bpm_no_eviction() {
let log_file = File::create("test_bpm_no_eviction.log").unwrap();

let stdout_subscriber = tracing_subscriber::fmt()
.compact()
.with_file(true)
.with_line_number(true)
.with_thread_ids(true)
.with_target(false)
.without_time()
.with_max_level(Level::DEBUG)
.with_writer(Mutex::new(log_file))
.finish();
tracing::subscriber::set_global_default(stdout_subscriber).unwrap();

const THREADS: usize = 95;

let bpm = Arc::new(BufferPoolManager::new(128, THREADS));

// Spawn all threads
thread::scope(|s| {
for i in 0..THREADS {
let bpm_clone = bpm.clone();

s.spawn(move || {
let dmh = bpm_clone.get_disk_manager();
let uring = Rc::new(dmh.get_uring());

let uring_daemon = SendWrapper::new(uring.clone());
let rt = Arc::new(
Builder::new_current_thread()
.on_thread_park(move || {
uring_daemon
.submit()
.expect("Was unable to submit `io_uring` operations");
uring_daemon.poll();
})
.enable_all()
.build()
.unwrap(),
);

let local = LocalSet::new();
local.spawn_local(async move {
let pid = PageId::new(i as u64);
let ph = bpm_clone.get_page(&pid).await;

let mut guard = ph.write().await;

guard.deref_mut().fill(b' ' + i as u8);
guard.flush().await;

drop(guard);

loop {
tokio::task::yield_now().await;
}
});

// // Check that everyone else has finished
// local.spawn_local(async move {
// for j in 0..THREADS {

// }
// });

rt.block_on(local);
});
}
// run eviction thread
});
}

0 comments on commit f66b7d8

Please sign in to comment.