Send a scope that is bigger than the push channel in bigger chunks

A sync is sent whole or not at all, so that a scope is never left half sent;
that needs the channel to have room for every frame of it. A scope with more
frames than the channel holds when it is empty (more than 16 frames of 256
entities on the smallest channel) could never be sent and stayed lagged for
ever. The chunks of such a sync are now as big as the channel needs, so every
sync fits an empty channel. A test syncs a SERVER scope of 5,000 channels over
the smallest channel.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-21 06:53:26 +03:00
1 parent 88f58ea468
commit b5ea0c3e95
3 files changed
+49 -4

No files matched your search

+41
View File
@@ -1919,3 +1919,44 @@ async fn a_consumer_that_lags_loses_the_queue_and_gets_the_scope_again() {
})
.await;
}
/// A scope that needs more frames than the channel holds is sent in bigger
/// chunks, not never: the smallest channel is 16 pushes, of 256 entities.
#[tokio::test(flavor = "multi_thread")]
async fn a_scope_bigger_than_the_channel_is_sent_in_bigger_chunks() {
use voelin_model::replica::{Replica, ScopeId};
const CHANNELS: u64 = 5_000;
let (conns, mut seen) = mpsc::unbounded_channel();
let connector = LinkConnector::new(Arc::new(Recorder(conns)), &["ts3server"]);
let (mut params, _media) = connect_params("ts3server://fake.test?port=9987");
params.credential = Credential::Foreign { kind: "teamspeak", blob: Default::default() };
params.push_capacity = 1;
let connecting = tokio::spawn(connector.connect(params));
let inner = within("the link to be asked", seen.recv()).await;
inner.events.send(connected(everything())).unwrap();
let mut big = presence();
for id in 100..100 + CHANNELS {
let channel = ChannelInfo { id, name: format!("c{id}"), ..Default::default() };
big.channels.insert(id, channel);
}
inner.events.send(LinkEvent::Presence(Box::new(big))).unwrap();
let connected = within("a session", async { connecting.await.ok().and_then(Result::ok) }).await;
let (session, mut pushes) = (connected.session, connected.pushes);
let server = ScopeId::Server(1);
session.request(subscribe(server)).await.unwrap();
let mut replica = Replica::default();
replica.subscribe(server);
within("the whole scope", async {
loop {
let push = pushes.recv().await?;
replica.apply_push(&push);
if matches!(push.body, Some(v1::push::Body::SyncEnd(_))) {
return Some(());
}
}
})
.await;
// Two of the fixture's channels, and the ones added.
assert_eq!(replica.channels(1).count() as u64, 2 + CHANNELS + 1, "with the server chat");
}
+7 -3
View File
@@ -650,18 +650,22 @@ impl Driver {
};
let mode = if delta { v1::SyncMode::Delta } else { v1::SyncMode::Full };
let proto = scope.to_proto();
// A sync has to fit the channel when it is empty, or it could never be sent:
// a scope bigger than the channel has bigger chunks.
let room = self.pushes.max_capacity().saturating_sub(2).max(1);
let chunk = SYNC_CHUNK.max(items.len().div_ceil(room));
let frame = |body| v1::Push { body: Some(body) };
let mut frames = Vec::with_capacity(items.len().div_ceil(SYNC_CHUNK) + 2);
let mut frames = Vec::with_capacity(items.len().div_ceil(chunk) + 2);
frames.push(frame(Body::SyncBegin(v1::SyncBegin {
scope: Some(proto),
mode: mode as i32,
epoch: self.epoch,
})));
for chunk in items.chunks(SYNC_CHUNK) {
for part in items.chunks(chunk) {
frames.push(frame(Body::Change(v1::Change {
scope: Some(proto),
rev: self.rev,
put: chunk.to_vec(),
put: part.to_vec(),
del: Vec::new(),
})));
}
+1 -1
View File
@@ -1027,6 +1027,6 @@ its own place above and tested.
| CHAT subscriptions were capped at 16 in process: the 15th private peer's messages were never delivered. | `LinkSession` says 65,536; SessionLink sizes its scopes from `Welcome.limits` (16 only when the host says nothing), server chat and own channel first, newest private conversations next (4.3). | `private_messages_from_more_than_16_peers_all_arrive`, the limits in `the_welcome_names_the_host_the_user_and_what_the_link_can_do` |
| `LinkSession::notify` accepted `List`, `FileRead` and `FileWrite` and ignored them. | A misplaced op is a `Protocol` error; any other op of the control stream is run (3.1). | `a_notify_needs_the_control_stream_and_is_run_as_the_request_it_is` |
| A push channel that ended during the connect syncs threw the session's close reason away. | The reason of `closed()` is the reason of `Disconnected` (4.2). | `a_session_that_ends_during_the_connect_syncs_says_why` |
| `LinkSession` awaited `pushes.send()`: a lagging consumer stalled voice and commands. | Nothing in the task waits: a push that finds the channel full is dropped, the scope is marked as lagged and sent again whole (`SyncBegin`..`SyncEnd`, all or none) when the channel has room, as `ConnectParams.push_capacity` documents. Signals have no scope: they are dropped. | `a_consumer_that_lags_loses_the_queue_and_gets_the_scope_again` |
| `LinkSession` awaited `pushes.send()`: a lagging consumer stalled voice and commands. | Nothing in the task waits: a push that finds the channel full is dropped, the scope is marked as lagged and sent again whole (`SyncBegin`..`SyncEnd`, all or none) when the channel has room, as `ConnectParams.push_capacity` documents; a scope bigger than the channel is sent in bigger chunks, so that it fits an empty channel. Signals have no scope: they are dropped. | `a_consumer_that_lags_loses_the_queue_and_gets_the_scope_again`, `a_scope_bigger_than_the_channel_is_sent_in_bigger_chunks` |
| An address no connector serves was echoed in full, with `?channelpassword=`. | The text cuts the address at `?` and `#` (4.1). | `the_text_of_an_address_nobody_serves_keeps_the_channel_password_out`, `an_address_is_shown_without_its_secrets` |
| `LinkEvent::Talking` of the inner link was ignored, and its documentation unchanged: Speex and CELT talkers were no longer shown as talking. | The docs of `Talking`, `OwnChannel` and `Connected.own_client` say what the adapter derives; the inner link's `Talking` goes on as `Signal{speaking}`, a hint that SessionLink believes until it is over (P13). | `a_talker_the_link_hears_but_does_not_forward_is_shown_as_talking`, `a_host_that_says_someone_talks_is_believed_until_it_says_otherwise` |