added a binding queue for oe to force one operation on a node at a time (#441)

* added a binding queue for oe to force one operation on a node at a time

* setting node subtype to temporal for temporal tables

* disposing oe service on shutdown
This commit is contained in:
Leila Lali
2017-08-22 15:15:01 -07:00
committed by GitHub
parent d94dda4282
commit eb61423f89
9 changed files with 174 additions and 38 deletions

View File

@@ -3,6 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Threading.Tasks;
using Microsoft.SqlTools.Credentials;
using Microsoft.SqlTools.Extensibility;
using Microsoft.SqlTools.Hosting;
@@ -112,12 +113,23 @@ namespace Microsoft.SqlTools.ServiceLayer
provider.RegisterSingleService(service.ServiceType, service);
}
ServiceHost serviceHost = host as ServiceHost;
foreach (IHostedService service in provider.GetServices<IHostedService>())
{
// Initialize all hosted services, and register them in the service provider for their requested
// service type. This ensures that when searching for the ConnectionService you can get it without
// searching for an IHostedService of type ConnectionService
service.InitializeService(host);
IDisposable disposable = service as IDisposable;
if (serviceHost != null && disposable != null)
{
serviceHost.RegisterShutdownTask(async (shutdownParams, shutdownRequestContext) =>
{
disposable.Dispose();
await Task.FromResult(0);
});
}
}
}
}

View File

@@ -47,6 +47,16 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
NodeValue = value;
}
private object buildingMetadataLock = new object();
/// <summary>
/// Event which tells if MetadataProvider is built fully or not
/// </summary>
public object BuildingMetadataLock
{
get { return this.buildingMetadataLock; }
}
/// <summary>
/// Value describing this node
/// </summary>

View File

@@ -17,6 +17,7 @@ using Microsoft.SqlTools.Hosting;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Contracts;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
@@ -32,7 +33,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
/// The APIs used for this are modeled closely on the VSCode TreeExplorerNodeProvider API.
/// </summary>
[Export(typeof(IHostedService))]
public class ObjectExplorerService : HostedService<ObjectExplorerService>, IComposableService, IHostedService
public class ObjectExplorerService : HostedService<ObjectExplorerService>, IComposableService, IHostedService, IDisposable
{
internal const string uriPrefix = "objectexplorer://";
@@ -42,6 +43,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
private ConcurrentDictionary<string, ObjectExplorerSession> sessionMap;
private readonly Lazy<Dictionary<string, HashSet<ChildFactory>>> applicableNodeChildFactories;
private IMultiServiceProvider serviceProvider;
private ConnectedBindingQueue bindingQueue = new ConnectedBindingQueue();
private const int PrepopulateBindTimeout = 10000;
/// <summary>
/// This timeout limits the amount of time that object explorer tasks can take to complete
@@ -280,7 +284,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
}
}
private void RunCreateSessionTask(ConnectionDetails connectionDetails, string uri)
private void RunCreateSessionTask(ConnectionDetails connectionDetails, string uri)
{
Logger.Write(LogLevel.Normal, "Creating OE session");
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
@@ -351,21 +355,54 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
{
return await Task.Factory.StartNew(() =>
{
NodeInfo[] nodes = null;
TreeNode node = session.Root.FindNodeByPath(nodePath);
if(node != null)
return QueueExpandNodeRequest(session, nodePath, forceRefresh);
});
}
internal ExpandResponse QueueExpandNodeRequest(ObjectExplorerSession session, string nodePath, bool forceRefresh = false)
{
NodeInfo[] nodes = null;
TreeNode node = session.Root.FindNodeByPath(nodePath);
ExpandResponse response = new ExpandResponse { Nodes = new NodeInfo[] { }, ErrorMessage = node.ErrorMessage, SessionId = session.Uri, NodePath = nodePath };
if (node != null && Monitor.TryEnter(node.BuildingMetadataLock, LanguageService.OnConnectionWaitTimeout))
{
try
{
if (forceRefresh)
QueueItem queueItem = bindingQueue.QueueBindingOperation(
key: session.Uri,
bindingTimeout: PrepopulateBindTimeout,
waitForLockTimeout: PrepopulateBindTimeout,
bindOperation: (bindingContext, cancelToken) =>
{
if (forceRefresh)
{
nodes = node.Refresh().Select(x => x.ToNodeInfo()).ToArray();
}
else
{
nodes = node.Expand().Select(x => x.ToNodeInfo()).ToArray();
}
response.Nodes = nodes;
response.ErrorMessage = node.ErrorMessage;
return response;
});
queueItem.ItemProcessed.WaitOne();
if (queueItem.GetResultAsT<ExpandResponse>() != null)
{
nodes = node.Refresh().Select(x => x.ToNodeInfo()).ToArray();
}
else
{
nodes = node.Expand().Select(x => x.ToNodeInfo()).ToArray();
response = queueItem.GetResultAsT<ExpandResponse>();
}
}
return new ExpandResponse { Nodes = nodes, ErrorMessage = node.ErrorMessage, SessionId = session.Uri, NodePath = nodePath };
});
catch
{
}
finally
{
Monitor.Exit(node.BuildingMetadataLock);
}
}
return response;
}
/// <summary>
@@ -590,6 +627,14 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
public Exception Exception { get; set; }
}
public void Dispose()
{
if (bindingQueue != null)
{
bindingQueue.Dispose();
}
}
internal class ObjectExplorerSession
{
private ConnectionService connectionService;

View File

@@ -128,6 +128,15 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
}
typeName += ")";
break;
case SqlDataType.Numeric:
case SqlDataType.Decimal:
typeName += $"({dataType.NumericPrecision},{dataType.NumericScale})";
break;
case SqlDataType.DateTime2:
case SqlDataType.Time:
case SqlDataType.DateTimeOffset:
typeName += $"({dataType.NumericScale})";
break;
}
}
return typeName;

