Skip to content

Commit 49e6393

Browse files
authored
Merge pull request #1829 from tursodatabase/lucio/local-offline-hyperv2
libsql: use hyper for offline writes
2 parents 240eee8 + 66622f2 commit 49e6393

File tree

6 files changed

+58
-221
lines changed

6 files changed

+58
-221
lines changed

Cargo.lock

Lines changed: 5 additions & 198 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libsql/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ fallible-iterator = { version = "0.3", optional = true }
4242

4343
libsql_replication = { version = "0.6", path = "../libsql-replication", optional = true }
4444
async-stream = { version = "0.3.5", optional = true }
45-
reqwest = { version = "0.12.9", default-features = false, features = [ "rustls-tls", "json" ], optional = true }
4645

4746
[dev-dependencies]
4847
criterion = { version = "0.5", features = ["html_reports", "async", "async_futures", "async_tokio"] }
@@ -105,7 +104,6 @@ sync = [
105104
"dep:bytes",
106105
"dep:tokio",
107106
"dep:futures",
108-
"dep:reqwest",
109107
"dep:serde_json",
110108
]
111109
hrana = [

libsql/src/database.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,8 @@ impl Database {
663663

664664
#[cfg(any(
665665
all(feature = "tls", feature = "replication"),
666-
all(feature = "tls", feature = "remote")
666+
all(feature = "tls", feature = "remote"),
667+
all(feature = "tls", feature = "sync")
667668
))]
668669
fn connector() -> Result<hyper_rustls::HttpsConnector<hyper::client::HttpConnector>> {
669670
let mut http = hyper::client::HttpConnector::new();
@@ -680,7 +681,8 @@ fn connector() -> Result<hyper_rustls::HttpsConnector<hyper::client::HttpConnect
680681

681682
#[cfg(any(
682683
all(not(feature = "tls"), feature = "replication"),
683-
all(not(feature = "tls"), feature = "remote")
684+
all(not(feature = "tls"), feature = "remote"),
685+
all(not(feature = "tls"), feature = "sync")
684686
))]
685687
fn connector() -> Result<hyper::client::HttpConnector> {
686688
panic!("The `tls` feature is disabled, you must provide your own http connector");

libsql/src/database/builder.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,17 @@ cfg_sync! {
424424

425425
let path = path.to_str().ok_or(crate::Error::InvalidUTF8Path)?.to_owned();
426426

427+
let https = super::connector()?;
428+
use tower::ServiceExt;
429+
430+
let svc = https
431+
.map_err(|e| e.into())
432+
.map_response(|s| Box::new(s) as Box<dyn crate::util::Socket>);
433+
434+
let connector = crate::util::ConnectorService::new(svc);
435+
427436
let db = crate::local::Database::open_local_with_offline_writes(
437+
connector,
428438
path,
429439
flags,
430440
url,

libsql/src/local/database.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ impl Database {
131131
#[cfg(feature = "sync")]
132132
#[doc(hidden)]
133133
pub async fn open_local_with_offline_writes(
134+
connector: crate::util::ConnectorService,
134135
db_path: impl Into<String>,
135136
flags: OpenFlags,
136137
endpoint: String,
@@ -144,6 +145,7 @@ impl Database {
144145
};
145146
let mut db = Database::open(&db_path, flags)?;
146147
db.sync_ctx = Some(tokio::sync::Mutex::new(SyncContext::new(
148+
connector,
147149
endpoint,
148150
Some(auth_token),
149151
)));
@@ -412,7 +414,7 @@ impl Database {
412414
// frames the server already knows about, we need to update the
413415
// frame number to the one returned by the server.
414416
let max_frame_no = sync_ctx
415-
.push_one_frame(frame.to_vec(), generation, frame_no)
417+
.push_one_frame(frame.freeze(), generation, frame_no)
416418
.await?;
417419

418420
if max_frame_no > frame_no {

0 commit comments

Comments
 (0)