Class for managing connections to the DB shards.
This shard manager allows registering multiple shards and request connections to them. It ensures that only one connection to a shard is used within a request.
| Properties | |
|---|---|
|
protected
|
Internal array for storing the load balancing groups and its shards. |
|
protected
|
Internal array for storing the mapping between shard names and connection parameters. |
| Methods | |
|---|---|
|
public
|
The method provides the DBWorker object for working with the shard. |
|
public
|
The method provides the DBWorker object for working with the shard, that is chosen randomly for load balancing reason. |
|
public
|
Registers a new shard. |
Internal array for storing the load balancing groups and its shards.
Internal array for storing the mapping between shard names and connection parameters.
The method provides the DBWorker object for working with the shard.
If the parameters are omitted, the system takes the parameters from the configuration settings and reuses the single instance of the DBWorker for all requests. If the user passes the parameters explicitly, a new instance of the DBWorker is created upon each new request.
Currently supported: MySQL, PostgreSQL und MS SQL.
| Name | Pass type | Value type | Default value | Description |
|---|---|---|---|---|
| $shard_name | by value | string |
The name of the shard. |
returns DBWorker object or null if the object could not be created.
It might throw an exception in the case of any errors:
The method provides the DBWorker object for working with the shard, that is chosen randomly for load balancing reason.
| Name | Pass type | Value type | Default value | Description |
|---|---|---|---|---|
| $load_balancing_group | by value | string |
The name of the load balancing group, from which the shard should be randomly picked. |
returns DBWorker object or null if the object could not be created.
It might throw an exception in the case of any errors:
Registers a new shard.
| Name | Pass type | Value type | Default value | Description |
|---|---|---|---|---|
| $shard_name | by value | string |
Unique shard name. |
|
| $parameters | by value | array |
The connection parameters to the shard as an associative array in the form key => value:
|
|
| $load_balancing_group | by value | string | "" |
The name of the load balancing group, if the shard should be part of it, \SmartFactory\DatabaseWorkers\ShardManager::randomDBShard(). |
It should return true if the registering was successful, otherwise false.
It might throw an exception in the case of any errors: