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

Experimental OperationStatus #1229

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Microsoft.Data.SqlClient.sln
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.SqlClient.Do
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.SqlClient.PerformanceTests", "Microsoft.Data.SqlClient\tests\PerformanceTests\Microsoft.Data.SqlClient.PerformanceTests.csproj", "{599A336B-2A5F-473D-8442-1223ED37C93E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlBench3.0", "..\..\dev\SqlClient-Integrated\SqlBench3.0\SqlBench3.0.csproj", "{3F7F9B89-651E-4110-ADD4-10B81627498F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -472,6 +474,18 @@ Global
{599A336B-2A5F-473D-8442-1223ED37C93E}.Release|x64.Build.0 = Release|x64
{599A336B-2A5F-473D-8442-1223ED37C93E}.Release|x86.ActiveCfg = Release|x86
{599A336B-2A5F-473D-8442-1223ED37C93E}.Release|x86.Build.0 = Release|x86
{3F7F9B89-651E-4110-ADD4-10B81627498F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3F7F9B89-651E-4110-ADD4-10B81627498F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F7F9B89-651E-4110-ADD4-10B81627498F}.Debug|x64.ActiveCfg = Debug|Any CPU
{3F7F9B89-651E-4110-ADD4-10B81627498F}.Debug|x64.Build.0 = Debug|Any CPU
{3F7F9B89-651E-4110-ADD4-10B81627498F}.Debug|x86.ActiveCfg = Debug|Any CPU
{3F7F9B89-651E-4110-ADD4-10B81627498F}.Debug|x86.Build.0 = Debug|Any CPU
{3F7F9B89-651E-4110-ADD4-10B81627498F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F7F9B89-651E-4110-ADD4-10B81627498F}.Release|Any CPU.Build.0 = Release|Any CPU
{3F7F9B89-651E-4110-ADD4-10B81627498F}.Release|x64.ActiveCfg = Release|Any CPU
{3F7F9B89-651E-4110-ADD4-10B81627498F}.Release|x64.Build.0 = Release|Any CPU
{3F7F9B89-651E-4110-ADD4-10B81627498F}.Release|x86.ActiveCfg = Release|Any CPU
{3F7F9B89-651E-4110-ADD4-10B81627498F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -507,6 +521,7 @@ Global
{B499E477-C9B1-4087-A5CF-5C762D90E433} = {0CC4817A-12F3-4357-912C-09315FAAD008}
{B93A3149-67E8-491E-A1E5-19D65F9D9E98} = {0CC4817A-12F3-4357-912C-09315FAAD008}
{599A336B-2A5F-473D-8442-1223ED37C93E} = {0CC4817A-12F3-4357-912C-09315FAAD008}
{3F7F9B89-651E-4110-ADD4-10B81627498F} = {28E5EFE6-C9DD-4FF9-9FEC-532F72DFFA6E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {01D48116-37A2-4D33-B9EC-94793C702431}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public void InvokeCompletionCallback(uint sniErrorCode)
/// <param name="dataLength">Length of byte array to be allocated</param>
public void Allocate(int headerLength, int dataLength)
{
//if (_data == null || _data.Length < (headerLength + dataLength))
//{
// _data = new byte[headerLength + dataLength]; //ArrayPool<byte>.Shared.Rent(headerLength + dataLength);
//}
_data = ArrayPool<byte>.Shared.Rent(headerLength + dataLength);
_dataCapacity = dataLength;
_dataLength = 0;
Expand Down Expand Up @@ -194,7 +198,7 @@ public void Release()
if (_data != null)
{
Array.Clear(_data, 0, _headerLength + _dataLength);
ArrayPool<byte>.Shared.Return(_data, clearArray: false);
ArrayPool<byte>.Shared.Return(_data, clearArray: true);

_data = null;
_dataCapacity = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Buffers;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Diagnostics;
Expand Down Expand Up @@ -36,19 +37,19 @@ internal List<byte[]> CachedBytes
}

// Reads off from the network buffer and caches bytes. Only reads one column value in the current row.
internal static bool TryCreate(SqlMetaDataPriv metadata, TdsParser parser, TdsParserStateObject stateObj, out SqlCachedBuffer buffer)
internal static OperationStatus TryCreate(SqlMetaDataPriv metadata, TdsParser parser, TdsParserStateObject stateObj, out SqlCachedBuffer buffer)
{
int cb = 0;
ulong plplength;
byte[] byteArr;

List<byte[]> cachedBytes = new List<byte[]>();
buffer = null;

OperationStatus result = parser.TryPlpBytesLeft(stateObj, out plplength);
// the very first length is already read.
if (!parser.TryPlpBytesLeft(stateObj, out plplength))
if (result != OperationStatus.Done)
{
return false;
return result;
}
// For now we only handle Plp data from the parser directly.
Debug.Assert(metadata.metaType.IsPlp, "SqlCachedBuffer call on a non-plp data");
Expand All @@ -60,9 +61,10 @@ internal static bool TryCreate(SqlMetaDataPriv metadata, TdsParser parser, TdsPa
{
cb = (plplength > (ulong)_maxChunkSize) ? _maxChunkSize : (int)plplength;
byteArr = new byte[cb];
if (!stateObj.TryReadPlpBytes(ref byteArr, 0, cb, out cb))
result = stateObj.TryReadPlpBytes(ref byteArr, 0, cb, out cb);
if (result != OperationStatus.Done)
{
return false;
return result;
}
Debug.Assert(cb == byteArr.Length);
if (cachedBytes.Count == 0)
Expand All @@ -73,15 +75,17 @@ internal static bool TryCreate(SqlMetaDataPriv metadata, TdsParser parser, TdsPa
cachedBytes.Add(byteArr);
plplength -= (ulong)cb;
} while (plplength > 0);
if (!parser.TryPlpBytesLeft(stateObj, out plplength))

result = parser.TryPlpBytesLeft(stateObj, out plplength);
if (result != OperationStatus.Done)
{
return false;
return result;
}
} while (plplength > 0);
Debug.Assert(stateObj._longlen == 0 && stateObj._longlenleft == 0);
Debug.Assert(stateObj._longlen == 0 && stateObj._longLenleft == 0);

buffer = new SqlCachedBuffer(cachedBytes);
return true;
return OperationStatus.Done;
}

private static void AddByteOrderMark(byte[] byteArr, List<byte[]> cachedBytes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -1568,9 +1569,8 @@ private object InternalEndExecuteNonQuery(IAsyncResult asyncResult, bool isInter
{
bool dataReady;
Debug.Assert(_stateObj._syncOverAsync, "Should not attempt pends in a synchronous call");
bool result = _stateObj.Parser.TryRun(RunBehavior.UntilDone, this, null, null, _stateObj,
out dataReady);
if (!result)
OperationStatus result = _stateObj.Parser.TryRun(RunBehavior.UntilDone, this, null, null, _stateObj, out dataReady);
if (result != OperationStatus.Done)
{
throw SQL.SynchronousCallMayNotPend();
}
Expand Down Expand Up @@ -3459,9 +3459,11 @@ private Task RunExecuteNonQueryTds(string methodName, bool isAsync, int timeout,
{
bool dataReady;
Debug.Assert(_stateObj._syncOverAsync, "Should not attempt pends in a synchronous call");
bool result = _stateObj.Parser.TryRun(RunBehavior.UntilDone, this, null, null, _stateObj, out dataReady);
if (!result)
{ throw SQL.SynchronousCallMayNotPend(); }
OperationStatus result = _stateObj.Parser.TryRun(RunBehavior.UntilDone, this, null, null, _stateObj, out dataReady);
if (result != OperationStatus.Done)
{
throw SQL.SynchronousCallMayNotPend();
}
}
}
catch (Exception e)
Expand Down Expand Up @@ -4878,9 +4880,11 @@ private SqlDataReader RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavi
Task executeTask = _stateObj.Parser.TdsExecuteSQLBatch(optionSettings, timeout, this.Notification, _stateObj, sync: true);
Debug.Assert(executeTask == null, "Shouldn't get a task when doing sync writes");
Debug.Assert(_stateObj._syncOverAsync, "Should not attempt pends in a synchronous call");
bool result = _stateObj.Parser.TryRun(RunBehavior.UntilDone, this, null, null, _stateObj, out bool dataReady);
if (!result)
{ throw SQL.SynchronousCallMayNotPend(); }
OperationStatus result = _stateObj.Parser.TryRun(RunBehavior.UntilDone, this, null, null, _stateObj, out bool dataReady);
if (result != OperationStatus.Done)
{
throw SQL.SynchronousCallMayNotPend();
}
// and turn OFF when the ds exhausts the stream on Close()
optionSettings = GetResetOptionsString(cmdBehavior);
}
Expand Down Expand Up @@ -5038,9 +5042,11 @@ private void FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, stri
{
bool dataReady;
Debug.Assert(_stateObj._syncOverAsync, "Should not attempt pends in a synchronous call");
bool result = _stateObj.Parser.TryRun(RunBehavior.UntilDone, this, ds, null, _stateObj, out dataReady);
if (!result)
{ throw SQL.SynchronousCallMayNotPend(); }
OperationStatus result = _stateObj.Parser.TryRun(RunBehavior.UntilDone, this, ds, null, _stateObj, out dataReady);
if (result != OperationStatus.Done)
{
throw SQL.SynchronousCallMayNotPend();
}
}
catch (Exception e)
{
Expand Down