Skip to content

Commit b59e1ce

Browse files
committed
fix: improve buffer management in BufferV1 by resetting line start length
1 parent c20de68 commit b59e1ce

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

src/net-questdb-client-tests/TcpTests.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -560,23 +560,23 @@ public async Task CancelLine()
560560

561561
using var sender = Sender.New($"tcp::addr={_host}:{_port};");
562562

563-
sender.Table("good");
564-
sender.Symbol("asdf", "sdfad");
565-
sender.Column("ddd", 123);
566-
#pragma warning disable CS0618 // Type or member is obsolete
567-
await sender.AtNowAsync();
568-
#pragma warning restore CS0618 // Type or member is obsolete
563+
await sender
564+
.Table("good")
565+
.Symbol("asdf", "sdfad")
566+
.Column("ddd", 123)
567+
.AtAsync(DateTime.UtcNow);
568+
569+
await sender
570+
.Table("bad")
571+
.Symbol("asdf", "sdfad")
572+
.Column("asdf", 123)
573+
.AtAsync(DateTime.UtcNow);
569574

570-
sender.Table("bad");
571-
sender.Symbol("asdf", "sdfad");
572-
sender.Column("asdf", 123);
573-
#pragma warning disable CS0618 // Type or member is obsolete
574-
await sender.AtNowAsync();
575-
#pragma warning restore CS0618 // Type or member is obsolete
576575
sender.CancelRow();
577576

578-
sender.Table("good");
579-
await sender.AtAsync(new DateTime(1970, 1, 2));
577+
await sender
578+
.Table("good")
579+
.AtAsync(new DateTime(1970, 1, 2));
580580
await sender.SendAsync();
581581

582582
var expected = "good,asdf=sdfad ddd=123i\n" +

src/net-questdb-client/Buffers/BufferV1.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class BufferV1 : IBuffer
4040
private int _currentBufferIndex;
4141
private string _currentTableName = null!;
4242
private bool _hasTable;
43+
private int _lineStartLength;
4344
private int _lineStartBufferIndex;
4445
private int _lineStartBufferPosition;
4546
private bool _noFields = true;
@@ -158,6 +159,7 @@ public void Clear()
158159
Length = 0;
159160
WithinTransaction = false;
160161
_currentTableName = "";
162+
_lineStartLength = 0;
161163
_lineStartBufferIndex = 0;
162164
_lineStartBufferPosition = 0;
163165
}
@@ -182,9 +184,11 @@ public void TrimExcessBuffers()
182184
public void CancelRow()
183185
{
184186
_currentBufferIndex = _lineStartBufferIndex;
185-
Length -= Position - _lineStartBufferPosition;
187+
Chunk = _buffers[_currentBufferIndex].Buffer;
188+
Length = _lineStartLength;
186189
Position = _lineStartBufferPosition;
187190
_hasTable = false;
191+
188192
}
189193

190194
/// <inheritdoc />
@@ -264,6 +268,7 @@ public IBuffer Table(ReadOnlySpan<char> name)
264268
_quoted = false;
265269
_hasTable = true;
266270

271+
_lineStartLength = Length;
267272
_lineStartBufferIndex = _currentBufferIndex;
268273
_lineStartBufferPosition = Position;
269274

0 commit comments

Comments
 (0)