Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ reqwest-tracing = "0.7.1"
ring = "0.17.14"
ringbuffer = "0.16.0"
rmcp = "2.2.0"
rmp = "0.8.15"
rmp-serde = "1.3.1"
rolling-file = "0.2.0"
rust-embed = "8.12.0"
Expand Down
625 changes: 516 additions & 109 deletions core/consensus/src/impls.rs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions core/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ pub trait Pipeline {

fn pop(&mut self) -> Option<Self::Entry>;

/// Drop the newest entry when it is `op`, returning it; `None` and no
/// mutation otherwise. Unwinds a push that turned out not to be durable.
fn remove_tail(&mut self, op: u64) -> Option<Self::Entry>;

fn clear(&mut self);

fn entry_by_op(&self, op: u64) -> Option<&Self::Entry>;
Expand All @@ -52,6 +56,9 @@ pub trait Pipeline {

fn len(&self) -> usize;

/// Requests parked waiting for a prepare slot (the second queue).
fn request_queue_len(&self) -> usize;

/// In-flight prepare-queue capacity. `VsrConsensus` snapshots it at
/// construction to size the loopback queue and to bound the uncommitted
/// range a new primary may rebuild after a view change.
Expand Down
12 changes: 2 additions & 10 deletions core/consensus/src/metadata_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@ where
{
// In-flight dedup: a live prepare from this client absorbs the retry.
// Pump delivers the reply at commit.
if consensus
.pipeline()
.borrow()
.has_message_from_client(client_id)
{
if consensus.pipeline_has_message_from_client(client_id) {
tracing::debug!(
client_id,
request,
Expand Down Expand Up @@ -262,11 +258,7 @@ where
P: Pipeline<Entry = PipelineEntry>,
{
// In-flight dedup.
if consensus
.pipeline()
.borrow()
.has_message_from_client(client_id)
{
if consensus.pipeline_has_message_from_client(client_id) {
tracing::debug!(client_id, "register_preflight: in-flight prepare, drop");
return false;
}
Expand Down
52 changes: 28 additions & 24 deletions core/consensus/src/plane_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,15 @@ where
return false;
}

let pipeline = consensus.pipeline().borrow();
let mut new_commit = consensus.commit_max();
while let Some(entry) = pipeline.entry_by_op(new_commit + 1) {
if !entry.ok_quorum_received {
break;
consensus.with_pipeline(|pipeline| {
while let Some(entry) = pipeline.entry_by_op(new_commit + 1) {
if !entry.ok_quorum_received {
break;
}
new_commit += 1;
}
new_commit += 1;
}
drop(pipeline);
});

if new_commit > consensus.commit_max() {
consensus.advance_commit_max(new_commit);
Expand All @@ -447,17 +447,27 @@ where
{
let commit = consensus.commit_max();
let mut drained = Vec::new();
let mut pipeline = consensus.pipeline().borrow_mut();

while let Some(head_op) = pipeline.head().map(|entry| entry.header.op) {
if head_op > commit {
break;
consensus.with_pipeline_mut(|pipeline| {
while let Some(head_op) = pipeline.head().map(|entry| entry.header.op) {
if head_op > commit {
break;
}

let entry = pipeline
.pop()
.expect("drain_committable_prefix: head exists");
drained.push(entry);
}
});

let entry = pipeline
.pop()
.expect("drain_committable_prefix: head exists");
drained.push(entry);
// Popping through the pipeline directly bypasses
// `VsrConsensus::pop_committed_prepare`, so re-establish the prepare
// timeout's ticking-iff-non-empty invariant here: an emptied pipeline
// disarms it, and a remaining head becomes the entry the timer measures,
// timed from now rather than inheriting the drained entry's elapsed ticks.
if !drained.is_empty() {
consensus.sync_prepare_timeout();
}

drained
Expand All @@ -478,10 +488,8 @@ where
P: Pipeline<Entry = PipelineEntry>,
{
let commit = consensus.commit_max();
let pipeline = consensus.pipeline().borrow();
pipeline
.head()
.map(|entry| entry.header)
consensus
.pipeline_head_header()
.filter(|header| header.op <= commit)
}

Expand Down Expand Up @@ -1971,11 +1979,7 @@ mod tests {

assert_eq!(drained_ops, vec![5, 6]);
assert_eq!(
consensus
.pipeline()
.borrow()
.head()
.map(|entry| entry.header.op),
consensus.pipeline_head_header().map(|header| header.op),
Some(7)
);
}
Expand Down
1 change: 1 addition & 0 deletions core/metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ journal = { workspace = true }
left-right = { workspace = true }
message_bus = { workspace = true }
paste = { workspace = true }
rmp = { workspace = true }
rmp-serde = { workspace = true }
serde = { workspace = true, features = ["derive"] }
server_common = { workspace = true }
Expand Down
Loading
Loading