Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit f86954c

Browse files
committed
changes to compactor trait
1 parent c05dc09 commit f86954c

File tree

6 files changed

+30
-40
lines changed

6 files changed

+30
-40
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libsqlx-server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ uuid = { version = "1.4.0", features = ["v4", "serde"] }
4848

4949
[dev-dependencies]
5050
turmoil = "0.5.5"
51+
walkdir = "2.3.3"

libsqlx/src/database/libsql/injector/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,14 @@ impl Injector {
171171

172172
#[cfg(test)]
173173
mod test {
174-
use std::fs::File;
174+
use std::path::PathBuf;
175175

176176
use crate::database::libsql::injector::Injector;
177177
use crate::database::libsql::replication_log::logger::LogFile;
178178

179179
#[test]
180180
fn test_simple_inject_frames() {
181-
let file = File::open("assets/test/simple_wallog").unwrap();
182-
let log = LogFile::new(file).unwrap();
181+
let log = LogFile::new(PathBuf::from("assets/test/simple_wallog")).unwrap();
183182
let temp = tempfile::tempdir().unwrap();
184183

185184
let mut injector = Injector::new(temp.path(), Box::new(()), 10).unwrap();
@@ -199,8 +198,7 @@ mod test {
199198

200199
#[test]
201200
fn test_inject_frames_split_txn() {
202-
let file = File::open("assets/test/simple_wallog").unwrap();
203-
let log = LogFile::new(file).unwrap();
201+
let log = LogFile::new(PathBuf::from("assets/test/simple_wallog")).unwrap();
204202
let temp = tempfile::tempdir().unwrap();
205203

206204
// inject one frame at a time
@@ -221,8 +219,7 @@ mod test {
221219

222220
#[test]
223221
fn test_inject_partial_txn_isolated() {
224-
let file = File::open("assets/test/simple_wallog").unwrap();
225-
let log = LogFile::new(file).unwrap();
222+
let log = LogFile::new(PathBuf::from("assets/test/simple_wallog")).unwrap();
226223
let temp = tempfile::tempdir().unwrap();
227224

228225
// inject one frame at a time

libsqlx/src/database/libsql/mod.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use self::replication_log::logger::FrameNotifierCb;
1919

2020
pub use connection::LibsqlConnection;
2121
pub use replication_log::logger::{LogCompactor, LogFile};
22-
pub use replication_log::merger::SnapshotMerger;
2322

2423
mod connection;
2524
mod injector;
@@ -196,12 +195,12 @@ impl InjectableDatabase for LibsqlDatabase<ReplicaType> {
196195

197196
#[cfg(test)]
198197
mod test {
199-
use std::fs::File;
200198
use std::sync::atomic::AtomicBool;
201199
use std::sync::atomic::Ordering::Relaxed;
202200

203201
use parking_lot::Mutex;
204202
use rusqlite::types::Value;
203+
use uuid::Uuid;
205204

206205
use crate::connection::Connection;
207206
use crate::database::libsql::replication_log::logger::LogFile;
@@ -238,8 +237,7 @@ mod test {
238237
.unwrap();
239238
assert!(row.lock().is_empty());
240239

241-
let file = File::open("assets/test/simple_wallog").unwrap();
242-
let log = LogFile::new(file).unwrap();
240+
let log = LogFile::new(PathBuf::from("assets/test/simple_wallog")).unwrap();
243241
let mut injector = db.injector().unwrap();
244242
log.frames_iter().unwrap().for_each(|f| {
245243
injector.inject(f.unwrap()).unwrap();
@@ -312,14 +310,16 @@ mod test {
312310
}
313311

314312
fn compact(
315-
&self,
316-
_file: LogFile,
317-
_path: PathBuf,
318-
_size_after: u32,
313+
&mut self,
314+
_id: Uuid,
319315
) -> Result<(), Box<dyn std::error::Error + Sync + Send + 'static>> {
320316
self.0.store(true, Relaxed);
321317
Ok(())
322318
}
319+
320+
fn snapshot_dir(&self) -> PathBuf {
321+
todo!();
322+
}
323323
}
324324

325325
let temp = tempfile::tempdir().unwrap();
@@ -353,13 +353,15 @@ mod test {
353353
}
354354

355355
fn compact(
356-
&self,
357-
_file: LogFile,
358-
_path: PathBuf,
359-
_size_after: u32,
356+
&mut self,
357+
_id: Uuid,
360358
) -> Result<(), Box<dyn std::error::Error + Sync + Send + 'static>> {
361359
unreachable!()
362360
}
361+
362+
fn snapshot_dir(&self) -> PathBuf {
363+
todo!()
364+
}
363365
}
364366

365367
let temp = tempfile::tempdir().unwrap();

libsqlx/src/database/libsql/replication_log/logger.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use crate::database::frame::{Frame, FrameHeader};
2626
#[cfg(feature = "bottomless")]
2727
use crate::libsql::ffi::SQLITE_IOERR_WRITE;
2828

29-
use super::snapshot::{find_snapshot_file, SnapshotFile};
3029
use super::{FrameNo, CRC_64_GO_ISO, WAL_MAGIC, WAL_PAGE_SIZE};
3130

3231
init_static_wal_method!(REPLICATION_METHODS, ReplicationLoggerHook);
@@ -767,15 +766,18 @@ pub trait LogCompactor: Sync + Send + 'static {
767766
impl LogCompactor for () {
768767
fn compact(
769768
&mut self,
770-
log_name: String,
771-
path: PathBuf,
769+
_log_id: Uuid,
772770
) -> Result<(), Box<dyn std::error::Error + Sync + Send + 'static>> {
773771
Ok(())
774772
}
775773

776774
fn should_compact(&self, _file: &LogFile) -> bool {
777775
false
778776
}
777+
778+
fn snapshot_dir(&self) -> PathBuf {
779+
todo!()
780+
}
779781
}
780782

781783
pub type FrameNotifierCb = Box<dyn Fn(FrameNo) + Send + Sync + 'static>;
@@ -784,7 +786,6 @@ pub struct ReplicationLogger {
784786
pub generation: Generation,
785787
pub log_file: RwLock<LogFile>,
786788
compactor: Box<Mutex<dyn LogCompactor + Send>>,
787-
db_path: PathBuf,
788789
/// a notifier channel other tasks can subscribe to, and get notified when new frames become
789790
/// available.
790791
pub new_frame_notifier: FrameNotifierCb,
@@ -821,17 +822,11 @@ impl ReplicationLogger {
821822
if should_recover {
822823
Self::recover(log_file, data_path, compactor, new_frame_notifier)
823824
} else {
824-
Self::from_log_file(
825-
db_path.to_path_buf(),
826-
log_file,
827-
compactor,
828-
new_frame_notifier,
829-
)
825+
Self::from_log_file(log_file, compactor, new_frame_notifier)
830826
}
831827
}
832828

833829
fn from_log_file(
834-
db_path: PathBuf,
835830
log_file: LogFile,
836831
compactor: impl LogCompactor,
837832
new_frame_notifier: FrameNotifierCb,
@@ -843,7 +838,6 @@ impl ReplicationLogger {
843838
generation: Generation::new(generation_start_frame_no),
844839
compactor: Box::new(Mutex::new(compactor)),
845840
log_file: RwLock::new(log_file),
846-
db_path,
847841
new_frame_notifier,
848842
})
849843
}
@@ -885,7 +879,7 @@ impl ReplicationLogger {
885879

886880
assert!(data_path.pop());
887881

888-
Self::from_log_file(data_path, log_file, compactor, new_frame_notifier)
882+
Self::from_log_file(log_file, compactor, new_frame_notifier)
889883
}
890884

891885
pub fn database_id(&self) -> anyhow::Result<Uuid> {
@@ -930,10 +924,6 @@ impl ReplicationLogger {
930924
.expect("there should be at least one frame after commit"))
931925
}
932926

933-
pub fn get_snapshot_file(&self, from: FrameNo) -> anyhow::Result<Option<SnapshotFile>> {
934-
find_snapshot_file(&self.db_path, from)
935-
}
936-
937927
pub fn get_frame(&self, frame_no: FrameNo) -> Result<Frame, LogReadError> {
938928
self.log_file.read().frame(frame_no)
939929
}
@@ -1036,8 +1026,8 @@ mod test {
10361026

10371027
#[test]
10381028
fn log_file_test_rollback() {
1039-
let f = tempfile::tempfile().unwrap();
1040-
let mut log_file = LogFile::new(f).unwrap();
1029+
let f = tempfile::NamedTempFile::new().unwrap();
1030+
let mut log_file = LogFile::new(f.path().to_path_buf()).unwrap();
10411031
(0..5)
10421032
.map(|i| WalPage {
10431033
page_no: i,

libsqlx/src/database/libsql/replication_log/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crc::Crc;
22

33
pub mod logger;
4-
pub mod merger;
5-
pub mod snapshot;
4+
// pub mod merger;
65

76
pub const WAL_PAGE_SIZE: i32 = 4096;
87
pub const WAL_MAGIC: u64 = u64::from_le_bytes(*b"SQLDWAL\0");

0 commit comments

Comments
 (0)