[mapguide-commits] r4392 - in trunk/MgDev: Common/MapGuideCommon/System Server/src/Common/Manager Server/src/Core

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Dec 8 19:27:50 EST 2009


Author: brucedechant
Date: 2009-12-08 19:27:49 -0500 (Tue, 08 Dec 2009)
New Revision: 4392

Modified:
   trunk/MgDev/Common/MapGuideCommon/System/ConfigProperties.cpp
   trunk/MgDev/Common/MapGuideCommon/System/ConfigProperties.h
   trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.cpp
   trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.h
   trunk/MgDev/Server/src/Core/Server.cpp
Log:
Fix for trac ticket 1014 - Support a way to limit # of operations performed on a FDO connection 
http://trac.osgeo.org/mapguide/ticket/1014 

Notes: 
- Added support for DataConnectionUseLimit on FDO providers 


Modified: trunk/MgDev/Common/MapGuideCommon/System/ConfigProperties.cpp
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/System/ConfigProperties.cpp	2009-12-09 00:23:40 UTC (rev 4391)
+++ trunk/MgDev/Common/MapGuideCommon/System/ConfigProperties.cpp	2009-12-09 00:27:49 UTC (rev 4392)
@@ -258,6 +258,8 @@
 const INT32  MgConfigProperties::DefaultFeatureServicePropertyDataConnectionTimerInterval   = 60;
 const STRING MgConfigProperties::FeatureServicePropertyJoinQueryBatchSize                   = L"JoinQueryBatchSize";
 const INT32  MgConfigProperties::DefaultFeatureServicePropertyJoinQueryBatchSize            = 100;
+const STRING MgConfigProperties::FeatureServicePropertyDataConnectionUseLimit               = L"DataConnectionUseLimit";
+const STRING MgConfigProperties::DefaultFeatureServicePropertyDataConnectionUseLimit        = L"";
 const STRING MgConfigProperties::FeatureServicePropertyDataTransactionTimeout               = L"DataTransactionTimeout";
 const INT32  MgConfigProperties::DefaultFeatureServicePropertyDataTransactionTimeout        = 360;
 const STRING MgConfigProperties::FeatureServicePropertyDataTransactionTimerInterval         = L"DataTransactionTimerInterval";
@@ -570,6 +572,7 @@
     { MgConfigProperties::FeatureServicePropertyDataConnectionTimeout               , MgPropertyType::Int32     , MG_CONFIG_MIN_TIMEOUT                 , MG_CONFIG_MAX_TIMEOUT                 , L""                                       },
     { MgConfigProperties::FeatureServicePropertyDataConnectionTimerInterval         , MgPropertyType::Int32     , MG_CONFIG_MIN_TIMER_INTERVAL          , MG_CONFIG_MAX_TIMER_INTERVAL          , L""                                       },
     { MgConfigProperties::FeatureServicePropertyJoinQueryBatchSize                  , MgPropertyType::Int32     , MG_CONFIG_MIN_JOIN_QUERY_BATCH_SIZE   , MG_CONFIG_MAX_JOIN_QUERY_BATCH_SIZE   , L""                                       },
+    { MgConfigProperties::FeatureServicePropertyDataConnectionUseLimit              , MgPropertyType::String    , MG_CONFIG_MIN_FS_CP_EXCLUDED_LENGTH   , MG_CONFIG_MAX_FS_CP_EXCLUDED_LENGTH   , L""                                       },
     { MgConfigProperties::FeatureServicePropertyDataTransactionTimeout              , MgPropertyType::Int32     , MG_CONFIG_MIN_TIMEOUT                 , MG_CONFIG_MAX_TIMEOUT                 , L""                                       },
     { MgConfigProperties::FeatureServicePropertyDataTransactionTimerInterval        , MgPropertyType::Int32     , MG_CONFIG_MIN_TIMER_INTERVAL          , MG_CONFIG_MAX_TIMER_INTERVAL          , L""                                       },
     { L""                                                                           , 0                         , 0.0                                   , 0.0                                   , L""                                       }

