fix(storage): require distinct catalog failure domains

go
codex 2 weeks ago
parent f5cc5afe6c
commit 7dc7e31160

@ -55,6 +55,34 @@ final class CloudStoragePlacementPolicy
throw new CloudError('健康且已验证的对象存储后端数量不足', 503);
}
// A required-two catalog artifact is not protected when both objects
// live in the same provider/failure domain. Do not silently trade the
// frozen durability contract for placement availability. Backups use
// requiredCopies=1 and retain the best-effort same-domain fallback
// below for their asynchronous secondary.
if ($requiredCopies > 1) {
$selected = [];
$domains = [];
foreach ($healthy as $backend) {
$domain = self::domain($backend);
if (isset($domains[$domain])) {
continue;
}
$selected[] = $backend;
$domains[$domain] = true;
if (count($selected) >= $desiredCopies) {
break;
}
}
if (count($selected) < $requiredCopies) {
throw new CloudError(
'健康对象存储后端缺少独立故障域',
503
);
}
return $selected;
}
// The primary must always be writable now. For an asynchronous
// required-one artifact, however, reserve a second active/tested
// backend even while it is unhealthy. Its copy operation remains

@ -125,6 +125,16 @@ $backends = [
$placed = CloudStoragePlacementPolicy::select($backends, 2, 2);
$assert(array_column($placed, 'id') === [1, 2],
'Placement must prefer a distinct failure domain over a lower-priority peer.');
$sameDomainRequired = [$backends[0], $backends[2]];
try {
CloudStoragePlacementPolicy::select($sameDomainRequired, 2, 2);
$assert(false,
'Required-two placement accepted two backends in one failure domain.');
} catch (CloudError $error) {
$assert($error->httpStatus === 503
&& $error->getMessage() === '健康对象存储后端缺少独立故障域',
'Same-domain required placement did not fail as an explicit 503.');
}
$backends[1]['health_state'] = 'unreachable';
$backupPlacement = CloudStoragePlacementPolicy::select($backends, 2, 1);
$assert(array_column($backupPlacement, 'id') === [1, 3],

Loading…
Cancel
Save