View File

@@ -29,6 +29,26 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
return string.Empty;
}
public override string GetNodeSubType(object context)
{
try
{
Table table = context as Table;
if (table != null && table.TemporalType != TableTemporalType.None)
{
return "Temporal";
}
// return string.Empty;
}
catch
{
//Ignore the exception and just not change create custom name
}
return string.Empty;
}
}
/// <summary>

View File

@@ -77,6 +77,7 @@
</Filters>
<Properties>
<Property Name="IsSystemVersioned" ValidFor="Sql2016|Sql2017|AzureV12"/>
<Property Name="TemporalType" ValidFor="Sql2016|Sql2017|AzureV12"/>
</Properties>
<Child Name="SystemTables" IsSystemObject="1"/>
<!--
@@ -201,6 +202,7 @@
<Value>IndexKeyType.DriUniqueKey</Value>
</Filter>
</Filters>
</Node>
<Node Name="Constraints" LocLabel="SR.SchemaHierarchy_Constraints" BaseClass="ModelBased" NodeType="Constraint" Strategy="ElementsInRelationship" ChildQuerierTypes="SqlDefaultConstraint;SqlCheck"/>
<Node Name="Triggers" LocLabel="SR.SchemaHierarchy_Triggers" BaseClass="ModelBased" Strategy="ElementsInRelationship" NodeType="Trigger" ChildQuerierTypes="SqlDmlTrigger" ValidFor="Sql2005|Sql2008|Sql2012|Sql2014|Sql2016|Sql2017|AzureV12"/>

View File

@@ -775,6 +775,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
Name = "IsSystemVersioned",
ValidFor = ValidForFlag.Sql2016|ValidForFlag.Sql2017|ValidForFlag.AzureV12
});
properties.Add(new NodeSmoProperty
{
Name = "TemporalType",
ValidFor = ValidForFlag.Sql2016|ValidForFlag.Sql2017|ValidForFlag.AzureV12
});
return properties;
}
}

View File

