Kaynağa Gözat

#2130 InnoDB support

Alex Trofimov 7 yıl önce
ebeveyn
işleme
16d6bd1164

+ 38 - 8
inc/classes/BxDolDb.php

@@ -64,6 +64,8 @@ class BxDolDb extends BxDolFactory implements iBxDolSingleton
         $this->_aError = array();
 
         $this->_sStorageEngine = 'MYISAM';
+        if (defined('BX_DATABASE_ENGINE'))
+            $this->_sStorageEngine = BX_DATABASE_ENGINE;
 
         $this->_sCharset = 'utf8mb4';
         if($aDbConf === false) {
@@ -84,7 +86,9 @@ class BxDolDb extends BxDolFactory implements iBxDolSingleton
             if(isset($aDbConf['charset']))
             	$this->_sCharset = $aDbConf['charset'];
             if(isset($aDbConf['error_checking']))
-            	$this->_bErrorChecking = $aDbConf['error_checking'];
+                $this->_bErrorChecking = $aDbConf['error_checking'];
+            if(isset($aDbConf['storage_engine']))
+            	$this->_sStorageEngine = $aDbConf['storage_engine'];
         }
 
         @set_exception_handler(array($this, 'pdoExceptionHandler'));
@@ -156,6 +160,8 @@ class BxDolDb extends BxDolFactory implements iBxDolSingleton
 
             $this->pdoExec("SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci'");
             $this->pdoExec("SET sql_mode = ''");
+            if (0 == strcasecmp($this->_sStorageEngine, 'INNODB'))
+                $this->pdoExec("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
 
             $sVer = $this->getVersion();
             $sStorageEngine = !$sVer || version_compare($sVer, '5.7.5', '>=') ? 'default_storage_engine' : 'storage_engine';
@@ -484,14 +490,33 @@ class BxDolDb extends BxDolFactory implements iBxDolSingleton
         if(isset($GLOBALS['bx_profiler']))
         	$GLOBALS['bx_profiler']->beginQuery($oStatement->queryString);
 
-		$bResult = $this->executeStatement($oStatement, $aBindings, $bVerbose);
+        for ($iAttempts = 3; $iAttempts > 0; --$iAttempts) {
 
-		//if mysql connection is lost - reconnect and try again
-        if(!$bResult && !$this->ping()) {
-            $this->disconnect();
-            $this->connect();
+            $oException = null;
+            $iErrorCode = 0;
+            $bResult = false;
+            try {
+                $bResult = $this->executeStatement($oStatement, $aBindings, $bVerbose, $iErrorCode);
+            } catch (PDOException $oException) {
+                $iErrorCode = $oException->errorInfo[1];
+            }
 
-            $bResult = $this->executeStatement($oStatement, $aBindings, $bVerbose);
+            // if deadlock timeout - try again, make sure that deadlock timeout is short
+            if (!$bResult && (1205 == $iErrorCode || 1213 == $iErrorCode)) {
+                continue;
+            }
+
+	    	// if mysql connection is lost - reconnect and try again
+            if(!$bResult && !$this->ping()) {
+                $this->disconnect();
+                $this->connect();
+                continue;
+            }
+
+            // in all other cases exit from the loop
+            if ($oException)
+                throw $oException;
+            break;
         }
 
         if(isset($GLOBALS['bx_profiler']))
@@ -1091,7 +1116,7 @@ class BxDolDb extends BxDolFactory implements iBxDolSingleton
         return empty($aResult) ? true : $aResult;
     }
 
-    protected function executeStatement($oStatement, $aBindings = array(), $bVerbose = null)
+    protected function executeStatement($oStatement, $aBindings = array(), $bVerbose = null, &$iErrorCode = null)
     {
         $bResult = false;
 
@@ -1117,6 +1142,11 @@ class BxDolDb extends BxDolFactory implements iBxDolSingleton
     			break;
     	}
 
+        if (!$bResult && !is_null($iErrorCode)) {
+            $aError = $oStatement->errorInfo();
+            $iErrorCode = $aError[1];
+        }
+
     	return $bResult;
     }
 

+ 1 - 1
inc/classes/BxDolFavorite.php

@@ -40,7 +40,7 @@ define('BX_DOL_FAVORITE_USAGE_DEFAULT', BX_DOL_FAVORITE_USAGE_BLOCK);
  *      `author_id` int(11) NOT NULL default '0', -- favoring user profile id
  *      `date` int(11) NOT NULL default '0', -- timestamp of last recorded view
  *      KEY `id` (`object_id`,`author_id`)
- *  ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+ *  );
  * @endcode
  *
  */

+ 1 - 1
inc/classes/BxDolView.php

@@ -44,7 +44,7 @@ define('BX_DOL_VIEW_USAGE_DEFAULT', BX_DOL_VIEW_USAGE_BLOCK);
  *      `viewer_nip` int(11) unsigned NOT NULL default '0', -- viewer ip address to track guest views
  *      `date` int(11) NOT NULL default '0', -- timestamp of last recorded view
  *      KEY `id` (`object_id`,`viewer_id`,`viewer_nip`)
- *  ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+ *  );
  * @endcode
  *
  */

+ 1 - 0
install/patterns/header.inc.php

@@ -12,6 +12,7 @@ define('BX_DATABASE_PORT', '%DB_PORT%'); ///< db port
 define('BX_DATABASE_USER', '%DB_USER%'); ///< db user
 define('BX_DATABASE_PASS', '%DB_PASSWORD%'); ///< db password
 define('BX_DATABASE_NAME', '%DB_NAME%'); ///< db name
