Fixing the bug with connections on database make restore fail (#473)

* closing the connections that don't need to be open and keeping track of the connections that should stay open
This commit is contained in:
Leila Lali
2017-10-05 20:06:31 -07:00
committed by GitHub
parent 7444939335
commit f09b9f4c30
33 changed files with 1045 additions and 287 deletions

View File

@@ -25,6 +25,7 @@ using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Microsoft.SqlTools.ServiceLayer.Workspace;
using Microsoft.SqlTools.Utility;
using Microsoft.SqlServer.Management.Common;
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
{
@@ -61,6 +62,18 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
applicableNodeChildFactories = new Lazy<Dictionary<string, HashSet<ChildFactory>>>(() => PopulateFactories());
}
internal ConnectedBindingQueue ConnectedBindingQueue
{
get
{
return bindingQueue;
}
set
{
this.bindingQueue = value;
}
}
/// <summary>
/// Internal for testing only
/// </summary>
@@ -99,6 +112,15 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
Validate.IsNotNull(nameof(provider), provider);
serviceProvider = provider;
connectionService = provider.GetService<ConnectionService>();
try
{
connectionService.RegisterConnectedQueue("OE", bindingQueue);
}
catch(Exception ex)
{
Logger.Write(LogLevel.Error, ex.Message);
}
}
/// <summary>
@@ -119,6 +141,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
{
workspaceService.RegisterConfigChangeCallback(HandleDidChangeConfigurationNotification);
}
}
/// <summary>
@@ -369,7 +392,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
try
{
QueueItem queueItem = bindingQueue.QueueBindingOperation(
key: session.Uri,
key: bindingQueue.AddConnectionContext(session.ConnectionInfo),
bindingTimeout: PrepopulateBindTimeout,
waitForLockTimeout: PrepopulateBindTimeout,
bindOperation: (bindingContext, cancelToken) =>
@@ -413,19 +436,40 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
{
try
{
ObjectExplorerSession session;
ObjectExplorerSession session = null;
connectionDetails.PersistSecurityInfo = true;
ConnectParams connectParams = new ConnectParams() { OwnerUri = uri, Connection = connectionDetails };
ConnectParams connectParams = new ConnectParams() { OwnerUri = uri, Connection = connectionDetails, Type = Connection.ConnectionType.ObjectExplorer };
ConnectionInfo connectionInfo;
ConnectionCompleteParams connectionResult = await Connect(connectParams, uri);
if (!connectionService.TryFindConnection(uri, out connectionInfo))
{
return null;
}
if (connectionResult == null)
{
// Connection failed and notification is already sent
return null;
}
session = ObjectExplorerSession.CreateSession(connectionResult, serviceProvider);
sessionMap.AddOrUpdate(uri, session, (key, oldSession) => session);
QueueItem queueItem = bindingQueue.QueueBindingOperation(
key: bindingQueue.AddConnectionContext(connectionInfo),
bindingTimeout: PrepopulateBindTimeout,
waitForLockTimeout: PrepopulateBindTimeout,
bindOperation: (bindingContext, cancelToken) =>
{
session = ObjectExplorerSession.CreateSession(connectionResult, serviceProvider, bindingContext.ServerConnection);
session.ConnectionInfo = connectionInfo;
sessionMap.AddOrUpdate(uri, session, (key, oldSession) => session);
return session;
});
queueItem.ItemProcessed.WaitOne();
if (queueItem.GetResultAsT<ObjectExplorerSession>() != null)
{
session = queueItem.GetResultAsT<ObjectExplorerSession>();
}
return session;
}
catch(Exception ex)
@@ -657,11 +701,13 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
public string Uri { get; private set; }
public TreeNode Root { get; private set; }
public ConnectionInfo ConnectionInfo { get; set; }
public string ErrorMessage { get; set; }
public static ObjectExplorerSession CreateSession(ConnectionCompleteParams response, IMultiServiceProvider serviceProvider)
public static ObjectExplorerSession CreateSession(ConnectionCompleteParams response, IMultiServiceProvider serviceProvider, ServerConnection serverConnection)
{
ServerNode rootNode = new ServerNode(response, serviceProvider);
ServerNode rootNode = new ServerNode(response, serviceProvider, serverConnection);
var session = new ObjectExplorerSession(response.OwnerUri, rootNode, serviceProvider, serviceProvider.GetService<ConnectionService>());
if (!DatabaseUtils.IsSystemDatabaseConnection(response.ConnectionSummary.DatabaseName))
{