Skip to content
Draft
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
12 changes: 12 additions & 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 crates/corro-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ itertools = { workspace = true }
metrics = { workspace = true }
opentelemetry = { workspace = true }
parking_lot = { workspace = true }
probabilistic-set = { path = "../probabilistic-set" }
quinn = { workspace = true }
quinn-proto = { workspace = true }
quinn-plaintext = { workspace = true }
Expand Down
45 changes: 30 additions & 15 deletions crates/corro-agent/src/agent/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use corro_types::{
actor::{Actor, ActorId},
agent::{Agent, Bookie, SplitPool},
base::CrsqlSeq,
broadcast::{BroadcastInput, BroadcastV1, ChangeSource, ChangeV1, FocaInput},
broadcast::{BroadcastInput, BroadcastV1, BroadcastV2, ChangeSource, ChangeV1, FocaInput},
channel::CorroReceiver,
members::MemberAddedResult,
sync::generate_sync,
Expand Down Expand Up @@ -690,7 +690,7 @@ pub async fn handle_changes(
continue;
}

let src_str: &'static str = src.into();
let src_str: &'static str = (&src).into();
let recv_lag = change.ts().and_then(|ts| {
let mut our_ts = Timestamp::from(agent.clock().new_timestamp());
if ts > our_ts {
Expand All @@ -705,7 +705,10 @@ pub async fn handle_changes(
Some((our_ts.0 - ts.0).to_duration())
});

if matches!(src, ChangeSource::Broadcast) {
if matches!(
src,
ChangeSource::Broadcast | ChangeSource::BroadcastV2(_, _)
) {
counter!("corro.broadcast.recv.count", "kind" => "change").increment(1);
}

Expand Down Expand Up @@ -766,20 +769,32 @@ pub async fn handle_changes(
}
}

assert_sometimes!(
matches!(src, ChangeSource::Sync),
"Corrosion receives changes through sync"
);
if matches!(src, ChangeSource::Broadcast) && !change.is_empty() {
assert_sometimes!(true, "Corrosion rebroadcasts changes");
if let Err(_e) =
agent
.tx_bcast()
.try_send(BroadcastInput::Rebroadcast(BroadcastV1::Change(
if !change.is_empty() {
let bcast = match src.clone() {
ChangeSource::Broadcast => {
assert_sometimes!(true, "Corrosion rebroadcasts changes");
Some(BroadcastInput::Rebroadcast(BroadcastV1::Change(
change.clone(),
)))
{
debug!("broadcasts are full or done!");
}
ChangeSource::BroadcastV2(set, num_broadcasts) => {
assert_sometimes!(true, "Corrosion rebroadcasts changes");
Some(BroadcastInput::RebroadcastV2(BroadcastV2 {
change: BroadcastV1::Change(change.clone()),
set,
num_broadcasts,
}))
}
ChangeSource::Sync => {
assert_sometimes!(true, "Corrosion receives changes through sync");
None
}
};

if let Some(bcast) = bcast {
if let Err(_e) = agent.tx_bcast().try_send(bcast) {
debug!("broadcasts are full or done!");
}
}
}

Expand Down
34 changes: 28 additions & 6 deletions crates/corro-agent/src/agent/uni.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use corro_types::{
actor::ClusterId,
broadcast::{BroadcastV1, ChangeSource, ChangeV1, UniPayload, UniPayloadV1},
broadcast::{BroadcastV1, BroadcastV2, ChangeSource, ChangeV1, UniPayload, UniPayloadV1},
channel::CorroSender,
};
use metrics::counter;
Expand Down Expand Up @@ -66,16 +66,38 @@ pub fn spawn_unipayload_handler(

match payload {
UniPayload::V1 {
data:
UniPayloadV1::Broadcast(BroadcastV1::Change(
change,
)),
data: payload_data,
cluster_id: payload_cluster_id,
} => {
if cluster_id != payload_cluster_id {
continue;
}
changes.push((change, ChangeSource::Broadcast));

match payload_data {
UniPayloadV1::Broadcast(
BroadcastV1::Change(change),
) => {
changes.push((
change,
ChangeSource::Broadcast,
));
}
UniPayloadV1::BroadcastV2(
BroadcastV2 {
change: BroadcastV1::Change(change),
set,
num_broadcasts,
},
) => {
changes.push((
change,
ChangeSource::BroadcastV2(
set,
num_broadcasts,
),
));
}
}
}
}
}
Expand Down
Loading
Loading