aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/DB/QueryBuilder/Sharded/AutoIncrementHandler.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/DB/QueryBuilder/Sharded/AutoIncrementHandler.php')
-rw-r--r--lib/private/DB/QueryBuilder/Sharded/AutoIncrementHandler.php21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/private/DB/QueryBuilder/Sharded/AutoIncrementHandler.php b/lib/private/DB/QueryBuilder/Sharded/AutoIncrementHandler.php
index caedaa71c97..3a230ea544d 100644
--- a/lib/private/DB/QueryBuilder/Sharded/AutoIncrementHandler.php
+++ b/lib/private/DB/QueryBuilder/Sharded/AutoIncrementHandler.php
@@ -108,7 +108,7 @@ class AutoIncrementHandler {
}
// discard the encoded initial shard
- $current = $this->getMaxFromDb($shardDefinition) >> 8;
+ $current = $this->getMaxFromDb($shardDefinition);
$next = max($current, self::MIN_VALID_KEY) + 1;
if ($cache->cas($shardDefinition->table, 'empty-placeholder', $next)) {
return $next;
@@ -131,19 +131,22 @@ class AutoIncrementHandler {
}
/**
- * Get the maximum primary key value from the shards
+ * Get the maximum primary key value from the shards, note that this has already stripped any embedded shard id
*/
private function getMaxFromDb(ShardDefinition $shardDefinition): int {
- $max = 0;
+ $max = $shardDefinition->fromFileId;
+ $query = $this->shardConnectionManager->getConnection($shardDefinition, 0)->getQueryBuilder();
+ $query->select($shardDefinition->primaryKey)
+ ->from($shardDefinition->table)
+ ->orderBy($shardDefinition->primaryKey, 'DESC')
+ ->setMaxResults(1);
foreach ($shardDefinition->getAllShards() as $shard) {
$connection = $this->shardConnectionManager->getConnection($shardDefinition, $shard);
- $query = $connection->getQueryBuilder();
- $query->select($shardDefinition->primaryKey)
- ->from($shardDefinition->table)
- ->orderBy($shardDefinition->primaryKey, 'DESC')
- ->setMaxResults(1);
- $result = $query->executeQuery()->fetchOne();
+ $result = $query->executeQuery($connection)->fetchOne();
if ($result) {
+ if ($result > $shardDefinition->fromFileId) {
+ $result = $result >> 8;
+ }
$max = max($max, $result);
}
}