]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17942 reimplemented detection of mysql max_packet_size problems
authorskodak <skodak>
Mon, 19 Jan 2009 08:03:55 +0000 (08:03 +0000)
committerskodak <skodak>
Mon, 19 Jan 2009 08:03:55 +0000 (08:03 +0000)
index.php
lang/en_utf8/error.php
lib/db/install.xml
lib/db/upgrade.php
lib/sessionlib.php
login/index.php
version.php

index 5730fed538547432b4963786530473ce034fac5a..dec4d08f776a0442486559dfc23939a8382a8a63 100644 (file)
--- a/index.php
+++ b/index.php
@@ -47,7 +47,7 @@
     define('BLOCK_R_MAX_WIDTH', $rmax);
 
     // check if major upgrade needed - also present in login/index.php
-    if (empty($CFG->version) or (int)$CFG->version < 2009011600) { //1.9 or older
+    if (empty($CFG->version) or (int)$CFG->version < 2009011900) { //1.9 or older
         @require_logout();
         redirect("$CFG->wwwroot/$CFG->admin/");
     }
index 8e0a5d9459493bcf91bfa279d29e7de5a9c9a0db..5a2ca1c5ea904d7a5cb2547396861a84963eb6d4 100644 (file)
@@ -191,6 +191,7 @@ $string['dbdriverproblem'] = '<p>Error: database driver problem detected</p>
 $string['dbupdatefailed'] = 'Database update failed';
 $string['dbsessionbroken'] = 'Serious database session problem detected.<br /><br />Please notify server administrator.';
 $string['dbsessionhandlerproblem'] = 'Setting up of database session failed.<br /><br />Please notify server administrator.';
+$string['dbsessionmysqlpacketsize'] = 'Serious session error detected.<br /><br />Please notify administrator, this problem is most probably caused by small value in max_packet_size MySQL setting.';
 $string['ddlexecuteerror'] = 'DDL sql execution error';
 $string['ddlfieldalreadyexists'] = 'Field \"$a\" does not exist';
 $string['ddlfieldnotexist'] = 'Field \"$a->fieldname\" does not exist in table \"$a->tablename\"';
index b33b7bac0137024218907f8975985bd46879d404..2b0f0a247275bfcdca93b2131dc0228fb5e35c43 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20090114" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20090119" COMMENT="XMLDB file for core Moodle tables"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
 >
         <FIELD NAME="state" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="0 means normal session" PREVIOUS="id" NEXT="sid"/>
         <FIELD NAME="sid" TYPE="char" LENGTH="128" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="Session id" PREVIOUS="state" NEXT="userid"/>
         <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="sid" NEXT="sessdata"/>
-        <FIELD NAME="sessdata" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="session content" PREVIOUS="userid" NEXT="sessdatahash"/>
-        <FIELD NAME="sessdatahash" TYPE="char" LENGTH="40" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="verifies integrity of sessdata" PREVIOUS="sessdata" NEXT="timecreated"/>
-        <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="sessdatahash" NEXT="timemodified"/>
+        <FIELD NAME="sessdata" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="session content" PREVIOUS="userid" NEXT="timecreated"/>
+        <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="sessdata" NEXT="timemodified"/>
         <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="timecreated" NEXT="firstip"/>
         <FIELD NAME="firstip" TYPE="char" LENGTH="45" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="timemodified" NEXT="lastip"/>
         <FIELD NAME="lastip" TYPE="char" LENGTH="45" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="firstip"/>
index 2ea3ddffabf2531451e5e02ea56b113b87797055..1ebdd0084df2ac62c7ebd555c6c3c1f362a7157f 100644 (file)
@@ -1323,7 +1323,7 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint($result, 2009011303);
     }
 
