Zend Framework

metadata cache identifier collisions

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.8.3
  • Fix Version/s: 1.9.3
  • Component/s: Zend_Db_Table
  • Labels:
    None

Description

The cache identifier where the metadata are saved is not unique:

  • schema is not mandatory, so if you have two databases with a same table name in both and you haven't set the schema it will generate the same id.
  • you can connect to databases on different host or port and it's also not include in the id so there are collisions.
Zend/Db/Table/Abstract.php
$cacheId = md5("$this->_schema.$this->_name");

should be replace to :

//get db configuration
$dbConfig = $this->_db->getConfig();

//get the port if available 
$port = isset($dbConfig['options']['port']) ? ':'.$dbConfig['options']['port'] : null;

//get the custom schema or the default schema if not specified
$schema = !empty($this->_schema) ? $this->_schema : $dbConfig['dbname'];

// Define the cache identifier where the metadata are saved
$cacheId = md5($dbConfig['host'].$port.'/'.$schema.'.'.$this->_name);

Activity

Hide
Mickael Perraud added a comment - - edited

Exactly the same for me today

But with your correction, we can't have same schema in different database on same server.

I choose:

// If $this has a metadata cache
if (null !== $this->_metadataCache) {
    //get db configuration
    $dbConfig = $this->_db->getConfig();

    //get the port if available
    $port = isset($dbConfig['options']['port']) ? ':'.$dbConfig['options']['port'] : null;

    //get the host if available
    $host = isset($dbConfig['options']['host']) ? ':'.$dbConfig['options']['host'] : null;

    // Define the cache identifier where the metadata are saved
    $cacheId = md5($host.$port.'/'.$dbConfig['dbname'].':'.$this->_schema.'.'.$this->_name);
}
Show
Mickael Perraud added a comment - - edited Exactly the same for me today But with your correction, we can't have same schema in different database on same server. I choose:
// If $this has a metadata cache
if (null !== $this->_metadataCache) {
    //get db configuration
    $dbConfig = $this->_db->getConfig();

    //get the port if available
    $port = isset($dbConfig['options']['port']) ? ':'.$dbConfig['options']['port'] : null;

    //get the host if available
    $host = isset($dbConfig['options']['host']) ? ':'.$dbConfig['options']['host'] : null;

    // Define the cache identifier where the metadata are saved
    $cacheId = md5($host.$port.'/'.$dbConfig['dbname'].':'.$this->_schema.'.'.$this->_name);
}
Hide
Ralph Schindler added a comment -

Used patch supplied.

Fixed in trunk in 17819, and merged to release branch 1.9 in 17820

Show
Ralph Schindler added a comment - Used patch supplied. Fixed in trunk in 17819, and merged to release branch 1.9 in 17820

People

Vote (2)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
15m
Original Estimate - 15 minutes
Remaining:
15m
Remaining Estimate - 15 minutes
Logged:
Not Specified
Time Spent - Not Specified