5. Nuvola e i suoi 50GB
• Difficoltà di manutenzione (backup/ripristino)
• Difficoltà di evoluzione (alter dello schema)
• Impossibile replicare il sistema (debug)
7. Applicazioni multi
tenant
“Multi-tenant si riferisce ad una architettura
software in cui una singola istanza del suddetto
software gira su un server ed è utilizzata da più di
una client organization (tenant)”.
– wikipedia
9. Sharding
A database shard is a horizontal partition of data
in a database. Each individual partition is referred
to as a shard or database shard. Each shard is
held on a separate database server instance, to
spread load.
– wikipedia
17. Sharding con Doctrine
Starting with 2.3 Doctrine DBAL contains some
functionality to simplify the development of
horizontally sharded applications.
!
In this first release it contains a ShardManager
interface. This interface allows to programatically
select a shard to send queries to.
- http://doctrine-dbal.readthedocs.org/en/latest/reference/sharding.html
18. Sharding con Doctrine
At the moment there are no functionalities yet to
dynamically pick a shard based on ID, query or
database row yet
- http://doctrine-dbal.readthedocs.org/en/latest/reference/sharding.html
19. ShardManager Interface
$shardManager = new PoolingShardManager($conn);
!
$currentCustomerId = 1234;
$shardManager->selectShard($currentCustomerId);
// all queries after this call hit the shard
// where customer with id 1234 is on.
!
$shardManager->selectGlobal();
// the global database is selected.
46. Switch della connessione
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
!
$this->shardManager->selectShard(
$this->session->get(‘shard')
);
}
48. Configurare gli shards
protected function configure()
{
$this->setName('nuvola:shard:add-config')
->setDescription('Aggiunge la configurazione
necessaria ad uno shard')
->addOption('host', null, InputOption::VALUE_OPTIONAL,
'L'host della connessione al db')
->addOption('codiceMeccanografico', null,
InputOption::VALUE_OPTIONAL, 'Codice meccanografico per lo
shard');
}
49. Configurare gli shards
protected function configure()
{
$this->setName('nuvola:shard:create-config')
->setDescription('Crea il file di configurazione per gli
shards')
->addOption(
'append',
null,
InputOption::VALUE_NONE,
'Se impostato a false cancella la configurazione attuale,
altrimenit la aggiunge. Default a true'
)
//CUT
}
50. Ad ognuno il suo shard
public function onConsoleCommand(ConsoleCommandEvent $event)
{
$shardManager = new SafeShardManager($connection);
$istituto = $input->getParameterOption(['--istituto', '-i']);
!
if ('global' === $istituto) {
$shardManager->selectGlobal();
} else {
$shardManager->selectShard($istituto);
}
!
}
51. Ciclare gli shards
class ListShardsCommand extends AbstractShardCommand
{
protected function configure()
{
$this->setName('nuvola:shard:list-shards')
->setDescription('Restituisce l'elenco degli shard configurati')
->addOption(
'letteraInizioIntervallo',
null,
InputOption::VALUE_OPTIONAL,
'Lettera di inizio intervallo per lo shard da esportare (estremo
compreso)'
)
->addOption(
'letteraFineIntervallo',
null,
InputOption::VALUE_OPTIONAL,
'Lettera di fine intervallo per lo shard da esportare (estremo compreso)'
);
}
}
52. Ciclare gli shards
app/console nu:sha:li | while read
shard; do app/console doctrine:mig:mig -
i $shard -n;done;