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

Merge TDSParserStateObject.StateSnapshot #2122

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
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 @@ -646,7 +646,7 @@
<Compile Include="Microsoft\Data\SqlClient\TdsParser.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParser.RegisterEncoding.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParserHelperClasses.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObject.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObject.netcore.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObjectManaged.cs" />
</ItemGroup>
<!--This will exclude SqlTypeWorkarounds.netcore.cs from Net7 and greater versions-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3098,7 +3098,7 @@ internal void CloneCleanupAltMetaDataSetArray()
}
}

private sealed class StateSnapshot
sealed partial class StateSnapshot
{
private sealed class PLPData
{
Expand Down Expand Up @@ -3144,45 +3144,19 @@ partial void SetStackInternal(string value)
}
}

private int _rollingPend = 0;
private int _rollingPendCount = 0;

#endif
private PacketData _snapshotInBuffList;
private PacketData _sparePacket;
private NullBitmap _snapshotNullBitmapInfo;
private _SqlMetaDataSet _snapshotCleanupMetaData;
private _SqlMetaDataSetCollection _snapshotCleanupAltMetaDataSetArray;

internal byte[] _plpBuffer;
private PLPData _plpData;
private TdsParserStateObject _stateObj;

private int _snapshotInBuffCount;
private int _snapshotInBuffCurrent;
private int _snapshotInBytesUsed;
private int _snapshotInBytesPacket;

private SnapshottedStateFlags _state;
private byte _snapshotMessageStatus;

#if DEBUG
internal bool DoPend()
{
if (s_failAsyncPends || !s_forceAllPends)
{
return false;
}

if (_rollingPendCount == _rollingPend)
{
_rollingPend++;
_rollingPendCount = 0;
return true;
}

_rollingPendCount++;
return false;
}

internal void AssertCurrent()
{
Debug.Assert(_snapshotInBuffCurrent == _snapshotInBuffCount, "Should not be reading new packets when not replaying last packet");
Expand All @@ -3201,22 +3175,6 @@ internal void CheckStack(string trace)
}
}
#endif
internal void CloneNullBitmapInfo()
{
if (_stateObj._nullBitmapInfo.ReferenceEquals(_snapshotNullBitmapInfo))
{
_stateObj._nullBitmapInfo = _stateObj._nullBitmapInfo.Clone();
}
}

internal void CloneCleanupAltMetaDataSetArray()
{
if (_stateObj._cleanupAltMetaDataSetArray != null && object.ReferenceEquals(_snapshotCleanupAltMetaDataSetArray, _stateObj._cleanupAltMetaDataSetArray))
{
_stateObj._cleanupAltMetaDataSetArray = (_SqlMetaDataSetCollection)_stateObj._cleanupAltMetaDataSetArray.Clone();
}
}

internal void PushBuffer(byte[] buffer, int read)
{
#if DEBUG
Expand Down Expand Up @@ -3339,11 +3297,6 @@ internal void ResetSnapshotState()
_stateObj.AssertValidState();
}

internal void PrepareReplay()
{
ResetSnapshotState();
}

internal void Clear()
{
PacketData packet = _snapshotInBuffList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@
<Compile Include="Microsoft\Data\SqlClient\SqlUtil.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParser.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParserHelperClasses.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObject.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObject.netfx.cs" />
<Compile Include="Microsoft\Data\SqlTypes\SqlFileStream.cs" />
<Compile Include="Microsoft\Data\SqlTypes\SqlStreamChars.cs" />
<Compile Include="Microsoft\Data\SqlTypes\SqlTypeWorkarounds.netfx.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3257,26 +3257,18 @@ class PacketData
#endif
}

