You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
2.3 KiB
PHTML
56 lines
2.3 KiB
PHTML
|
3 weeks ago
|
<?php
|
||
|
|
|
||
|
|
$root = dirname(__DIR__);
|
||
|
|
$lockOrder = file_get_contents(
|
||
|
|
$root . '/app/Services/Cloud/CloudVpcLockOrder.php'
|
||
|
|
);
|
||
|
|
$batch = file_get_contents(
|
||
|
|
$root . '/app/Services/Cloud/CloudVpcMembershipBatchService.php'
|
||
|
|
);
|
||
|
|
$ports = file_get_contents(
|
||
|
|
$root . '/app/Services/Cloud/CloudVpcPortService.php'
|
||
|
|
);
|
||
|
|
|
||
|
|
$assert = static function (bool $condition, string $message): void {
|
||
|
|
if (!$condition) {
|
||
|
|
throw new RuntimeException($message);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
$assert(is_string($lockOrder)
|
||
|
|
&& str_contains($lockOrder,
|
||
|
|
"'instances', 'vpc', 'ports', 'host_states', 'coordination'")
|
||
|
|
&& str_contains($lockOrder, "sort(\$ids, SORT_NUMERIC);")
|
||
|
|
&& str_contains($lockOrder, "->orderBy('id')")
|
||
|
|
&& str_contains($lockOrder, '->lockForUpdate()'),
|
||
|
|
'The canonical VPC row-lock order is missing or not executable.');
|
||
|
|
|
||
|
|
$batchInstances = strpos($batch,
|
||
|
|
'CloudVpcLockOrder::instances($instanceIds)');
|
||
|
|
$batchVpc = strpos($batch, 'CloudVpcLockOrder::vpcByKey($vpcKey)');
|
||
|
|
$assert($batchInstances !== false && $batchVpc !== false
|
||
|
|
&& $batchInstances < $batchVpc,
|
||
|
|
'Batch membership does not lock sorted instances before the VPC row.');
|
||
|
|
|
||
|
|
$detachStart = strpos($ports, 'public static function detach(');
|
||
|
|
$detachEnd = strpos($ports, 'public static function releaseAfterInstanceDeletedLocked',
|
||
|
|
$detachStart);
|
||
|
|
$detach = substr($ports, $detachStart, $detachEnd - $detachStart);
|
||
|
|
$assert(strpos($detach, 'CloudVpcLockOrder::instance(')
|
||
|
|
< strpos($detach, 'CloudVpcLockOrder::vpcById(')
|
||
|
|
&& strpos($detach, 'CloudVpcLockOrder::vpcById(')
|
||
|
|
< strpos($detach, 'CloudVpcLockOrder::portById('),
|
||
|
|
'Detach does not follow instance -> VPC -> port locking.');
|
||
|
|
|
||
|
|
$finalizerStart = strpos($ports, 'public static function finishJobLocked(');
|
||
|
|
$finalizerEnd = strpos($ports, 'public static function markJobUncertain(',
|
||
|
|
$finalizerStart);
|
||
|
|
$finalizer = substr($ports, $finalizerStart, $finalizerEnd - $finalizerStart);
|
||
|
|
$assert(strpos($finalizer, 'CloudVpcLockOrder::instance(')
|
||
|
|
< strpos($finalizer, 'CloudVpcLockOrder::vpcById(')
|
||
|
|
&& strpos($finalizer, 'CloudVpcLockOrder::vpcById(')
|
||
|
|
< strpos($finalizer, 'CloudVpcLockOrder::portById('),
|
||
|
|
'VPC finalization does not follow instance -> VPC -> port locking.');
|
||
|
|
|
||
|
|
echo "Canonical VPC database lock order contract passed.\n";
|