Skip to content

Commit

Permalink
Revert buffer changes to fix issue with concurrent writes
Browse files Browse the repository at this point in the history
  • Loading branch information
rickykaare authored and aloneguid committed Oct 12, 2021
1 parent 058d409 commit 637e06e
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions src/Parquet/Data/Concrete/StringDataTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ namespace Parquet.Data.Concrete
{
class StringDataTypeHandler : BasicDataTypeHandler<string>
{
private static readonly UTF8Encoding E = new UTF8Encoding();
private static readonly Encoding E = Encoding.UTF8;
private static readonly ArrayPool<byte> _bytePool = ArrayPool<byte>.Shared;
private static readonly ArrayPool<string> _stringPool = ArrayPool<string>.Shared;

private static byte[] _encodingBuf;

public StringDataTypeHandler() : base(DataType.String, Thrift.Type.BYTE_ARRAY, Thrift.ConvertedType.UTF8)
{
Expand Down Expand Up @@ -118,26 +116,12 @@ private static void WriteOne(BinaryWriter writer, string value, bool includeLeng
else
{
//transofrm to byte array first, as we need the length of the byte buffer, not string length

int needLength = value.Length * 3;
if(_encodingBuf == null || _encodingBuf.Length < needLength)
{
if(_encodingBuf != null)
{
_bytePool.Return(_encodingBuf);
}

_encodingBuf = _bytePool.Rent(needLength);
}

// this can write directly to buffer after I kill binarystream
int bytesWritten = E.GetBytes(value, 0, value.Length, _encodingBuf, 0);

byte[] data = E.GetBytes(value);
if (includeLengthPrefix)
{
writer.Write(bytesWritten);
writer.Write(data.Length);
}
writer.Write(_encodingBuf, 0, bytesWritten);
writer.Write(data);
}
}

Expand Down

0 comments on commit 637e06e

Please sign in to comment.