Modified: trunk/MgDev/Common/MapGuideCommon/System/ConfigProperties.h
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/System/ConfigProperties.h	2009-12-09 00:23:40 UTC (rev 4391)
+++ trunk/MgDev/Common/MapGuideCommon/System/ConfigProperties.h	2009-12-09 00:27:49 UTC (rev 4392)
@@ -311,6 +311,10 @@
     static const STRING FeatureServicePropertyJoinQueryBatchSize;               /// value("JoinQueryBatchSize")
     static const INT32 DefaultFeatureServicePropertyJoinQueryBatchSize;         /// value(100)
 
+    /// Sets the number of uses for a FDO connection for a specific provider before it is released
+    static const STRING FeatureServicePropertyDataConnectionUseLimit;         /// value("DataConnectionUseLimit")
+    static const STRING DefaultFeatureServicePropertyDataConnectionUseLimit;  /// value("")
+
     /// Sets the maximum amount of time (in seconds) for an idle FDO transaction before the transaction is dropped
     static const STRING FeatureServicePropertyDataTransactionTimeout;            /// value("DataTransactionTimeout")
     static const INT32 DefaultFeatureServicePropertyDataTransactionTimeout;      /// value(360)

Modified: trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.cpp
===================================================================
--- trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.cpp	2009-12-09 00:23:40 UTC (rev 4391)
+++ trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.cpp	2009-12-09 00:27:49 UTC (rev 4392)
@@ -97,7 +97,8 @@
                                         INT32 nFdoConnectionPoolSize,
                                         INT32 nFdoConnectionTimeout,
                                         STRING excludedProviders,
-                                        STRING fdoConnectionPoolSizeCustom)
+                                        STRING fdoConnectionPoolSizeCustom,
+                                        STRING fdoConnectionUseLimit)
 {
     MG_FDOCONNECTION_MANAGER_TRY()
 
@@ -121,6 +122,8 @@
 
     m_fdoConnectionPoolSizeCustomCol = MgStringCollection::ParseCollection(fdoConnectionPoolSizeCustom, L",");
 
+    m_fdoConnectionUseLimitCol = MgStringCollection::ParseCollection(fdoConnectionUseLimit, L",");
+
     // Update the provider cache size collection
     if (m_fdoConnectionPoolSizeCustomCol.p)
     {
@@ -142,7 +145,7 @@
                 nCustomPoolSize = MgUtil::StringToInt32(value);
             }
 
-            ProviderInfo* providerInfo = new ProviderInfo(provider, nCustomPoolSize, (FdoThreadCapability)-1, (m_bFdoConnectionPoolEnabled & !IsExcludedProvider(provider)));
+            ProviderInfo* providerInfo = new ProviderInfo(provider, nCustomPoolSize, (FdoThreadCapability)-1, (m_bFdoConnectionPoolEnabled & !IsExcludedProvider(provider)), -1);
             if(providerInfo)
             {
                 m_ProviderInfoCollection.insert(ProviderInfoCacheEntry_Pair(provider, providerInfo));
@@ -150,6 +153,49 @@
         }
     }
 
+    // Update the provider cache size collection
+    if (m_fdoConnectionUseLimitCol.p)
+    {
+        for(INT32 i=0;i<m_fdoConnectionUseLimitCol->GetCount();i++)
+        {
+            STRING providerUseLimit =  m_fdoConnectionUseLimitCol->GetItem(i);
+
+            STRING provider = providerUseLimit;
+            INT32 useLimit = -1;   // No limit
+
+            // Parse the format: provider:useLimit
+            // Example: OSGeo.SDF:1000
+
+            size_t position = providerUseLimit.find(L":", 0); // NOXLATE
+            if(position != string::npos)
+            {
+                provider = providerUseLimit.substr(0, position);
+                STRING value = providerUseLimit.substr(position+1, providerUseLimit.size());
+                useLimit = MgUtil::StringToInt32(value);
+            }
+
+            ProviderInfoCollection::iterator iterProviderInfoCollection = m_ProviderInfoCollection.find(provider);
+            if(m_ProviderInfoCollection.end() != iterProviderInfoCollection)
+            {
+                ProviderInfo* providerInfo = iterProviderInfoCollection->second;
+                if(providerInfo)
+                {
+                    // Update the use limit
+                    providerInfo->SetUseLimit(useLimit);
+                }
+            }
+            else
+            {
+                // Not found so add it
+                ProviderInfo* providerInfo = new ProviderInfo(provider, nFdoConnectionPoolSize, (FdoThreadCapability)-1, (m_bFdoConnectionPoolEnabled & !IsExcludedProvider(provider)), useLimit);
+                if(providerInfo)
+                {
+                    m_ProviderInfoCollection.insert(ProviderInfoCacheEntry_Pair(provider, providerInfo));
+                }
+            }
+        }
+    }
+
 #ifdef _DEBUG
     ShowProviderInfoCache();
 #endif
