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

Cleanup/Merge | Remove Reliability Section #3042

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,6 @@ internal struct SNIErrorDetails
public Exception exception;
}

internal struct ReliabilitySection
{
/// <summary>
/// This is a no-op in netcore version. Only needed for merging with netfx codebase.
/// </summary>
[Conditional("NETFRAMEWORK")]
internal static void Assert(string message)
{
}

[Conditional("NETFRAMEWORK")]
internal void Start()
{
}

[Conditional("NETFRAMEWORK")]
internal void Stop()
{
}
}

internal static void FillGuidBytes(Guid guid, Span<byte> buffer) => guid.TryWriteBytes(buffer);

internal static void FillDoubleBytes(double value, Span<byte> buffer) => BinaryPrimitives.TryWriteInt64LittleEndian(buffer, BitConverter.DoubleToInt64Bits(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,6 @@ internal bool ValidateSNIConnection()
// This method should only be called by ReadSni! If not - it may have problems with timeouts!
private void ReadSniError(TdsParserStateObject stateObj, uint error)
{
TdsParser.ReliabilitySection.Assert("unreliable call to ReadSniSyncError"); // you need to setup for a thread abort somewhere before you call this method

if (TdsEnums.SNI_WAIT_TIMEOUT == error)
{
Debug.Assert(_syncOverAsync, "Should never reach here with async on!");
Expand Down Expand Up @@ -753,8 +751,6 @@ public void WriteAsyncCallback(IntPtr key, PacketHandle packet, uint sniError)
//
internal void WriteSecureString(SecureString secureString)
{
TdsParser.ReliabilitySection.Assert("unreliable call to WriteSecureString"); // you need to setup for a thread abort somewhere before you call this method

Debug.Assert(_securePasswords[0] == null || _securePasswords[1] == null, "There are more than two secure passwords");

int index = _securePasswords[0] != null ? 1 : 0;
Expand Down Expand Up @@ -829,8 +825,6 @@ internal Task WaitForAccumulatedWrites()
// and then the buffer is re-initialized in flush() and then the byte is put in the buffer.
internal void WriteByte(byte b)
{
TdsParser.ReliabilitySection.Assert("unreliable call to WriteByte"); // you need to setup for a thread abort somewhere before you call this method

Debug.Assert(_outBytesUsed <= _outBuff.Length, "ERROR - TDSParser: _outBytesUsed > _outBuff.Length");

// check to make sure we haven't used the full amount of space available in the buffer, if so, flush it
Expand Down Expand Up @@ -866,8 +860,6 @@ private Task WriteBytes(ReadOnlySpan<byte> b, int len, int offsetBuffer, bool ca
}
try
{
TdsParser.ReliabilitySection.Assert("unreliable call to WriteByteArray"); // you need to setup for a thread abort somewhere before you call this method

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
Debug.Assert(async || _asyncWriteCount == 0);
// Do we have to send out in packet size chunks, or can we rely on netlib layer to break it up?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2059,58 +2059,40 @@ private Task WriteRowSourceToServerAsync(int columnCount, CancellationToken ctok
RuntimeHelpers.PrepareConstrainedRegions();
try
{
#if DEBUG
TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection();

RuntimeHelpers.PrepareConstrainedRegions();
try
{
tdsReliabilitySection.Start();
#else // !DEBUG
{
#endif //DEBUG
bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(_connection);
WriteRowSourceToServerCommon(columnCount); //this is common in both sync and async
Task resultTask = WriteToServerInternalAsync(ctoken); // resultTask is null for sync, but Task for async.
if (resultTask != null)
{
finishedSynchronously = false;
return resultTask.ContinueWith(
static (Task task, object state) =>
bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(_connection);
WriteRowSourceToServerCommon(columnCount); //this is common in both sync and async
Task resultTask = WriteToServerInternalAsync(ctoken); // resultTask is null for sync, but Task for async.
if (resultTask != null)
{
finishedSynchronously = false;
return resultTask.ContinueWith(
static (Task task, object state) =>
{
SqlBulkCopy sqlBulkCopy = (SqlBulkCopy)state;
try
{
SqlBulkCopy sqlBulkCopy = (SqlBulkCopy)state;
try
sqlBulkCopy.AbortTransaction(); // if there is one, on success transactions will be commited
}
finally
{
sqlBulkCopy._isBulkCopyingInProgress = false;
if (sqlBulkCopy._parser != null)
{
sqlBulkCopy.AbortTransaction(); // if there is one, on success transactions will be commited
sqlBulkCopy._parser._asyncWrite = false;
}
finally
if (sqlBulkCopy._parserLock != null)
{
sqlBulkCopy._isBulkCopyingInProgress = false;
if (sqlBulkCopy._parser != null)
{
sqlBulkCopy._parser._asyncWrite = false;
}
if (sqlBulkCopy._parserLock != null)
{
sqlBulkCopy._parserLock.Release();
sqlBulkCopy._parserLock = null;
}
sqlBulkCopy._parserLock.Release();
sqlBulkCopy._parserLock = null;
}
return task;
},
state: this,
scheduler: TaskScheduler.Default
).Unwrap();
}
return null;
}

#if DEBUG
finally
{
tdsReliabilitySection.Stop();
}
return task;
},
state: this,
scheduler: TaskScheduler.Default
).Unwrap();
}
#endif //DEBUG
return null;
}
catch (System.OutOfMemoryException e)
{
Expand Down Expand Up @@ -2796,13 +2778,6 @@ private void CopyBatchesAsyncContinuedOnError(bool cleanupParser)
RuntimeHelpers.PrepareConstrainedRegions();
try
{
#if DEBUG
TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection();
RuntimeHelpers.PrepareConstrainedRegions();
try
{
tdsReliabilitySection.Start();
#endif //DEBUG
if ((cleanupParser) && (_parser != null) && (_stateObj != null))
{
_parser._asyncWrite = false;
Expand All @@ -2815,13 +2790,6 @@ private void CopyBatchesAsyncContinuedOnError(bool cleanupParser)
{
CleanUpStateObject();
}
#if DEBUG
}
finally
{
tdsReliabilitySection.Stop();
}
#endif //DEBUG
}
catch (OutOfMemoryException)
{
Expand Down
Loading
Loading