Skip to content

Commit

Permalink
reset replica when injector detects potential corruption
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinPostma committed Feb 1, 2024
1 parent 58eda02 commit 860deb3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
10 changes: 10 additions & 0 deletions libsql-replication/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ impl From<FrameBorrowed> for FrameMut {
}
}

impl From<Box<FrameBorrowed>> for FrameMut {
fn from(inner: Box<FrameBorrowed>) -> Self {
Self { inner }
}
}

impl Frame {
pub fn from_parts(header: &FrameHeader, data: &[u8]) -> Self {
FrameBorrowed::from_parts(header, data).into()
Expand Down Expand Up @@ -134,6 +140,10 @@ impl FrameBorrowed {
&self.page
}

pub fn page_mut(&mut self) -> &mut [u8] {
&mut self.page
}

pub fn header(&self) -> &FrameHeader {
&self.header
}
Expand Down
2 changes: 1 addition & 1 deletion libsql-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
http-body = "0.4"
url = { version = "2.3", features = ["serde"] }
uuid = { version = "1.3", features = ["v4", "serde"] }
zerocopy = { version = "0.7.28", features = ["derive"] }
zerocopy = { version = "0.7.28", features = ["derive", "alloc"] }

[dev-dependencies]
arbitrary = { version = "1.3.0", features = ["derive_arbitrary"] }
Expand Down
6 changes: 5 additions & 1 deletion libsql-server/src/namespace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,11 @@ impl Namespace<ReplicaDatabase> {
(reset)(ResetOp::Destroy(namespace.clone()));
Err(err)?;
}
e @ Error::Injector(_) => {
tracing::error!("potential corruption detected while replicating, reseting replica: {e}");
(reset)(ResetOp::Reset(namespace.clone()));
Err(e)?;
},
Error::Meta(err) => {
use libsql_replication::meta::Error;
match err {
Expand All @@ -917,7 +922,6 @@ impl Namespace<ReplicaDatabase> {
}
}
e @ (Error::Internal(_)
| Error::Injector(_)
| Error::Client(_)
| Error::PrimaryHandshakeTimeout
| Error::NeedSnapshot) => {
Expand Down
4 changes: 2 additions & 2 deletions libsql-server/tests/cluster/replication.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::sync::Arc;
use std::time::Duration;

Check failure on line 1 in libsql-server/tests/cluster/replication.rs

View workflow job for this annotation

GitHub Actions / Run Checks

Diff in /home/runner/work/libsql/libsql/libsql-server/tests/cluster/replication.rs
use std::sync::Arc;

use insta::assert_debug_snapshot;
use libsql::Database;
Expand All @@ -14,7 +14,7 @@ use crate::common::{
/// In this test, we first create a primary with a very small max_log_size, and then add a good
/// amount of data to it. This will cause the primary to create a bunch of snaphots a large enough
/// to prevent the replica from applying them all at once. We then start the replica, and check
/// that it replicates correctly to the primary's replicaton index.
/// that it replicates correctly to the primary's replicaton index. #[test]
#[test]
fn apply_partial_snapshot() {
let mut sim = turmoil::Builder::new()
Expand Down

0 comments on commit 860deb3

Please sign in to comment.