class StateSnapshot
sealed partial class StateSnapshot
{
private List<PacketData> _snapshotInBuffs;
private int _snapshotInBuffCurrent = 0;
private int _snapshotInBytesUsed = 0;
private int _snapshotInBytesPacket = 0;

private bool _snapshotPendingData = false;
private bool _snapshotErrorTokenReceived = false;
private bool _snapshotHasOpenResult = false;
private bool _snapshotReceivedColumnMetadata = false;
private bool _snapshotAttentionReceived;
private byte _snapshotMessageStatus;

private NullBitmap _snapshotNullBitmapInfo;
private ulong _snapshotLongLen;
private ulong _snapshotLongLenLeft;
private _SqlMetaDataSet _snapshotCleanupMetaData;
private _SqlMetaDataSetCollection _snapshotCleanupAltMetaDataSetArray;

private readonly TdsParserStateObject _stateObj;

public StateSnapshot(TdsParserStateObject state)
{
Expand All @@ -3285,27 +3277,6 @@ public StateSnapshot(TdsParserStateObject state)
}

#if DEBUG
private int _rollingPend = 0;
private int _rollingPendCount = 0;

internal bool DoPend()
{
if (s_failAsyncPends || !s_forceAllPends)
{
return false;
}

if (_rollingPendCount == _rollingPend)
{
_rollingPend++;
_rollingPendCount = 0;
return true;
}

_rollingPendCount++;
return false;
}

internal void AssertCurrent()
{
Debug.Assert(_snapshotInBuffCurrent == _snapshotInBuffs.Count, "Should not be reading new packets when not replaying last packet");
Expand All @@ -3324,21 +3295,6 @@ internal void CheckStack(StackTrace trace)
}
}
#endif
internal void CloneNullBitmapInfo()
{
if (_stateObj._nullBitmapInfo.ReferenceEquals(_snapshotNullBitmapInfo))
{
_stateObj._nullBitmapInfo = _stateObj._nullBitmapInfo.Clone();
}
}

internal void CloneCleanupAltMetaDataSetArray()
{
if (_stateObj._cleanupAltMetaDataSetArray != null && object.ReferenceEquals(_snapshotCleanupAltMetaDataSetArray, _stateObj._cleanupAltMetaDataSetArray))
{
_stateObj._cleanupAltMetaDataSetArray = (_SqlMetaDataSetCollection)_stateObj._cleanupAltMetaDataSetArray.Clone();
}
}

internal void PushBuffer(byte[] buffer, int read)
{
Expand Down Expand Up @@ -3452,11 +3408,6 @@ internal void ResetSnapshotState()

_stateObj.AssertValidState();
}

internal void PrepareReplay()
{
ResetSnapshotState();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public TimeoutState(int value)
// Out buffer variables
internal byte[] _outBuff; // internal write buffer - initialize on login
internal int _outBytesUsed = TdsEnums.HEADER_LEN; // number of bytes used in internal write buffer - initialize past header

// In buffer variables

/// <summary>
Expand Down Expand Up @@ -988,7 +988,7 @@ internal void ResetPacketCounters()
_outputPacketNumber = 1;
_outputPacketCount = 0;
}

internal bool SetPacketSize(int size)
{
if (size > TdsEnums.MAX_PACKET_SIZE)
Expand Down Expand Up @@ -1101,5 +1101,63 @@ private void DumpBuffer() {
}
}
*/

sealed partial class StateSnapshot
{
private int _snapshotInBuffCurrent;
private int _snapshotInBytesUsed;
private int _snapshotInBytesPacket;

private byte _snapshotMessageStatus;

private NullBitmap _snapshotNullBitmapInfo;
private _SqlMetaDataSet _snapshotCleanupMetaData;
private _SqlMetaDataSetCollection _snapshotCleanupAltMetaDataSetArray;

private TdsParserStateObject _stateObj;

#if DEBUG
private int _rollingPend = 0;
private int _rollingPendCount = 0;

internal bool DoPend()
{
if (s_failAsyncPends || !s_forceAllPends)
{
return false;
}

if (_rollingPendCount == _rollingPend)
{
_rollingPend++;
_rollingPendCount = 0;
return true;
}

_rollingPendCount++;
return false;
}
#endif
internal void CloneNullBitmapInfo()
{
if (_stateObj._nullBitmapInfo.ReferenceEquals(_snapshotNullBitmapInfo))
{
_stateObj._nullBitmapInfo = _stateObj._nullBitmapInfo.Clone();
}
}

internal void CloneCleanupAltMetaDataSetArray()
{
if (_stateObj._cleanupAltMetaDataSetArray != null && object.ReferenceEquals(_snapshotCleanupAltMetaDataSetArray, _stateObj._cleanupAltMetaDataSetArray))
{
_stateObj._cleanupAltMetaDataSetArray = (_SqlMetaDataSetCollection)_stateObj._cleanupAltMetaDataSetArray.Clone();
}
}

internal void PrepareReplay()
{
ResetSnapshotState();
}
}
}
}