Skip to content

Commit 083ae33

Browse files
authored
Cleanup/Merge | Remove Reliability Section (#3164)
* REMOVE THE RELIABILITY SECTION! * Remove the reliability sections from the netcore code * Removing extra prepareconstrainedregions
1 parent 6151075 commit 083ae33

19 files changed

+1799
-3117
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDataReader.cs

Lines changed: 553 additions & 778 deletions
Large diffs are not rendered by default.

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.netcore.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,6 @@ internal struct SNIErrorDetails
2121
public Exception exception;
2222
}
2323

24-
internal struct ReliabilitySection
25-
{
26-
/// <summary>
27-
/// This is a no-op in netcore version. Only needed for merging with netfx codebase.
28-
/// </summary>
29-
[Conditional("NETFRAMEWORK")]
30-
internal static void Assert(string message)
31-
{
32-
}
33-
34-
[Conditional("NETFRAMEWORK")]
35-
internal void Start()
36-
{
37-
}
38-
39-
[Conditional("NETFRAMEWORK")]
40-
internal void Stop()
41-
{
42-
}
43-
}
44-
4524
internal static void FillGuidBytes(Guid guid, Span<byte> buffer) => guid.TryWriteBytes(buffer);
4625

4726
internal static void FillDoubleBytes(double value, Span<byte> buffer) => BinaryPrimitives.TryWriteInt64LittleEndian(buffer, BitConverter.DoubleToInt64Bits(value));

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObject.netcore.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,6 @@ internal bool ValidateSNIConnection()
298298
// This method should only be called by ReadSni! If not - it may have problems with timeouts!
299299
private void ReadSniError(TdsParserStateObject stateObj, uint error)
300300
{
301-
TdsParser.ReliabilitySection.Assert("unreliable call to ReadSniSyncError"); // you need to setup for a thread abort somewhere before you call this method
302-
303301
if (TdsEnums.SNI_WAIT_TIMEOUT == error)
304302
{
305303
Debug.Assert(_syncOverAsync, "Should never reach here with async on!");
@@ -710,8 +708,6 @@ public void WriteAsyncCallback(IntPtr key, PacketHandle packet, uint sniError)
710708
//
711709
internal void WriteSecureString(SecureString secureString)
712710
{
713-
TdsParser.ReliabilitySection.Assert("unreliable call to WriteSecureString"); // you need to setup for a thread abort somewhere before you call this method
714-
715711
Debug.Assert(_securePasswords[0] == null || _securePasswords[1] == null, "There are more than two secure passwords");
716712

717713
int index = _securePasswords[0] != null ? 1 : 0;
@@ -786,8 +782,6 @@ internal Task WaitForAccumulatedWrites()
786782
// and then the buffer is re-initialized in flush() and then the byte is put in the buffer.
787783
internal void WriteByte(byte b)
788784
{
789-
TdsParser.ReliabilitySection.Assert("unreliable call to WriteByte"); // you need to setup for a thread abort somewhere before you call this method
790-
791785
Debug.Assert(_outBytesUsed <= _outBuff.Length, "ERROR - TDSParser: _outBytesUsed > _outBuff.Length");
792786

793787
// check to make sure we haven't used the full amount of space available in the buffer, if so, flush it
@@ -823,8 +817,6 @@ private Task WriteBytes(ReadOnlySpan<byte> b, int len, int offsetBuffer, bool ca
823817
}
824818
try
825819
{
826-
TdsParser.ReliabilitySection.Assert("unreliable call to WriteByteArray"); // you need to setup for a thread abort somewhere before you call this method
827-
828820
bool async = _parser._asyncWrite; // NOTE: We are capturing this now for the assert after the Task is returned, since WritePacket will turn off async if there is an exception
829821
Debug.Assert(async || _asyncWriteCount == 0);
830822
// Do we have to send out in packet size chunks, or can we rely on netlib layer to break it up?

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,58 +2059,40 @@ private Task WriteRowSourceToServerAsync(int columnCount, CancellationToken ctok
20592059
RuntimeHelpers.PrepareConstrainedRegions();
20602060
try
20612061
{
2062-
#if DEBUG
2063-
TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection();
2064-
2065-
RuntimeHelpers.PrepareConstrainedRegions();
2066-
try
2067-
{
2068-
tdsReliabilitySection.Start();
2069-
#else // !DEBUG
2070-
{
2071-
#endif //DEBUG
2072-
bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(_connection);
2073-
WriteRowSourceToServerCommon(columnCount); //this is common in both sync and async
2074-
Task resultTask = WriteToServerInternalAsync(ctoken); // resultTask is null for sync, but Task for async.
2075-
if (resultTask != null)
2076-
{
2077-
finishedSynchronously = false;
2078-
return resultTask.ContinueWith(
2079-
static (Task task, object state) =>
2062+
bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(_connection);
2063+
WriteRowSourceToServerCommon(columnCount); //this is common in both sync and async
2064+
Task resultTask = WriteToServerInternalAsync(ctoken); // resultTask is null for sync, but Task for async.
2065+
if (resultTask != null)
2066+
{
2067+
finishedSynchronously = false;
2068+
return resultTask.ContinueWith(
2069+
static (Task task, object state) =>
2070+
{
2071+
SqlBulkCopy sqlBulkCopy = (SqlBulkCopy)state;
2072+
try
20802073
{
2081-
SqlBulkCopy sqlBulkCopy = (SqlBulkCopy)state;
2082-
try
2074+
sqlBulkCopy.AbortTransaction(); // if there is one, on success transactions will be commited
2075+
}
2076+
finally
2077+
{
2078+
sqlBulkCopy._isBulkCopyingInProgress = false;
2079+
if (sqlBulkCopy._parser != null)
20832080
{
2084-
sqlBulkCopy.AbortTransaction(); // if there is one, on success transactions will be commited
2081+
sqlBulkCopy._parser._asyncWrite = false;
20852082
}
2086-
finally
2083+
if (sqlBulkCopy._parserLock != null)
20872084
{
2088-
sqlBulkCopy._isBulkCopyingInProgress = false;
2089-
if (sqlBulkCopy._parser != null)
2090-
{
2091-
sqlBulkCopy._parser._asyncWrite = false;
2092-
}
2093-
if (sqlBulkCopy._parserLock != null)
2094-
{
2095-
sqlBulkCopy._parserLock.Release();
2096-
sqlBulkCopy._parserLock = null;
2097-
}
2085+
sqlBulkCopy._parserLock.Release();
2086+
sqlBulkCopy._parserLock = null;
20982087
}
2099-
return task;
2100-
},
2101-
state: this,
2102-
scheduler: TaskScheduler.Default
2103-
).Unwrap();
2104-
}
2105-
return null;
2106-
}
2107-
2108-
#if DEBUG
2109-
finally
2110-
{
2111-
tdsReliabilitySection.Stop();
2088+
}
2089+
return task;
2090+
},
2091+
state: this,
2092+
scheduler: TaskScheduler.Default
2093+
).Unwrap();
21122094
}
2113-
#endif //DEBUG
2095+
return null;
21142096
}
21152097
catch (System.OutOfMemoryException e)
21162098
{
@@ -2796,13 +2778,6 @@ private void CopyBatchesAsyncContinuedOnError(bool cleanupParser)
27962778
RuntimeHelpers.PrepareConstrainedRegions();
27972779
try
27982780
{
2799-
#if DEBUG
2800-
TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection();
2801-
RuntimeHelpers.PrepareConstrainedRegions();
2802-
try
2803-
{
2804-
tdsReliabilitySection.Start();
2805-
#endif //DEBUG
28062781
if ((cleanupParser) && (_parser != null) && (_stateObj != null))
28072782
{
28082783
_parser._asyncWrite = false;
@@ -2815,13 +2790,6 @@ private void CopyBatchesAsyncContinuedOnError(bool cleanupParser)
28152790
{
28162791
CleanUpStateObject();
28172792
}
2818-
#if DEBUG
2819-
}
2820-
finally
2821-
{
2822-
tdsReliabilitySection.Stop();
2823-
}
2824-
#endif //DEBUG
28252793
}
28262794
catch (OutOfMemoryException)
28272795
{

0 commit comments

Comments
 (0)