@@ -432,9 +478,10 @@
                     if(pFdoConnectionCacheEntry)
                     {
                         INT32 time = now.sec() - pFdoConnectionCacheEntry->lastUsed.sec();
-                        if((time > m_nFdoConnectionTimeout) || (!pFdoConnectionCacheEntry->bValid))
+                        INT32 useLimit = providerInfo->GetUseLimit();
+                        if((time > m_nFdoConnectionTimeout) || (!pFdoConnectionCacheEntry->bValid) || (useLimit != -1 && pFdoConnectionCacheEntry->nUseTotal >= useLimit))
                         {
-                            // Connection has expired or is no longer valid so close it and remove it
+                            // Connection has expired or is no longer valid or has reached the use limit so close it and remove it
                             if (pFdoConnectionCacheEntry->pFdoConnection)
                             {
                                 // Is it in use?
@@ -604,29 +651,34 @@
                             if(pFdoConnectionCacheEntry->ltName == ltName)
                             {
                                 // We have a long transaction name match
-                                if((!pFdoConnectionCacheEntry->bInUse) || 
-                                   (providerInfo->GetThreadModel() == FdoThreadCapability_PerCommandThreaded) ||
-                                   (providerInfo->GetThreadModel() == FdoThreadCapability_MultiThreaded))
+                                INT32 useLimit = providerInfo->GetUseLimit();
+                                if (useLimit == -1 || pFdoConnectionCacheEntry->nUseTotal <= useLimit)
                                 {
-                                    // It is not in use or the provider is a PerCommandThreaded/MultiThreaded provider so claim it
-                                    pFdoConnectionCacheEntry->lastUsed = ACE_OS::gettimeofday();
-                                    pFdoConnectionCacheEntry->bInUse = true;
-                                    pFdoConnectionCacheEntry->nUseCount++;  // Only used by PerCommandThreaded/MultiThreaded
+                                    if((!pFdoConnectionCacheEntry->bInUse) || 
+                                       (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();
+                                        pFdoConnectionCacheEntry->bInUse = true;
+                                        pFdoConnectionCacheEntry->nUseCount++;  // Only used by PerCommandThreaded/MultiThreaded
+                                        pFdoConnectionCacheEntry->nUseTotal++;
 
-                                    // Check to see if the key is blank which indicates a blank connection string was cached
-                                    if(0 < key.size())
-                                    {
-                                        // The key was not blank so check if we need to open it
-                                        if (FdoConnectionState_Closed == pFdoConnectionCacheEntry->pFdoConnection->GetConnectionState())
+                                        // Check to see if the key is blank which indicates a blank connection string was cached
+                                        if(0 < key.size())
                                         {
-                                            pFdoConnectionCacheEntry->pFdoConnection->Open();
-                                            #ifdef _DEBUG_FDOCONNECTION_MANAGER
-                                            ACE_DEBUG ((LM_DEBUG, ACE_TEXT("SearchFdoConnectionCache() - Had to reopen connection!!\n")));
-                                            #endif
+                                            // The key was not blank so check if we need to open it
+                                            if (FdoConnectionState_Closed == pFdoConnectionCacheEntry->pFdoConnection->GetConnectionState())
+                                            {
+                                                pFdoConnectionCacheEntry->pFdoConnection->Open();
+                                                #ifdef _DEBUG_FDOCONNECTION_MANAGER
+                                                ACE_DEBUG ((LM_DEBUG, ACE_TEXT("SearchFdoConnectionCache() - Had to reopen connection!!\n")));
+                                                #endif
+                                            }
                                         }
+                                        pFdoConnection = FDO_SAFE_ADDREF(pFdoConnectionCacheEntry->pFdoConnection);
+                                        break;
                                     }
-                                    pFdoConnection = FDO_SAFE_ADDREF(pFdoConnectionCacheEntry->pFdoConnection);
-                                    break;
                                 }
                             }
                         }
@@ -1093,6 +1145,7 @@
             pFdoConnectionCacheEntry->bValid = true;
             pFdoConnectionCacheEntry->bInUse = true;
             pFdoConnectionCacheEntry->nUseCount = 1;
+            pFdoConnectionCacheEntry->nUseTotal = 1;
 
             #ifdef _DEBUG_FDOCONNECTION_MANAGER
             ACE_DEBUG ((LM_DEBUG, ACE_TEXT("CacheFdoConnection:\nConnection: %@\nProvider = %W\nKey = %W\nVersion(LT) = %W\n\n"), (void*)pFdoConnection, provider.c_str(), key.c_str(), ltName.empty() ? L"(empty)" : ltName.c_str()));
@@ -1255,7 +1308,7 @@
     else
     {
         // Provider information has not been cached yet so a connection will be available.
-        providerInfo = new ProviderInfo(provider, m_nFdoConnectionPoolSize, (FdoThreadCapability)-1, (m_bFdoConnectionPoolEnabled & !IsExcludedProvider(provider)));
+        providerInfo = new ProviderInfo(provider, m_nFdoConnectionPoolSize, (FdoThreadCapability)-1, (m_bFdoConnectionPoolEnabled & !IsExcludedProvider(provider)), -1);
         if(providerInfo)
         {
             m_ProviderInfoCollection.insert(ProviderInfoCacheEntry_Pair(provider, providerInfo));
@@ -1459,7 +1512,7 @@
     if(NULL == providerInfo)
     {
         // Create new entry
-        providerInfo = new ProviderInfo(provider, m_nFdoConnectionPoolSize, (FdoThreadCapability)-1, (m_bFdoConnectionPoolEnabled & !IsExcludedProvider(provider)));
+        providerInfo = new ProviderInfo(provider, m_nFdoConnectionPoolSize, (FdoThreadCapability)-1, (m_bFdoConnectionPoolEnabled & !IsExcludedProvider(provider)), -1);
         if(providerInfo)
         {
             m_ProviderInfoCollection.insert(ProviderInfoCacheEntry_Pair(provider, providerInfo));

Modified: trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.h
===================================================================
--- trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.h	2009-12-09 00:23:40 UTC (rev 4391)
+++ trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.h	2009-12-09 00:27:49 UTC (rev 4392)
@@ -42,6 +42,7 @@
     bool bValid;
     bool bInUse;
     INT32 nUseCount;    // Used by PerCommandThreaded/MultiThreaded providers
+    INT32 nUseTotal;    // Total number of times this connection has been used
 } FdoConnectionCacheEntry;
 
 // FDO Connection Cache
@@ -55,12 +56,14 @@
     ProviderInfo(STRING provider,
                  INT32 poolSize,
                  FdoThreadCapability threadModel,
-                 bool bKeepCached)
+                 bool bKeepCached,
+                 INT32 useLimit)
     {
         m_provider = provider;
         m_poolSize = poolSize;
         m_threadModel = threadModel;
         m_bKeepCached = bKeepCached;
+        m_useLimit = useLimit;
 
         m_currentConnections = 0;
     }
@@ -154,6 +157,18 @@
 
     STRING GetProviderName()                        { return m_provider; }
 
+    INT32 GetUseLimit()
+    {
+        ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, ace_mon, sm_mutex, -1));
+        return m_useLimit;
+    }
+
+    void SetUseLimit(INT32 useLimit)
+    {
+        ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, sm_mutex));
+        m_useLimit = useLimit;
+    }
+
 private:
     // The name of the provider
     STRING m_provider;
@@ -173,6 +188,9 @@
     // The flag indicating if the FDO connections for this provider should be cached
     bool m_bKeepCached;
 
+    // The # of times this FDO connections can be used before it is released
+    INT32 m_useLimit;
+
     static ACE_Recursive_Thread_Mutex sm_mutex;
 };
 
@@ -197,7 +215,8 @@
                     INT32 nFdoConnectionPoolSize,
                     INT32 nFdoConnectionTimeout,
                     STRING excludedProviders,
-                    STRING fdoConnectionPoolSizeCustom);
+                    STRING fdoConnectionPoolSizeCustom,
+                    STRING fdoConnectionUseLimit);
 
     static void Terminate();
     void ClearCache();
