Documentation

ShardManager

Sharding Manager gives access to APIs to implementing sharding on top of Doctrine\DBAL\Connection instances.

For simplicity and developer ease-of-use (and understanding) the sharding API only covers single shard queries, no fan-out support. It is primarily suited for multi-tenant applications.

The assumption about sharding here is that a distribution value can be found that gives access to all the necessary data for all use-cases. Switching between shards should be done with caution, especially if lazy loading is implemented. Any query is always executed against the last shard that was selected. If a query is created for a shard Y but then a shard X is selected when its actually executed you will hit the wrong shard.

Tags
author

Benjamin Eberlei kontakt@beberlei.de

Table of Contents

getCurrentDistributionValue()  : string
Gets the distribution value currently used for sharding.
getShards()  : array<string|int, mixed>
Gets information about the amount of shards and other details.
queryAll()  : array<string|int, mixed>
Queries all shards in undefined order and return the results appended to each other. Restore the previous distribution value after execution.
selectGlobal()  : void
Selects global database with global data.
selectShard()  : void
Selects the shard against which the queries after this statement will be issued.

Methods

getCurrentDistributionValue()

Gets the distribution value currently used for sharding.

public getCurrentDistributionValue() : string
Return values
string —

getShards()

Gets information about the amount of shards and other details.

public getShards() : array<string|int, mixed>

Format is implementation specific, each shard is one element and has an 'id' attribute at least.

Return values
array<string|int, mixed> —

queryAll()

Queries all shards in undefined order and return the results appended to each other. Restore the previous distribution value after execution.

public queryAll(string $sql, array<string|int, mixed> $params, array<string|int, mixed> $types) : array<string|int, mixed>

Using to retrieve rows internally.

Parameters
$sql : string
$params : array<string|int, mixed>
$types : array<string|int, mixed>
Return values
array<string|int, mixed> —

selectGlobal()

Selects global database with global data.

public selectGlobal() : void

This is the default database that is connected when no shard is selected.

Return values
void —

selectShard()

Selects the shard against which the queries after this statement will be issued.

public selectShard(string $distributionValue) : void
Parameters
$distributionValue : string
Tags
throws
ShardingException

If no value is passed as shard identifier.

Return values
void —

Search results