Chunk connection-authorized sync batches
This commit is contained in:
@@ -192,14 +192,36 @@ public sealed class RemoteAgentHostedService(
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
var sequence = sourceChanged ? 1 : checkpoint.ConfirmedSequence + 1;
|
var sequence = sourceChanged ? 1 : checkpoint.ConfirmedSequence + 1;
|
||||||
var batch = new RemoteSyncBatch(
|
var remainingConversations = collection.Conversations.ToList();
|
||||||
remote.NodeId!, account.AccountId, Guid.NewGuid().ToString("N"), collection.SourceGeneration,
|
var remainingMessages = collection.Messages.ToList();
|
||||||
"messages", sequence, SerializeCursors(cursorStart), SerializeCursors(collection.NextCursors),
|
var cursorStartJson = SerializeCursors(cursorStart);
|
||||||
string.Empty, collection.IsComplete ? "complete" : "partial", collection.Conversations, collection.Messages);
|
var cursorEndJson = SerializeCursors(collection.NextCursors);
|
||||||
batch = batch with { PayloadHash = RemoteDataBatchAuthorization.ComputePayloadHash(batch) };
|
var allQueued = true;
|
||||||
var queued = queue.Enqueue(reporting, batch);
|
RemoteSyncBatch? lastQueuedBatch = null;
|
||||||
if (queued.Accepted && queued.Batch is not null)
|
while (remainingConversations.Count > 0 || remainingMessages.Count > 0 || lastQueuedBatch is null)
|
||||||
state.MarkCollected(queued.Batch, collection.UnavailableSources);
|
{
|
||||||
|
var conversationCount = Math.Min(remainingConversations.Count, RemoteDataProtocol.MaxBatchMessages);
|
||||||
|
var conversations = remainingConversations.Take(conversationCount).ToArray();
|
||||||
|
remainingConversations.RemoveRange(0, conversationCount);
|
||||||
|
var messageCount = Math.Min(remainingMessages.Count, RemoteDataProtocol.MaxBatchMessages - conversations.Length);
|
||||||
|
var messages = remainingMessages.Take(messageCount).ToArray();
|
||||||
|
remainingMessages.RemoveRange(0, messageCount);
|
||||||
|
var batch = new RemoteSyncBatch(
|
||||||
|
remote.NodeId!, account.AccountId, Guid.NewGuid().ToString("N"), collection.SourceGeneration,
|
||||||
|
"messages", sequence++, cursorStartJson, cursorEndJson, string.Empty,
|
||||||
|
collection.IsComplete ? "complete" : "partial", conversations, messages);
|
||||||
|
batch = batch with { PayloadHash = RemoteDataBatchAuthorization.ComputePayloadHash(batch) };
|
||||||
|
var queued = queue.Enqueue(reporting, batch);
|
||||||
|
if (!queued.Accepted || queued.Batch is null)
|
||||||
|
{
|
||||||
|
allQueued = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
lastQueuedBatch = queued.Batch;
|
||||||
|
cursorStartJson = cursorEndJson;
|
||||||
|
}
|
||||||
|
if (allQueued && lastQueuedBatch is not null)
|
||||||
|
state.MarkCollected(lastQueuedBatch, collection.UnavailableSources);
|
||||||
if (!collection.IsComplete)
|
if (!collection.IsComplete)
|
||||||
logger.LogWarning("Data sync is partial; accountId={AccountId}; unavailableSources={UnavailableSourceCount}.", account.AccountId, collection.UnavailableSources.Count);
|
logger.LogWarning("Data sync is partial; accountId={AccountId}; unavailableSources={UnavailableSourceCount}.", account.AccountId, collection.UnavailableSources.Count);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user