Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Add finally block to Kafka Offset Commit #2662

Merged
merged 5 commits into from
May 11, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -436,28 +436,37 @@ private void CommitOffsets()

private void CommitAllOffsets(DateTime flushTime)
{
var listOffsets = new List<TopicPartitionOffset>();
var currentOffsetsInBag = _offsetStorage.Count;
for (int i = 0; i < currentOffsetsInBag; i++)
try
{
bool hasOffsets = _offsetStorage.TryTake(out var offset);
if (hasOffsets)
listOffsets.Add(offset);
else
break;


var listOffsets = new List<TopicPartitionOffset>();
var currentOffsetsInBag = _offsetStorage.Count;
for (int i = 0; i < currentOffsetsInBag; i++)
{
bool hasOffsets = _offsetStorage.TryTake(out var offset);
if (hasOffsets)
listOffsets.Add(offset);
else
break;

}

if (s_logger.IsEnabled(LogLevel.Information))
{
var offsets = listOffsets.Select(tpo =>
$"Topic: {tpo.Topic} Partition: {tpo.Partition.Value} Offset: {tpo.Offset.Value}");
var offsetAsString = string.Join(Environment.NewLine, offsets);
s_logger.LogInformation("Sweeping offsets: {0} {Offset}", Environment.NewLine, offsetAsString);
}

_consumer.Commit(listOffsets);
_lastFlushAt = flushTime;
}

if (s_logger.IsEnabled(LogLevel.Information))
finally
{
var offsets = listOffsets.Select(tpo => $"Topic: {tpo.Topic} Partition: {tpo.Partition.Value} Offset: {tpo.Offset.Value}");
var offsetAsString = string.Join(Environment.NewLine, offsets);
s_logger.LogInformation("Sweeping offsets: {0} {Offset}", Environment.NewLine, offsetAsString);
_flushToken.Release(1);
}

_consumer.Commit(listOffsets);
_lastFlushAt = flushTime;
_flushToken.Release(1);
}

// The batch size has been exceeded, so flush our offsets
Expand Down