@@ -1,3 +1,18 @@
NodeType: Table Label: dbo.tableWithAllDataTypes SubType: Status:
NodeType: Column Label: cDecimal (decimal(18,5), null) SubType: Status:
NodeType: Column Label: cNumeric (numeric(18,2), null) SubType: Status:
NodeType: Column Label: cBigint (bigint, null) SubType: Status:
NodeType: Column Label: cDate (date, null) SubType: Status:
NodeType: Column Label: cDatetime (datetime, null) SubType: Status:
NodeType: Column Label: cFloat (float, null) SubType: Status:
NodeType: Column Label: cSmalldatetime (smalldatetime, null) SubType: Status:
NodeType: Column Label: cDatetime2 (datetime2(7), null) SubType: Status:
NodeType: Column Label: cDatetimeoffset (datetimeoffset(7), null) SubType: Status:
NodeType: Column Label: cTime (time(7), null) SubType: Status:
NodeType: Column Label: cBinary (binary(1), null) SubType: Status:
NodeType: Column Label: cBit (bit, null) SubType: Status:
NodeType: Column Label: cChar (char(1), null) SubType: Status:
NodeType: Column Label: cMoney (money, null) SubType: Status:
NodeType: Table Label: dbo.tableWithColumnset SubType: Status:
NodeType: Column Label: i (int, null) SubType: Status:
NodeType: Column Label: cs (Column Set, null) SubType: Status:
@@ -29,7 +44,7 @@ NodeType: Constraint Label: CK_Employee_VacationHours SubType: Status:
NodeType: Index Label: NonClusteredIndex-Login (Non-Unique, Non-Clustered) SubType: Status:
NodeType: Statistic Label: NonClusteredIndex-Login SubType: Status:
NodeType: Statistic Label: PK_Employee_BusinessEntityID SubType: Status:
NodeType: Table Label: HumanResources.Employee_Temporal (System-Versioned) SubType: Status:
NodeType: Table Label: HumanResources.Employee_Temporal (System-Versioned) SubType:Temporal Status:
NodeType: Column Label: BusinessEntityID (PK, int, not null) SubType: Status:
NodeType: Column Label: NationalIDNumber (nvarchar(15), not null) SubType: Status:
NodeType: Column Label: LoginID (nvarchar(256), not null) SubType: Status:
@@ -42,8 +57,8 @@ NodeType: Column Label: Gender (nchar(1), not null) SubType: Status:
NodeType: Column Label: HireDate (date, not null) SubType: Status:
NodeType: Column Label: VacationHours (smallint, not null) SubType: Status:
NodeType: Column Label: SickLeaveHours (smallint, not null) SubType: Status:
NodeType: Column Label: ValidFrom (datetime2, not null) SubType: Status:
NodeType: Column Label: ValidTo (datetime2, not null) SubType: Status:
NodeType: Column Label: ValidFrom (datetime2(7), not null) SubType: Status:
NodeType: Column Label: ValidTo (datetime2(7), not null) SubType: Status:
NodeType: Key Label: PK_Employee_History_BusinessEntityID SubType:PrimaryKey Status:
NodeType: Statistic Label: PK_Employee_History_BusinessEntityID SubType: Status:
NodeType: HistoryTable Label: HumanResources.Employee_Temporal_History (History) SubType: Status:
@@ -59,8 +74,8 @@ NodeType: Column Label: Gender (nchar(1), not null) SubType: Status:
NodeType: Column Label: HireDate (date, not null) SubType: Status:
NodeType: Column Label: VacationHours (smallint, not null) SubType: Status:
NodeType: Column Label: SickLeaveHours (smallint, not null) SubType: Status:
NodeType: Column Label: ValidFrom (datetime2, not null) SubType: Status:
NodeType: Column Label: ValidTo (datetime2, not null) SubType: Status:
NodeType: Column Label: ValidFrom (datetime2(7), not null) SubType: Status:
NodeType: Column Label: ValidTo (datetime2(7), not null) SubType: Status:
NodeType: Table Label: Person.Person SubType: Status:
NodeType: Column Label: BusinessEntityID (PK, int, not null) SubType: Status:
NodeType: Column Label: PersonType (nchar(2), not null) SubType: Status:

View File

@@ -240,6 +240,24 @@
GO
CREATE TABLE [dbo].[tableWithAllDataTypes](
[cDecimal] [decimal](18, 5) NULL,
[cNumeric] [numeric](18, 2) NULL,
[cBigint] [bigint] NULL,
[cDate] [date] NULL,
[cDatetime] [datetime] NULL,
[cFloat] [float] NULL,
[cSmalldatetime] [smalldatetime] NULL,
[cDatetime2] [datetime2](7) NULL,
[cDatetimeoffset] [datetimeoffset](7) NULL,
[cTime] [time](7) NULL,
[cBinary] [Binary] NULL,
[cBit] [Bit] NULL,
[cChar] [Char] NULL,
[cMoney] [Money] NULL
) ON [PRIMARY]
GO
ALTER TABLE [HumanResources].[Employee] ADD CONSTRAINT [DF_Employee_SalariedFlag] DEFAULT ((1)) FOR [SalariedFlag]
GO
ALTER TABLE [HumanResources].[Employee] ADD CONSTRAINT [DF_Employee_VacationHours] DEFAULT ((0)) FOR [VacationHours]