+define('BX_DATABASE_ENGINE', 'MYISAM'); ///< db engine
 
 define('BX_SYSTEM_JAVA', '%JAVA_PATH%'); ///< path to java binary
 define('BX_SYSTEM_FFMPEG', '%FFMPEG_PATH%'); ///< path to ffmpeg binary

+ 1 - 1
install/sql/system.sql

@@ -2845,7 +2845,7 @@ CREATE TABLE IF NOT EXISTS `sys_objects_uploader` (
   `override_class_file` varchar(255) NOT NULL,
   PRIMARY KEY (`id`),
   UNIQUE KEY `object` (`object`)
-) ENGINE=MyISAM;
+);
 
 INSERT INTO `sys_objects_uploader` (`object`, `active`, `override_class_name`, `override_class_file`) VALUES
 ('sys_simple', 1, 'BxTemplUploaderSimple', ''),

+ 1 - 1
modules/boonex/dolphin_connect/install/sql/install.sql

@@ -4,7 +4,7 @@ CREATE TABLE `bx_dolcon_accounts` (
   `remote_profile` int(10) unsigned NOT NULL,
   PRIMARY KEY (`local_profile`),
   KEY `remote_profile` (`remote_profile`)
-) ENGINE=MyISAM;
+);
 
 -- Studio page and widget
 

+ 1 - 1
modules/boonex/google_connect/install/sql/install.sql

@@ -4,7 +4,7 @@ CREATE TABLE `bx_googlecon_accounts` (
   `remote_profile` varchar(16) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
   PRIMARY KEY (`local_profile`),
   KEY `remote_profile` (`remote_profile`)
-) ENGINE=MyISAM;
+);
 
 -- Studio page and widget
 

+ 1 - 1
modules/boonex/linkedin_connect/install/sql/install.sql

@@ -4,7 +4,7 @@ CREATE TABLE `bx_linkedin_accounts` (
   `remote_profile` varchar(16) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
   PRIMARY KEY (`local_profile`),
   KEY `remote_profile` (`remote_profile`)
-) ENGINE=MyISAM;
+);
 
 -- Studio page and widget
 

+ 1 - 1
modules/boonex/twitter_connect/install/sql/install.sql

@@ -4,7 +4,7 @@ CREATE TABLE `bx_twitter_accounts` (
   `remote_profile` varchar(16) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
   PRIMARY KEY (`local_profile`),
   KEY `remote_profile` (`remote_profile`)
-) ENGINE=MyISAM;
+);
 
 -- Studio page and widget
 

+ 1 - 1
modules/boonex/una_connect/install/sql/install.sql

@@ -4,7 +4,7 @@ CREATE TABLE `bx_unacon_accounts` (
   `remote_profile` int(10) unsigned NOT NULL,
   PRIMARY KEY (`local_profile`),
   KEY `remote_profile` (`remote_profile`)
-) ENGINE=MyISAM;
+);
 
 -- Studio page and widget
 

+ 4 - 4
samples/BxCmtsMy.php

@@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS `sample_cmts_votes` (
   `count` int(11) NOT NULL default '0',
   `sum` int(11) NOT NULL default '0',
   UNIQUE KEY `object_id` (`object_id`)
-) ENGINE=MYISAM DEFAULT CHARSET=utf8;
+);
 
 CREATE TABLE IF NOT EXISTS `sample_cmts_votes_track` (
   `object_id` int(11) NOT NULL default '0',
@@ -32,7 +32,7 @@ CREATE TABLE IF NOT EXISTS `sample_cmts_votes_track` (
   `value` tinyint(4) NOT NULL default '0',
   `date` int(11) NOT NULL default '0',
   KEY `vote` (`object_id`, `author_nip`)
-) ENGINE=MYISAM DEFAULT CHARSET=utf8;
+);
 
  */
 
@@ -56,7 +56,7 @@ CREATE TABLE IF NOT EXISTS `sample_cmts` (
   `cmt_replies` int(11) NOT NULL DEFAULT '0',
   PRIMARY KEY (`cmt_id`),
   KEY `cmt_object_id` (`cmt_object_id`,`cmt_parent_id`)
-) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
+);
 
 Note: 'sample_cmts_trigger' table is needed just to check comments counter. In real integration it should be your main content table.
 CREATE TABLE IF NOT EXISTS `sample_cmts_trigger` (
@@ -64,7 +64,7 @@ CREATE TABLE IF NOT EXISTS `sample_cmts_trigger` (
   `title` varchar(64) NOT NULL DEFAULT '0',
   `comments` int(11) NOT NULL DEFAULT '0',
   PRIMARY KEY (`id`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+);
 
 INSERT INTO `sample_cmts_trigger` (`id`, `title`, `comments`) VALUES
 (1, 'Sample Comments', 0);

+ 1 - 1
samples/BxGridMy.php

@@ -64,7 +64,7 @@ CREATE TABLE IF NOT EXISTS `sample_grid_data` (
   KEY `Country` (`Country`),
   KEY `DateOfBirth` (`DateOfBirth`),
   FULLTEXT KEY `NickName_2` (`NickName`,`City`,`Headline`,`DescriptionMe`,`Tags`)
-) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=56 ;
+);
 
 INSERT INTO `sample_grid_data` VALUES
 (1, 'admin', 'dev@boonex.com', 'Rejected', 3, '', '', '', '', '', '0000-00-00', '', 0),

+ 1 - 1
samples/BxSampleForm.php

@@ -34,7 +34,7 @@ CREATE TABLE IF NOT EXISTS `sample_input_types` (
   `radio_set` int(11) NOT NULL,
   `custom` varchar(255) NOT NULL,
   PRIMARY KEY (`id`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+);
 
 -- SQL dump of form object: