[mapguide-commits] r6690 - trunk/MgDev/Server/src/Common/Manager
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Wed May 23 22:29:49 EDT 2012
Author: hubu
Date: 2012-05-23 19:29:48 -0700 (Wed, 23 May 2012)
New Revision: 6690
Modified:
trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.cpp
trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.h
Log:
Submit on behalf of Andy Zhang
Implement ticket #1998: Fdo Connection Manager enhancement.
Ticket: http://trac.osgeo.org/mapguide/ticket/1998
Modified: trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.cpp
===================================================================
--- trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.cpp 2012-05-23 16:57:57 UTC (rev 6689)
+++ trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.cpp 2012-05-24 02:29:48 UTC (rev 6690)
@@ -239,26 +239,35 @@
// Try to acquire a connection. We will either get a connection or exhaust the re-try logic
providerInfo = TryAcquireFdoConnection(provider);
+
+ bool reuseOnly = false;
+
+ ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, ace_mon, sm_mutex, NULL));
if(providerInfo)
{
- ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, ace_mon, sm_mutex, NULL));
-
+ // If current connections count is equal to the pool size of the provider, we cannot create new connection.
+ // But if it is a PerCommandThreaded/MultiThreaded provider, we can reuse existing connections.
+ reuseOnly = (providerInfo->GetCurrentConnections() == providerInfo->GetPoolSize());
if(m_bFdoConnectionPoolEnabled)
{
// Search the cache for an FDO connection matching this resourceIdentifier
// The content and long transaction name must also match, as the information may change
- pFdoConnection = FindFdoConnection(resourceIdentifier);
+ pFdoConnection = FindFdoConnection(resourceIdentifier, reuseOnly);
}
+ }
+
+ if (providerInfo && ((NULL == pFdoConnection && !reuseOnly) || (NULL != pFdoConnection)))
+ {
+ STRING longTransactionName = (STRING)featureSource->GetLongTransaction();
+ // Update the long transaction name to any active one for the current request
+ MgLongTransactionManager::GetLongTransactionName(resourceIdentifier, longTransactionName);
+
if(NULL == pFdoConnection)
{
// Parse XML and get properties
STRING configDocumentName = (STRING)featureSource->GetConfigurationDocument();
- STRING longTransactionName = (STRING)featureSource->GetLongTransaction();
- // Update the long transaction name to any active one for the current request
- MgLongTransactionManager::GetLongTransactionName(resourceIdentifier, longTransactionName);
-
// Create a new connection
pFdoConnection = m_connManager->CreateConnection(provider.c_str());
@@ -294,6 +303,11 @@
resourceIdentifier->ToString(),
longTransactionName);
}
+ else
+ {
+ // Need to activate long transaction again for some providers.
+ ActivateLongTransaction(pFdoConnection, longTransactionName);
+ }
#ifdef _DEBUG_FDOCONNECTION_MANAGER
ShowProviderInfoCache();
@@ -369,16 +383,24 @@
// Try to acquire a connection. We will either get a connection or exhaust the re-try logic
providerInfo = TryAcquireFdoConnection(providerNoVersion);
+
+ bool reuseOnly = false;
+
if(providerInfo)
{
- ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, ace_mon, sm_mutex, NULL));
+ // If current connections count is equal to the pool size of the provider, we cannot create new connection.
+ // But if it is a PerCommandThreaded/MultiThreaded provider, we can reuse existing connections.
+ reuseOnly = (providerInfo->GetCurrentConnections() == providerInfo->GetPoolSize());
if(m_bFdoConnectionPoolEnabled)
{
// Search the cache for an FDO connection matching this provider/connection string
- pFdoConnection = FindFdoConnection(providerNoVersion, updatedConnectionString);
+ pFdoConnection = FindFdoConnection(providerNoVersion, updatedConnectionString, reuseOnly);
}
+ }
+ if (providerInfo && ((NULL == pFdoConnection && !reuseOnly) || (NULL != pFdoConnection)))
+ {
if(NULL == pFdoConnection)
{
// Create a new connection and add it to the cache
@@ -586,7 +608,7 @@
}
-FdoIConnection* MgFdoConnectionManager::FindFdoConnection(MgResourceIdentifier* resourceIdentifier)
+FdoIConnection* MgFdoConnectionManager::FindFdoConnection(MgResourceIdentifier* resourceIdentifier, bool reuseOnly)
{
CHECKNULL(resourceIdentifier, L"MgFdoConnectionManager.FindFdoConnection");
@@ -619,7 +641,8 @@
pFdoConnection = SearchFdoConnectionCache(provider,
resourceIdentifier->ToString(),
- ltName);
+ ltName,
+ reuseOnly);
MG_FDOCONNECTION_MANAGER_CATCH_AND_THROW(L"MgFdoConnectionManager.FindFdoConnection")
@@ -627,7 +650,7 @@
}
-FdoIConnection* MgFdoConnectionManager::FindFdoConnection(CREFSTRING provider, CREFSTRING connectionString)
+FdoIConnection* MgFdoConnectionManager::FindFdoConnection(CREFSTRING provider, CREFSTRING connectionString, bool reuseOnly)
{
FdoPtr<FdoIConnection> pFdoConnection;
@@ -636,7 +659,7 @@
STRING providerNoVersion = UpdateProviderName(provider);
STRING ltName = L"";
- pFdoConnection = SearchFdoConnectionCache(providerNoVersion, connectionString, ltName);
+ pFdoConnection = SearchFdoConnectionCache(providerNoVersion, connectionString, ltName, reuseOnly);
MG_FDOCONNECTION_MANAGER_CATCH_AND_THROW(L"MgFdoConnectionManager.FindFdoConnection")
@@ -644,7 +667,7 @@
}
-FdoIConnection* MgFdoConnectionManager::SearchFdoConnectionCache(CREFSTRING provider, CREFSTRING key, CREFSTRING ltName)
+FdoIConnection* MgFdoConnectionManager::SearchFdoConnectionCache(CREFSTRING provider, CREFSTRING key, CREFSTRING ltName, bool reuseOnly)
{
FdoPtr<FdoIConnection> pFdoConnection;
@@ -684,9 +707,12 @@
INT32 useLimit = providerInfo->GetUseLimit();
if (useLimit == -1 || pFdoConnectionCacheEntry->nUseTotal <= useLimit)
{
+ // If the provider is a PerCommandThreaded/MultiThreaded provider, reuse existing
+ // connection only when reuseOnly is true (current connections count == pool size).
if((!pFdoConnectionCacheEntry->bInUse) ||
- (providerInfo->GetThreadModel() == FdoThreadCapability_PerCommandThreaded) ||
- (providerInfo->GetThreadModel() == FdoThreadCapability_MultiThreaded))
+ (reuseOnly &&
+ ((providerInfo->GetThreadModel() == FdoThreadCapability_PerCommandThreaded) ||
+ (providerInfo->GetThreadModel() == FdoThreadCapability_MultiThreaded))))
{
// It is not in use or the provider is a PerCommandThreaded/MultiThreaded provider so claim it
pFdoConnectionCacheEntry->lastUsed = ACE_OS::gettimeofday();
@@ -1405,7 +1431,10 @@
if(providerInfo)
{
// Check to see if all connections are in use
- if(providerInfo->GetCurrentConnections() == providerInfo->GetPoolSize())
+ // If it is a PerCommandThreaded/MultiThreaded provider, the existing connections can be reused.
+ if(providerInfo->GetCurrentConnections() == providerInfo->GetPoolSize() &&
+ ((providerInfo->GetThreadModel() != FdoThreadCapability_PerCommandThreaded) &&
+ (providerInfo->GetThreadModel() != FdoThreadCapability_MultiThreaded)))
{
// All connections are in use
providerInfo = NULL;
Modified: trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.h
===================================================================
--- trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.h 2012-05-23 16:57:57 UTC (rev 6689)
+++ trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.h 2012-05-24 02:29:48 UTC (rev 6690)
@@ -244,9 +244,9 @@
// Constructor
MgFdoConnectionManager();
- FdoIConnection* FindFdoConnection(MgResourceIdentifier* resourceIdentifier);
- FdoIConnection* FindFdoConnection(CREFSTRING provider, CREFSTRING connectionString);
- FdoIConnection* SearchFdoConnectionCache(CREFSTRING provider, CREFSTRING key, CREFSTRING ltName);
+ FdoIConnection* FindFdoConnection(MgResourceIdentifier* resourceIdentifier, bool reuseOnly = false);
+ FdoIConnection* FindFdoConnection(CREFSTRING provider, CREFSTRING connectionString, bool reuseOnly = false);
+ FdoIConnection* SearchFdoConnectionCache(CREFSTRING provider, CREFSTRING key, CREFSTRING ltName, bool reuseOnly = false);
void CacheFdoConnection(FdoIConnection* pFdoConnection, CREFSTRING provider, CREFSTRING key, CREFSTRING ltName);
bool UpdateFdoConnectionCache(CREFSTRING provider);
More information about the mapguide-commits
mailing list