The docs specify in your models you can use:
var $useDbConfig = 'default';
which will find a matching variable in DATABASE_CONFIG and use the connection settings.
in database.php
class DATABASE_CONFIG {
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'port' => '',
'login' => 'myuser',
'password' => 'yeahright',
'database' => 'mycake',
'schema' => '',
'prefix' => '',
'encoding' => ''
);
...
}
Note: Difference between Sharding and Partitioning is shards resides on different servers. However both separate data depending on some field or attribute.
So to make this dynamic you start in bootstrap.php and create a hashing alg like this to separate your data:
$shardId = $id % 10;The next change you make is in database.php.
$shardHostArray = array(5 => '192.168.0.25');
Configure::write('shard.host', $shardHostArray[5]);
or a
define('SHARDHOST', $shardHostArray[5]);
Add a constructor to class DATABASE_CONFIG
public function __construct()Now when you have a model in cakephp such as GroupModel that you want to shard. You specify:
{
$this->shard = $this->default;
$this->shard['host'] = SHARDHOST;
}
var $useDbConfig = 'shard'; // this is the name of a class member inAnd the correct server address will be used. This allows you to stay within the cakephp conventions and not break the schema caching.
// DATABASE_CONFIG. I created this var in
// the above constructor.
1 comment:
can you explain more about the selector hash.. Thanks
Post a Comment