@@ -258,6 +277,7 @@
     INT32 m_nFdoConnectionTimeout;
     Ptr<MgStringCollection> m_excludedProviders;
     Ptr<MgStringCollection> m_fdoConnectionPoolSizeCustomCol;
+    Ptr<MgStringCollection> m_fdoConnectionUseLimitCol;
 };
 
 #endif

Modified: trunk/MgDev/Server/src/Core/Server.cpp
===================================================================
--- trunk/MgDev/Server/src/Core/Server.cpp	2009-12-09 00:23:40 UTC (rev 4391)
+++ trunk/MgDev/Server/src/Core/Server.cpp	2009-12-09 00:27:49 UTC (rev 4392)
@@ -891,11 +891,13 @@
             INT32 nDataConnectionPoolSize = MgConfigProperties::DefaultFeatureServicePropertyDataConnectionPoolSize;
             STRING dataConnectionPoolExcludedProviders = MgConfigProperties::DefaultFeatureServicePropertyDataConnectionPoolExcludedProviders;
             STRING dataConnectionPoolSizeCustom = MgConfigProperties::DefaultFeatureServicePropertyDataConnectionPoolSizeCustom;
+            STRING dataConnectionUseLimit = MgConfigProperties::DefaultFeatureServicePropertyDataConnectionUseLimit;
 
             pConfiguration->GetBoolValue(MgConfigProperties::FeatureServicePropertiesSection, MgConfigProperties::FeatureServicePropertyDataConnectionPoolEnabled, bDataConnectionPoolEnabled, MgConfigProperties::DefaultFeatureServicePropertyDataConnectionPoolEnabled);
             pConfiguration->GetIntValue(MgConfigProperties::FeatureServicePropertiesSection, MgConfigProperties::FeatureServicePropertyDataConnectionPoolSize, nDataConnectionPoolSize, MgConfigProperties::DefaultFeatureServicePropertyDataConnectionPoolSize);
             pConfiguration->GetStringValue(MgConfigProperties::FeatureServicePropertiesSection, MgConfigProperties::FeatureServicePropertyDataConnectionPoolExcludedProviders, dataConnectionPoolExcludedProviders, MgConfigProperties::DefaultFeatureServicePropertyDataConnectionPoolExcludedProviders);
             pConfiguration->GetStringValue(MgConfigProperties::FeatureServicePropertiesSection, MgConfigProperties::FeatureServicePropertyDataConnectionPoolSizeCustom, dataConnectionPoolSizeCustom, MgConfigProperties::DefaultFeatureServicePropertyDataConnectionPoolSizeCustom);
