ShardManager.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Doctrine\DBAL\Sharding;
  3. /**
  4. * Sharding Manager gives access to APIs to implementing sharding on top of
  5. * Doctrine\DBAL\Connection instances.
  6. *
  7. * For simplicity and developer ease-of-use (and understanding) the sharding
  8. * API only covers single shard queries, no fan-out support. It is primarily
  9. * suited for multi-tenant applications.
  10. *
  11. * The assumption about sharding here
  12. * is that a distribution value can be found that gives access to all the
  13. * necessary data for all use-cases. Switching between shards should be done with
  14. * caution, especially if lazy loading is implemented. Any query is always
  15. * executed against the last shard that was selected. If a query is created for
  16. * a shard Y but then a shard X is selected when its actually executed you
  17. * will hit the wrong shard.
  18. */
  19. interface ShardManager
  20. {
  21. /**
  22. * Selects global database with global data.
  23. *
  24. * This is the default database that is connected when no shard is
  25. * selected.
  26. *
  27. * @return void
  28. */
  29. public function selectGlobal();
  30. /**
  31. * Selects the shard against which the queries after this statement will be issued.
  32. *
  33. * @param string $distributionValue
  34. *
  35. * @return void
  36. *
  37. * @throws ShardingException If no value is passed as shard identifier.
  38. */
  39. public function selectShard($distributionValue);
  40. /**
  41. * Gets the distribution value currently used for sharding.
  42. *
  43. * @return string|null
  44. */
  45. public function getCurrentDistributionValue();
  46. /**
  47. * Gets information about the amount of shards and other details.
  48. *
  49. * Format is implementation specific, each shard is one element and has an
  50. * 'id' attribute at least.
  51. *
  52. * @return mixed[][]
  53. */
  54. public function getShards();
  55. /**
  56. * Queries all shards in undefined order and return the results appended to
  57. * each other. Restore the previous distribution value after execution.
  58. *
  59. * Using {@link \Doctrine\DBAL\Connection::fetchAll} to retrieve rows internally.
  60. *
  61. * @param string $sql
  62. * @param mixed[] $params
  63. * @param int[]|string[] $types
  64. *
  65. * @return mixed[]
  66. */
  67. public function queryAll($sql, array $params, array $types);
  68. }