/// <summary> /// Adds offsets from given committable batch to existing ones /// </summary> private ICommittableOffsetBatch UpdateWithBatch(ICommittableOffsetBatch committableOffsetBatch) { if (!(committableOffsetBatch is CommittableOffsetBatch committableOffsetBatchImpl)) { throw new ArgumentException($"Unexpected CommittableOffsetBatch, got {committableOffsetBatch.GetType().Name}, expected {nameof(CommittableOffsetBatch)}"); } var newOffsetsAndMetdata = OffsetsAndMetadata.SetItems(committableOffsetBatchImpl.OffsetsAndMetadata); var newCommitters = committableOffsetBatchImpl.Committers.Aggregate(Committers, (committers, pair) => { var groupId = pair.Key; var committer = pair.Value; if (committers.TryGetValue(groupId, out var groupCommitter)) { if (!groupCommitter.Equals(committer)) { throw new ArgumentException($"CommittableOffsetBatch {committableOffsetBatch} committer for groupId {groupId} " + $"must be same as the other with this groupId."); } return(committers); } else { return(committers.Add(groupId, committer)); } }).ToImmutableDictionary(pair => pair.Key, pair => pair.Value); return(new CommittableOffsetBatch(newOffsetsAndMetdata, newCommitters, BatchSize + committableOffsetBatchImpl.BatchSize)); }
/// <inheritdoc /> public async Task Commit(ICommittableOffsetBatch batch) { if (!(batch is CommittableOffsetBatch batchImpl)) { throw new ArgumentException($"Unknown CommittableOffsetBatch, got {batch.GetType().FullName}, but expected {nameof(CommittableOffsetBatch)}"); } await Task.WhenAll(batchImpl.OffsetsAndMetadata.GroupBy(o => o.Key.GroupId).Select(group => { if (!batchImpl.Committers.TryGetValue(group.Key, out var committer)) { throw new IllegalStateException($"Unknown committer, got groupId = {group.Key}"); } var offsets = group.Select(offset => new GroupTopicPartitionOffset(offset.Key, offset.Value.Offset)).ToImmutableList(); return(committer.Commit(offsets)); })); }
public Task Commit(ICommittableOffsetBatch batch) => Task.CompletedTask;