+            pConfiguration->GetStringValue(MgConfigProperties::FeatureServicePropertiesSection, MgConfigProperties::FeatureServicePropertyDataConnectionUseLimit, dataConnectionUseLimit, MgConfigProperties::DefaultFeatureServicePropertyDataConnectionUseLimit);
 
             // Add additional font mappings to the FontManager
             ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t) MgServer::open() - Adding Font Manager Mappings.\n")));
@@ -984,7 +986,7 @@
             ACE_DEBUG ((LM_DEBUG, ACE_TEXT("(%t) MgServer::open() - Initializing FDO Connection Manager.\n")));
             MgEventTimer& dataConnectionTimer = m_eventTimerManager.GetEventTimer(MgEventTimer::DataConnectionTimeout);
             MgFdoConnectionManager* pFdoConnectionManager = MgFdoConnectionManager::GetInstance();
-            pFdoConnectionManager->Initialize(bDataConnectionPoolEnabled, nDataConnectionPoolSize, dataConnectionTimer.GetEventTimeout(), dataConnectionPoolExcludedProviders, dataConnectionPoolSizeCustom);
+            pFdoConnectionManager->Initialize(bDataConnectionPoolEnabled, nDataConnectionPoolSize, dataConnectionTimer.GetEventTimeout(), dataConnectionPoolExcludedProviders, dataConnectionPoolSizeCustom, dataConnectionUseLimit);
 
             // Initialize the transaction pool
             ACE_DEBUG ((LM_DEBUG, ACE_TEXT("(%t) MgServer::open() - Initializing transaction pool.\n")));



More information about the mapguide-commits mailing list