Skip to content

Commit

Permalink
next iteration impl reader
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillKurdyukov committed Dec 26, 2024
1 parent 087c2b2 commit 3c503b8
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 120 deletions.
85 changes: 85 additions & 0 deletions src/Ydb.Sdk/src/Services/Topic/Reader/InternalMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System.Collections.Immutable;
using Google.Protobuf;
using Google.Protobuf.Collections;
using Google.Protobuf.WellKnownTypes;
using Ydb.Topic;

namespace Ydb.Sdk.Services.Topic.Reader;

internal class InternalMessage
{
public InternalMessage(
ByteString data,
string topic,
long partitionId,
string producerId,
OffsetsRange offsetsRange,
Timestamp createdAt,
RepeatedField<MetadataItem> metadataItems,
int dataSize)
{
Data = data;
Topic = topic;
PartitionId = partitionId;
ProducerId = producerId;
OffsetsRange = offsetsRange;
CreatedAt = createdAt;
MetadataItems = metadataItems;
DataSize = dataSize;
}

private ByteString Data { get; }

private string Topic { get; }

private long PartitionId { get; }

private string ProducerId { get; }

private OffsetsRange OffsetsRange { get; }

private Timestamp CreatedAt { get; }

private RepeatedField<MetadataItem> MetadataItems { get; }

private int DataSize { get; }

Check warning on line 45 in src/Ydb.Sdk/src/Services/Topic/Reader/InternalMessage.cs

View workflow job for this annotation

GitHub Actions / Inspection (./src/YdbSdk.sln)

"[UnusedAutoPropertyAccessor.Local] Auto-property accessor 'DataSize.get' is never used" on /home/runner/work/ydb-dotnet-sdk/ydb-dotnet-sdk/src/Ydb.Sdk/src/Services/Topic/Reader/InternalMessage.cs(45,1089)

internal Message<TValue> ToPublicMessage<TValue>(IDeserializer<TValue> deserializer, ReaderSession readerSession)
{
return new Message<TValue>(
data: deserializer.Deserialize(Data.ToByteArray()),
topic: Topic,
partitionId: PartitionId,
producerId: ProducerId,
createdAt: CreatedAt.ToDateTime(),
metadata: MetadataItems.Select(item => new Metadata(item.Key, item.Value.ToByteArray())).ToImmutableArray(),
offsetsRange: OffsetsRange,
readerSession: readerSession
);
}
}

internal class InternalBatchMessage
{
public InternalBatchMessage(
OffsetsRange batchOffsetsRange,
Queue<InternalMessage> internalMessages,
ReaderSession readerSession)
{
BatchOffsetsRange = batchOffsetsRange;
InternalMessages = internalMessages;
ReaderSession = readerSession;
}

internal OffsetsRange BatchOffsetsRange { get; }

internal Queue<InternalMessage> InternalMessages { get; }

internal ReaderSession ReaderSession { get; }
}

internal record CommitSending(
OffsetsRange OffsetsRange,
long PartitionSessionId,
TaskCompletionSource<TopicPartitionOffset> TcsTopicPartitionOffset
);
17 changes: 15 additions & 2 deletions src/Ydb.Sdk/src/Services/Topic/Reader/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal Message(

public Task CommitAsync()
{
return _readerSession.CommitOffsetRange(_offsetsRange);
return _readerSession.CommitOffsetRange(_offsetsRange, PartitionId);
}
}

Expand All @@ -76,6 +76,19 @@ public Task CommitBatchAsync()

var offsetsRange = new OffsetsRange { Start = Batch.First().Start, End = Batch.Last().End };

return _readerSession.CommitOffsetRange(offsetsRange);
return _readerSession.CommitOffsetRange(offsetsRange, Batch.First().PartitionId);
}
}

public class TopicPartitionOffset
{
public TopicPartitionOffset(long offset, long partitionId)
{
Offset = offset;
PartitionId = partitionId;
}

public long Offset { get; }

public long PartitionId { get; }
}
Loading

0 comments on commit 3c503b8

Please sign in to comment.