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 common code bases for TdsParserStateObject.cs (2) #1844

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
840af41
Merging "Buffer read" methods of TdsParserStateObject (note: includes…
panoskj Mar 18, 2022
5429584
Merging of TdsParserStateObject.TryReadPlpBytes method (note: ports p…
panoskj Mar 19, 2022
d112701
Merging "Value Skip Logic" methods of TdsParserStateObject.
panoskj Mar 19, 2022
f115d59
Merging some "Network/Packet Reading & Processing" methods of TdsPars…
panoskj Mar 19, 2022
7c3dfe2
Merging of TdsParserStateObject.ReadSniSyncOverAsync method.
panoskj Mar 19, 2022
6ae1321
Merging some "Network/Packet Reading & Processing" methods of TdsPars…
panoskj Mar 19, 2022
e5af755
Merging TdsParserStateObject.ReadSni method.
panoskj Mar 19, 2022
49f7169
Merging TdsParserStateObject.IsConnectionAlive method.
panoskj Mar 19, 2022
7073564
Merging TdsParserStateObject.ValidateSNIConnection method (note: chan…
panoskj Mar 19, 2022
1ddaeec
Merging TdsParserStateObject.ReadSniError method.
panoskj Mar 19, 2022
32b2b2f
Merging of TdsParserStateObject.ProcessSniPacket method.
panoskj Mar 19, 2022
81f549e
Merging of TdsParserStateObject.ReadAsyncCallback (note: ports parts …
panoskj Mar 19, 2022
ff3d22e
Merging TdsParserStateObject.WriteAsyncCallback method.
panoskj Mar 19, 2022
567d0e6
Merging some "Network/Packet Writing & Processing" methods of TdsPars…
panoskj Mar 19, 2022
96c2e68
Merging constructor of TdsParserStateObject.
panoskj Mar 20, 2022
32b2699
Merging common type NullBitmap of TdsParserStateObject.
panoskj Mar 20, 2022
c910c06
Merging StartSession, Cancel and ResetCancelAndProcessAttention metho…
panoskj Mar 20, 2022
a720efa
Merging DecrementPendingCallbacks and incrementPendingCallbacks metho…
panoskj Mar 20, 2022
6a89090
TdsParserStateObject: Removed unnecessary "#pragma warning disable". …
panoskj Nov 23, 2022
aadf8e3
TdsParserStateObject: replaced some netfx fields with properties, to …
panoskj Nov 23, 2022
bc0ceb2
TdsParserStateObject: removed consecutive empty lines.
panoskj Nov 23, 2022
98bd515
TdsParserStateObject: Removed trailing whitespaces. Removed unnecessa…
panoskj Nov 23, 2022
2e2dab5
Merge remote-tracking branch 'remotes/origin/main' into MergeTdsParse…
panoskj Feb 23, 2023
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 @@ -3088,7 +3088,7 @@ private void WriteToServerInternalRestAsync(CancellationToken cts, TaskCompletio
{
_stateObj = _parser.GetSession(this);
_stateObj._bulkCopyOpperationInProgress = true;
_stateObj.StartSession(ObjectID);
_stateObj.StartSession(this);
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1283,14 +1283,14 @@ public override void Cancel()
TdsParserStateObject stateObj = _stateObj;
if (null != stateObj)
{
stateObj.Cancel(ObjectID);
stateObj.Cancel(this);
}
else
{
SqlDataReader reader = connection.FindLiveReader(this);
if (reader != null)
{
reader.Cancel(ObjectID);
reader.Cancel(this);
}
}
}
Expand Down Expand Up @@ -5986,7 +5986,7 @@ private void GetStateObject(TdsParser parser = null)
}

TdsParserStateObject stateObj = parser.GetSession(this);
stateObj.StartSession(ObjectID);
stateObj.StartSession(this);

_stateObj = stateObj;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,12 +797,13 @@ internal DataTable BuildSchemaTable()
return schemaTable;
}

internal void Cancel(int objectID)
internal void Cancel(SqlCommand command)
{
Debug.Assert(command == _command, "Calling command from an object that isn't this reader's command");
TdsParserStateObject stateObj = _stateObj;
if (null != stateObj)
{
stateObj.Cancel(objectID);
stateObj.Cancel(command);
}
}

Expand Down Expand Up @@ -860,7 +861,7 @@ private bool TryCleanPartialRead()
}

#if DEBUG
if (_stateObj._pendingData)
if (_stateObj.HasPendingData)
{
byte token;
if (!_stateObj.TryPeekByte(out token))
Expand Down Expand Up @@ -1067,7 +1068,7 @@ private bool TryCloseInternal(bool closeReader)
#else
{
#endif //DEBUG
if ((!_isClosed) && (parser != null) && (stateObj != null) && (stateObj._pendingData))
if ((!_isClosed) && (parser != null) && (stateObj != null) && (stateObj.HasPendingData))
{

// It is possible for this to be called during connection close on a
Expand Down Expand Up @@ -1333,7 +1334,7 @@ private bool TryConsumeMetaData()
{
// warning: Don't check the MetaData property within this function
// warning: as it will be a reentrant call
while (_parser != null && _stateObj != null && _stateObj._pendingData && !_metaDataConsumed)
while (_parser != null && _stateObj != null && _stateObj.HasPendingData && !_metaDataConsumed)
{
if (_parser.State == TdsParserState.Broken || _parser.State == TdsParserState.Closed)
{
Expand Down Expand Up @@ -3473,7 +3474,7 @@ private bool TryHasMoreResults(out bool moreResults)

Debug.Assert(null != _command, "unexpected null command from the data reader!");

while (_stateObj._pendingData)
while (_stateObj.HasPendingData)
{
byte token;
if (!_stateObj.TryPeekByte(out token))
Expand Down Expand Up @@ -3563,7 +3564,7 @@ private bool TryHasMoreRows(out bool moreRows)
moreRows = false;
return true;
}
if (_stateObj._pendingData)
if (_stateObj.HasPendingData)
{
// Consume error's, info's, done's on HasMoreRows, so user obtains error on Read.
// Previous bug where Read() would return false with error on the wire in the case
Expand Down Expand Up @@ -3620,7 +3621,7 @@ private bool TryHasMoreRows(out bool moreRows)
moreRows = false;
return false;
}
if (_stateObj._pendingData)
if (_stateObj.HasPendingData)
{
if (!_stateObj.TryPeekByte(out b))
{
Expand Down Expand Up @@ -3964,7 +3965,7 @@ private bool TryReadInternal(bool setTimeout, out bool more)
if (moreRows)
{
// read the row from the backend (unless it's an altrow were the marker is already inside the altrow ...)
while (_stateObj._pendingData)
while (_stateObj.HasPendingData)
{
if (_altRowStatus != ALTROWSTATUS.AltRow)
{
Expand Down Expand Up @@ -3996,7 +3997,7 @@ private bool TryReadInternal(bool setTimeout, out bool more)
}
}

if (!_stateObj._pendingData)
if (!_stateObj.HasPendingData)
{
if (!TryCloseInternal(false /*closeReader*/))
{
Expand All @@ -4020,7 +4021,7 @@ private bool TryReadInternal(bool setTimeout, out bool more)
{
// if we are in SingleRow mode, and we've read the first row,
// read the rest of the rows, if any
while (_stateObj._pendingData && !_sharedState._dataReady)
while (_stateObj.HasPendingData && !_sharedState._dataReady)
{
if (!_parser.TryRun(RunBehavior.ReturnImmediately, _command, this, null, _stateObj, out _sharedState._dataReady))
{
Expand Down Expand Up @@ -4061,7 +4062,7 @@ private bool TryReadInternal(bool setTimeout, out bool more)
more = false;

#if DEBUG
if ((!_sharedState._dataReady) && (_stateObj._pendingData))
if ((!_sharedState._dataReady) && (_stateObj.HasPendingData))
{
byte token;
if (!_stateObj.TryPeekByte(out token))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -910,11 +910,11 @@ override internal void ValidateConnectionForExecute(SqlCommand command)
// or if MARS is off, then a datareader exists
throw ADP.OpenReaderExists(parser.MARSOn); // MDAC 66411
}
else if (!parser.MARSOn && parser._physicalStateObj._pendingData)
else if (!parser.MARSOn && parser._physicalStateObj.HasPendingData)
{
parser.DrainData(parser._physicalStateObj);
}
Debug.Assert(!parser._physicalStateObj._pendingData, "Should not have a busy physicalStateObject at this point!");
Debug.Assert(!parser._physicalStateObj.HasPendingData, "Should not have a busy physicalStateObject at this point!");

parser.RollbackOrphanedAPITransactions();
}
Expand Down Expand Up @@ -1073,7 +1073,7 @@ private void ResetConnection()
// obtains a clone.

Debug.Assert(!HasLocalTransactionFromAPI, "Upon ResetConnection SqlInternalConnectionTds has a currently ongoing local transaction.");
Debug.Assert(!_parser._physicalStateObj._pendingData, "Upon ResetConnection SqlInternalConnectionTds has pending data.");
Debug.Assert(!_parser._physicalStateObj.HasPendingData, "Upon ResetConnection SqlInternalConnectionTds has pending data.");

if (_fResetConnection)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ internal void EnableMars()

internal TdsParserStateObject CreateSession()
{
TdsParserStateObject session = new TdsParserStateObject(this, (SNIHandle)_pMarsPhysicalConObj.Handle, true);
TdsParserStateObject session = new TdsParserStateObject(this, _pMarsPhysicalConObj, true);
SqlClientEventSource.Log.TryAdvancedTraceEvent("<sc.TdsParser.CreateSession|ADV> {0} created session {1}", ObjectID, session.ObjectID);
return session;
}
Expand All @@ -964,7 +964,7 @@ internal TdsParserStateObject GetSession(object owner)
{
session = _sessionPool.GetSession(owner);

Debug.Assert(!session._pendingData, "pending data on a pooled MARS session");
Debug.Assert(!session.HasPendingData, "pending data on a pooled MARS session");
SqlClientEventSource.Log.TryAdvancedTraceEvent("<sc.TdsParser.GetSession|ADV> {0} getting session {1} from pool", ObjectID, session.ObjectID);
}
else
Expand Down Expand Up @@ -1598,7 +1598,7 @@ internal void Deactivate(bool connectionIsDoomed)

if (!connectionIsDoomed && null != _physicalStateObj)
{
if (_physicalStateObj._pendingData)
if (_physicalStateObj.HasPendingData)
{
DrainData(_physicalStateObj);
}
Expand Down Expand Up @@ -2479,7 +2479,7 @@ internal bool TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataRead
{
if (token == TdsEnums.SQLERROR)
{
stateObj._errorTokenReceived = true; // Keep track of the fact error token was received - for Done processing.
stateObj.HasReceivedError = true; // Keep track of the fact error token was received - for Done processing.
}

SqlError error;
Expand Down Expand Up @@ -3009,18 +3009,18 @@ internal bool TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataRead
break;
}

Debug.Assert(stateObj._pendingData || !dataReady, "dataReady is set, but there is no pending data");
Debug.Assert(stateObj.HasPendingData || !dataReady, "dataReady is set, but there is no pending data");
}

// Loop while data pending & runbehavior not return immediately, OR
// if in attention case, loop while no more pending data & attention has not yet been
// received.
while ((stateObj._pendingData &&
while ((stateObj.HasPendingData &&
(RunBehavior.ReturnImmediately != (RunBehavior.ReturnImmediately & runBehavior))) ||
(!stateObj._pendingData && stateObj._attentionSent && !stateObj._attentionReceived));
(!stateObj.HasPendingData && stateObj._attentionSent && !stateObj.HasReceivedAttention));

#if DEBUG
if ((stateObj._pendingData) && (!dataReady))
if ((stateObj.HasPendingData) && (!dataReady))
{
byte token;
if (!stateObj.TryPeekByte(out token))
Expand All @@ -3031,7 +3031,7 @@ internal bool TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataRead
}
#endif

if (!stateObj._pendingData)
if (!stateObj.HasPendingData)
{
if (null != CurrentTransaction)
{
Expand All @@ -3041,7 +3041,7 @@ internal bool TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataRead

// if we recieved an attention (but this thread didn't send it) then
// we throw an Operation Cancelled error
if (stateObj._attentionReceived)
if (stateObj.HasReceivedAttention)
{
// Dev11 #344723: SqlClient stress test suspends System_Data!Tcp::ReadSync via a call to SqlDataReader::Close
// Spin until SendAttention has cleared _attentionSending, this prevents a race condition between receiving the attention ACK and setting _attentionSent
Expand All @@ -3052,7 +3052,7 @@ internal bool TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataRead
{
// Reset attention state.
stateObj._attentionSent = false;
stateObj._attentionReceived = false;
stateObj.HasReceivedAttention = false;

if (RunBehavior.Clean != (RunBehavior.Clean & runBehavior) && !stateObj.IsTimeoutStateExpired)
{
Expand Down Expand Up @@ -3518,7 +3518,7 @@ private bool TryProcessDone(SqlCommand cmd, SqlDataReader reader, ref RunBehavio
{
Debug.Assert(TdsEnums.DONE_MORE != (status & TdsEnums.DONE_MORE), "Not expecting DONE_MORE when receiving DONE_ATTN");
Debug.Assert(stateObj._attentionSent, "Received attention done without sending one!");
stateObj._attentionReceived = true;
stateObj.HasReceivedAttention = true;
Debug.Assert(stateObj._inBytesUsed == stateObj._inBytesRead && stateObj._inBytesPacket == 0, "DONE_ATTN received with more data left on wire");
}
if ((null != cmd) && (TdsEnums.DONE_COUNT == (status & TdsEnums.DONE_COUNT)))
Expand All @@ -3537,13 +3537,13 @@ private bool TryProcessDone(SqlCommand cmd, SqlDataReader reader, ref RunBehavio
}

// Skip the bogus DONE counts sent by the server
if (stateObj._receivedColMetaData || (curCmd != TdsEnums.SELECT))
if (stateObj.HasReceivedColumnMetadata || (curCmd != TdsEnums.SELECT))
{
cmd.OnStatementCompleted(count);
}
}

stateObj._receivedColMetaData = false;
stateObj.HasReceivedColumnMetadata = false;

// Surface exception for DONE_ERROR in the case we did not receive an error token
// in the stream, but an error occurred. In these cases, we throw a general server error. The
Expand All @@ -3552,7 +3552,7 @@ private bool TryProcessDone(SqlCommand cmd, SqlDataReader reader, ref RunBehavio
// the server has reached its max connection limit. Bottom line, we need to throw general
// error in the cases where we did not receive a error token along with the DONE_ERROR.
if ((TdsEnums.DONE_ERROR == (TdsEnums.DONE_ERROR & status)) && stateObj.ErrorCount == 0 &&
stateObj._errorTokenReceived == false && (RunBehavior.Clean != (RunBehavior.Clean & run)))
stateObj.HasReceivedError == false && (RunBehavior.Clean != (RunBehavior.Clean & run)))
{
stateObj.AddError(new SqlError(0, 0, TdsEnums.MIN_ERROR_CLASS, _server, SQLMessage.SevereError(), "", 0));

Expand Down Expand Up @@ -3586,17 +3586,17 @@ private bool TryProcessDone(SqlCommand cmd, SqlDataReader reader, ref RunBehavio
// stop if the DONE_MORE bit isn't set (see above for attention handling)
if (TdsEnums.DONE_MORE != (status & TdsEnums.DONE_MORE))
{
stateObj._errorTokenReceived = false;
stateObj.HasReceivedError = false;
if (stateObj._inBytesUsed >= stateObj._inBytesRead)
{
stateObj._pendingData = false;
stateObj.HasPendingData = false;
}
}

// _pendingData set by e.g. 'TdsExecuteSQLBatch'
// _hasOpenResult always set to true by 'WriteMarsHeader'
//
if (!stateObj._pendingData && stateObj._hasOpenResult)
if (!stateObj.HasPendingData && stateObj.HasOpenResult)
{
/*
Debug.Assert(!((sqlTransaction != null && _distributedTransaction != null) ||
Expand Down Expand Up @@ -5140,7 +5140,7 @@ internal void ThrowUnsupportedCollationEncountered(TdsParserStateObject stateObj
{
DrainData(stateObj);

stateObj._pendingData = false;
stateObj.HasPendingData = false;
}

ThrowExceptionAndWarning(stateObj);
Expand Down Expand Up @@ -5742,7 +5742,7 @@ private bool TryCommonProcessMetaData(TdsParserStateObject stateObj, _SqlMetaDat

// We get too many DONE COUNTs from the server, causing too meany StatementCompleted event firings.
// We only need to fire this event when we actually have a meta data stream with 0 or more rows.
stateObj._receivedColMetaData = true;
stateObj.HasReceivedColumnMetadata = true;
return true;
}

Expand Down Expand Up @@ -9340,8 +9340,8 @@ internal void TdsLogin(SqlLogin rec,
}

_physicalStateObj.WritePacket(TdsEnums.HARDFLUSH);
_physicalStateObj.ResetSecurePasswordsInfomation(); // Password information is needed only from Login process; done with writing login packet and should clear information
_physicalStateObj._pendingData = true;
_physicalStateObj.ResetSecurePasswordsInformation(); // Password information is needed only from Login process; done with writing login packet and should clear information
_physicalStateObj.HasPendingData = true;
_physicalStateObj._messageStatus = 0;

// Remvove CTAIP Provider after login record is sent.
Expand Down Expand Up @@ -9389,7 +9389,7 @@ internal void SendFedAuthToken(SqlFedAuthToken fedAuthToken)
_physicalStateObj.WriteByteArray(accessToken, accessToken.Length, 0);

_physicalStateObj.WritePacket(TdsEnums.HARDFLUSH);
_physicalStateObj._pendingData = true;
_physicalStateObj.HasPendingData = true;
_physicalStateObj._messageStatus = 0;

_connHandler._federatedAuthenticationRequested = true;
Expand Down Expand Up @@ -9701,7 +9701,7 @@ internal SqlDataReader TdsExecuteTransactionManagerRequest(

Task writeTask = stateObj.WritePacket(TdsEnums.HARDFLUSH);
Debug.Assert(writeTask == null, "Writes should not pend when writing sync");
stateObj._pendingData = true;
stateObj.HasPendingData = true;
stateObj._messageStatus = 0;

SqlDataReader dtcReader = null;
Expand Down Expand Up @@ -11223,7 +11223,7 @@ internal Task WriteBulkCopyDone(TdsParserStateObject stateObj)
WriteShort(0, stateObj);
WriteInt(0, stateObj);

stateObj._pendingData = true;
stateObj.HasPendingData = true;
stateObj._messageStatus = 0;
return stateObj.WritePacket(TdsEnums.HARDFLUSH);
}
Expand Down
Loading
Loading