Skip to content

Commit 79c2f1d

Browse files
author
Benjamin Hugot
committed
I merged more methods from TdsParserStateObject after dotnet#1520 It would maybe help to start working on fix the async bug.
1 parent 6511535 commit 79c2f1d

File tree

8 files changed

+2190
-3664
lines changed

8 files changed

+2190
-3664
lines changed

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

+66-1,814
Large diffs are not rendered by default.

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ private bool TryCleanPartialRead()
860860
}
861861

862862
#if DEBUG
863-
if (_stateObj._pendingData)
863+
if (_stateObj.HasPendingData)
864864
{
865865
byte token;
866866
if (!_stateObj.TryPeekByte(out token))
@@ -1067,7 +1067,7 @@ private bool TryCloseInternal(bool closeReader)
10671067
#else
10681068
{
10691069
#endif //DEBUG
1070-
if ((!_isClosed) && (parser != null) && (stateObj != null) && (stateObj._pendingData))
1070+
if ((!_isClosed) && (parser != null) && (stateObj != null) && (stateObj.HasPendingData))
10711071
{
10721072

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

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

3476-
while (_stateObj._pendingData)
3476+
while (_stateObj.HasPendingData)
34773477
{
34783478
byte token;
34793479
if (!_stateObj.TryPeekByte(out token))
@@ -3563,7 +3563,7 @@ private bool TryHasMoreRows(out bool moreRows)
35633563
moreRows = false;
35643564
return true;
35653565
}
3566-
if (_stateObj._pendingData)
3566+
if (_stateObj.HasPendingData)
35673567
{
35683568
// Consume error's, info's, done's on HasMoreRows, so user obtains error on Read.
35693569
// Previous bug where Read() would return false with error on the wire in the case
@@ -3620,7 +3620,7 @@ private bool TryHasMoreRows(out bool moreRows)
36203620
moreRows = false;
36213621
return false;
36223622
}
3623-
if (_stateObj._pendingData)
3623+
if (_stateObj.HasPendingData)
36243624
{
36253625
if (!_stateObj.TryPeekByte(out b))
36263626
{
@@ -3964,7 +3964,7 @@ private bool TryReadInternal(bool setTimeout, out bool more)
39643964
if (moreRows)
39653965
{
39663966
// read the row from the backend (unless it's an altrow were the marker is already inside the altrow ...)
3967-
while (_stateObj._pendingData)
3967+
while (_stateObj.HasPendingData)
39683968
{
39693969
if (_altRowStatus != ALTROWSTATUS.AltRow)
39703970
{
@@ -3996,7 +3996,7 @@ private bool TryReadInternal(bool setTimeout, out bool more)
39963996
}
39973997
}
39983998

3999-
if (!_stateObj._pendingData)
3999+
if (!_stateObj.HasPendingData)
40004000
{
40014001
if (!TryCloseInternal(false /*closeReader*/))
40024002
{
@@ -4020,7 +4020,7 @@ private bool TryReadInternal(bool setTimeout, out bool more)
40204020
{
40214021
// if we are in SingleRow mode, and we've read the first row,
40224022
// read the rest of the rows, if any
4023-
while (_stateObj._pendingData && !_sharedState._dataReady)
4023+
while (_stateObj.HasPendingData && !_sharedState._dataReady)
40244024
{
40254025
if (!_parser.TryRun(RunBehavior.ReturnImmediately, _command, this, null, _stateObj, out _sharedState._dataReady))
40264026
{
@@ -4061,7 +4061,7 @@ private bool TryReadInternal(bool setTimeout, out bool more)
40614061
more = false;
40624062

40634063
#if DEBUG
4064-
if ((!_sharedState._dataReady) && (_stateObj._pendingData))
4064+
if ((!_sharedState._dataReady) && (_stateObj.HasPendingData))
40654065
{
40664066
byte token;
40674067
if (!_stateObj.TryPeekByte(out token))

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -910,11 +910,11 @@ override internal void ValidateConnectionForExecute(SqlCommand command)
910910
// or if MARS is off, then a datareader exists
911911
throw ADP.OpenReaderExists(parser.MARSOn); // MDAC 66411
912912
}
913-
else if (!parser.MARSOn && parser._physicalStateObj._pendingData)
913+
else if (!parser.MARSOn && parser._physicalStateObj.HasPendingData)
914914
{
915915
parser.DrainData(parser._physicalStateObj);
916916
}
917-
Debug.Assert(!parser._physicalStateObj._pendingData, "Should not have a busy physicalStateObject at this point!");
917+
Debug.Assert(!parser._physicalStateObj.HasPendingData, "Should not have a busy physicalStateObject at this point!");
918918

919919
parser.RollbackOrphanedAPITransactions();
920920
}
@@ -1073,7 +1073,7 @@ private void ResetConnection()
10731073
// obtains a clone.
10741074

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

10781078
if (_fResetConnection)
10791079
{

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

+26-26
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ internal TdsParserStateObject GetSession(object owner)
964964
{
965965
session = _sessionPool.GetSession(owner);
966966

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

15991599
if (!connectionIsDoomed && null != _physicalStateObj)
16001600
{
1601-
if (_physicalStateObj._pendingData)
1601+
if (_physicalStateObj.HasPendingData)
16021602
{
16031603
DrainData(_physicalStateObj);
16041604
}
@@ -2479,7 +2479,7 @@ internal bool TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataRead
24792479
{
24802480
if (token == TdsEnums.SQLERROR)
24812481
{
2482-
stateObj._errorTokenReceived = true; // Keep track of the fact error token was received - for Done processing.
2482+
stateObj.HasReceivedError = true; // Keep track of the fact error token was received - for Done processing.
24832483
}
24842484

24852485
SqlError error;
@@ -3009,18 +3009,18 @@ internal bool TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataRead
30093009
break;
30103010
}
30113011

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

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

30223022
#if DEBUG
3023-
if ((stateObj._pendingData) && (!dataReady))
3023+
if ((stateObj.HasPendingData) && (!dataReady))
30243024
{
30253025
byte token;
30263026
if (!stateObj.TryPeekByte(out token))
@@ -3031,7 +3031,7 @@ internal bool TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataRead
30313031
}
30323032
#endif
30333033

3034-
if (!stateObj._pendingData)
3034+
if (!stateObj.HasPendingData)
30353035
{
30363036
if (null != CurrentTransaction)
30373037
{
@@ -3041,7 +3041,7 @@ internal bool TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataRead
30413041

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

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

35393539
// Skip the bogus DONE counts sent by the server
3540-
if (stateObj._receivedColMetaData || (curCmd != TdsEnums.SELECT))
3540+
if (stateObj.HasReceivedColumnMetadata || (curCmd != TdsEnums.SELECT))
35413541
{
35423542
cmd.OnStatementCompleted(count);
35433543
}
35443544
}
35453545

3546-
stateObj._receivedColMetaData = false;
3546+
stateObj.HasReceivedColumnMetadata = false;
35473547

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

@@ -3586,17 +3586,17 @@ private bool TryProcessDone(SqlCommand cmd, SqlDataReader reader, ref RunBehavio
35863586
// stop if the DONE_MORE bit isn't set (see above for attention handling)
35873587
if (TdsEnums.DONE_MORE != (status & TdsEnums.DONE_MORE))
35883588
{
3589-
stateObj._errorTokenReceived = false;
3589+
stateObj.HasReceivedError = false;
35903590
if (stateObj._inBytesUsed >= stateObj._inBytesRead)
35913591
{
3592-
stateObj._pendingData = false;
3592+
stateObj.HasPendingData = false;
35933593
}
35943594
}
35953595

3596-
// _pendingData set by e.g. 'TdsExecuteSQLBatch'
3597-
// _hasOpenResult always set to true by 'WriteMarsHeader'
3596+
// HasPendingData set by e.g. 'TdsExecuteSQLBatch'
3597+
// HasOpenResult always set to true by 'WriteMarsHeader'
35983598
//
3599-
if (!stateObj._pendingData && stateObj._hasOpenResult)
3599+
if (!stateObj.HasPendingData && stateObj.HasOpenResult)
36003600
{
36013601
/*
36023602
Debug.Assert(!((sqlTransaction != null && _distributedTransaction != null) ||
@@ -5140,7 +5140,7 @@ internal void ThrowUnsupportedCollationEncountered(TdsParserStateObject stateObj
51405140
{
51415141
DrainData(stateObj);
51425142

5143-
stateObj._pendingData = false;
5143+
stateObj.HasPendingData = false;
51445144
}
51455145

51465146
ThrowExceptionAndWarning(stateObj);
@@ -5742,7 +5742,7 @@ private bool TryCommonProcessMetaData(TdsParserStateObject stateObj, _SqlMetaDat
57425742

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

@@ -9340,8 +9340,8 @@ internal void TdsLogin(SqlLogin rec,
93409340
}
93419341

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

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

93919391
_physicalStateObj.WritePacket(TdsEnums.HARDFLUSH);
9392-
_physicalStateObj._pendingData = true;
9392+
_physicalStateObj.HasPendingData = true;
93939393
_physicalStateObj._messageStatus = 0;
93949394

93959395
_connHandler._federatedAuthenticationRequested = true;
@@ -9701,7 +9701,7 @@ internal SqlDataReader TdsExecuteTransactionManagerRequest(
97019701

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

97079707
SqlDataReader dtcReader = null;
@@ -11223,7 +11223,7 @@ internal Task WriteBulkCopyDone(TdsParserStateObject stateObj)
1122311223
WriteShort(0, stateObj);
1122411224
WriteInt(0, stateObj);
1122511225

11226-
stateObj._pendingData = true;
11226+
stateObj.HasPendingData = true;
1122711227
stateObj._messageStatus = 0;
1122811228
return stateObj.WritePacket(TdsEnums.HARDFLUSH);
1122911229
}

0 commit comments

Comments
 (0)