-    if ($result && $oldversion < 2009011600) {
+    if ($result && $oldversion < 2009011900) {
 
     /// Define table sessions2 to be dropped
         $table = new xmldb_table('sessions2');
@@ -1350,7 +1350,6 @@ function xmldb_main_upgrade($oldversion) {
         $table->add_field('sid', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null, null, null);
         $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
         $table->add_field('sessdata', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
-        $table->add_field('sessdatahash', XMLDB_TYPE_CHAR, '40', null, null, null, null, null, null);
         $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
         $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
         $table->add_field('firstip', XMLDB_TYPE_CHAR, '45', null, null, null, null, null, null);
@@ -1370,7 +1369,7 @@ function xmldb_main_upgrade($oldversion) {
         $dbman->create_table($table);
 
     /// Main savepoint reached
-        upgrade_main_savepoint($result, 2009011600);
+        upgrade_main_savepoint($result, 2009011900);
     }
 
 
index 84a70fafe68f9f9f2d3e951057477b10d4a976fb..81251f1ac7a8b74af0cea9805b95edd8503c373d 100644 (file)
@@ -60,7 +60,7 @@ abstract class session_stub implements moodle_session {
         global $CFG;
 
         if (!defined('NO_MOODLE_COOKIES')) {
-            if (empty($CFG->version) or $CFG->version < 2009011600) {
+            if (empty($CFG->version) or $CFG->version < 2009011900) {
                 // no session before sessions table gets greated
                 define('NO_MOODLE_COOKIES', true);
             } else if (CLI_SCRIPT) {
@@ -322,6 +322,15 @@ class database_session extends session_stub {
         global $DB;
         $this->database = $DB;
         parent::__construct();
+
+        if (!empty($this->record->state)) {
+            // something is very wrong
+            session_kill($this->record->sid);
+
+            if ($this->record->state == 9) {
+                print_error('dbsessionmysqlpacketsize', 'error');
+            }
+        }
     }
 
     protected function init_session_storage() {
@@ -372,7 +381,6 @@ class database_session extends session_stub {
                 $record->state        = 0;
                 $record->sid          = $sid;
                 $record->sessdata     = null;
-                $record->sessdatahash = null;
                 $record->userid       = 0;
                 $record->timecreated  = $record->timemodified = time();
                 $record->firstip      = $record->lastip = getremoteaddr();
@@ -415,7 +423,6 @@ class database_session extends session_stub {
                 //time out session
                 $record->state        = 0;
                 $record->sessdata     = null;
-                $record->sessdatahash = null;
                 $record->userid       = 0;
                 $record->timecreated  = $record->timemodified = time();
                 $record->firstip      = $record->lastip = getremoteaddr();
@@ -428,20 +435,7 @@ class database_session extends session_stub {
             }
         }
 
-        if ($record->sessdata !== null) {
-            if (md5($record->sessdata) !== $record->sessdatahash) {
-                // probably this is caused by misconfigured mysql - the allowed request size might be too small
-                try {
-                    $this->database->delete_records('sessions', array('sid'=>$record->sid));
-                } catch (dml_exception $ignored) {
-                }
-                print_error('dbsessionbroken', 'error');
-            }
-
-            $data = base64_decode($record->sessdata);
-        } else {
-            $data = '';
-        }
+        $data = is_null($record->sessdata) ? '' : base64_decode($record->sessdata);
 
         unset($record->sessdata); // conserve memory
         $this->record = $record;
@@ -452,36 +446,55 @@ class database_session extends session_stub {
     public function handler_write($sid, $session_data) {
         global $USER;
 
-        try {
-            if (isset($this->record->id)) {
-                $record->sid                = $sid;                         // might be regenerating sid
-                $this->record->sessdata     = base64_encode($session_data); // there might be some binary mess :-(
-                $this->record->sessdatahash = md5($this->record->sessdata);
-                $this->record->userid       = empty($USER->realuser) ? $USER->id : $USER->realuser;
-                $this->record->timemodified = time();
-                $this->record->lastip       = getremoteaddr();
+        $userid = 0;
+        if (!empty($USER->realuser)) {
+            $userid = $USER->realuser;
+        } else if (!empty($USER->id)) {
+            $userid = $USER->id;
+        }
+
+        if (isset($this->record->id)) {
+            $record->state              = 0;
+            $record->sid                = $sid;                         // might be regenerating sid
+            $this->record->sessdata     = base64_encode($session_data); // there might be some binary mess :-(
+            $this->record->userid       = $userid;
+            $this->record->timemodified = time();
+            $this->record->lastip       = getremoteaddr();
 
-                // TODO: verify session changed before doing update
+            // TODO: verify session changed before doing update
 
+            try {
                 $this->database->update_record_raw('sessions', $this->record);
+            } catch (dml_exception $ex) {
+                if ($this->database->get_dbfamily() === 'mysql') {
+                    try {
+                        $this->database->set_field('sessions', 'state', 9, array('id'=>$this->record->id));
+                    } catch (Exception $ignored) {
 
-            } else {
-                // session already destroyed
-                $record = new object();
-                $record->state        = 0;
-                $record->sid          = $sid;
-                $record->sessdata     = base64_encode($session_data); // there might be some binary mess :-(
-                $record->sessdatahash = md5($record->sessdata);
-                $record->userid       = empty($USER->realuser) ? $USER->id : $USER->realuser;
-                $record->timecreated  = $record->timemodified = time();
-                $record->firstip      = $record->lastip = getremoteaddr();
-                $record->id           = $this->database->insert_record_raw('sessions', $record);
-                $this->record = $record;
+                    }
+                    error_log('Can not write session - please verify max_packet_size is at least 4MB');
+                } else {
+                    error_log('Can not write session');
+                }
+            }
 
+        } else {
+            // session already destroyed
+            $record = new object();
+            $record->state        = 0;
+            $record->sid          = $sid;
+            $record->sessdata     = base64_encode($session_data); // there might be some binary mess :-(
+            $record->userid       = $userid;
+            $record->timecreated  = $record->timemodified = time();
+            $record->firstip      = $record->lastip = getremoteaddr();
+            $record->id           = $this->database->insert_record_raw('sessions', $record);
+            $this->record = $record;
+
+            try {
                 $this->database->get_session_lock($this->record->id);
+            } catch (dml_exception $ex) {
+                error_log('Can not write new session');
             }
-        } catch (dml_exception $ex) {
-            error_log('Can not write session');
         }
 
         return true;
index 385dce6156622389e38655044e74e504dbc996ed..68fedfb618db6c4c70654be9cca66428f23be55b 100644 (file)
@@ -4,7 +4,7 @@
     require_once("../config.php");
 
 /// check if major upgrade needed - also present in /index.php
-    if ((int)$CFG->version < 2009011600) { //1.9 or older
+    if ((int)$CFG->version < 2009011900) { //1.9 or older
         @require_logout();
         redirect("$CFG->wwwroot/$CFG->admin/");
     }
index 707ab024ddbb880653080e0695259f14cc65edb0..c035863cab9ea432aa7b6eef43d1d587326df1cb 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-    $version = 2009011600;  // YYYYMMDD   = date of the last version bump
+    $version = 2009011900;  // YYYYMMDD   = date of the last version bump
                             //         XX = daily increments
 
     $release = '2.0 dev (Build: 20090119)';  // Human-friendly version name