Skip to content

Commit

Permalink
Merge TDSParserStateObject.StateSnapshot (#2122)
Browse files Browse the repository at this point in the history
* change TDSParserStateObject filenames so that they are visible and distinct in both projects
* move identical StateSnapshot members to shared stateobject file
  • Loading branch information
Wraith2 committed Aug 16, 2023
1 parent 359c4ba commit 3202a3c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,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 @@ private sealed partial class PacketData
}
}

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 @@ -662,7 +662,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 @@ internal bool SetPacketSize(int size)
}
}
*/

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();
}
}
}
}

0 comments on commit 3202a3c

Please sign in to comment.