| 1 |
<?php |
| 2 |
/** |
| 3 |
* Pure database host-state error taxonomy. |
| 4 |
* |
| 5 |
* Owns string-based classification of server-side state failures: storage |
| 6 |
* exhaustion (disk, quota, memory), write-blocking modes (read-only, |
| 7 |
* Galera optimistic-concurrency conflicts), and access-control rejections |
| 8 |
* (access denied, missing SUPER privilege for SET STATEMENT). These are the |
| 9 |
* error classes the notice-state side-effects and "permanent host-side |
| 10 |
* staged failure" policies act on. |
| 11 |
* |
| 12 |
* No side effects: callers reuse the matchers without inheriting recovery |
| 13 |
* behavior. |
| 14 |
*/ |
| 15 |
|
| 16 |
if (!defined('ABSPATH')) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
// allow-no-test-found: covered through DatabaseInfrastructureErrorTaxonomy facade by tests/ErrorClassifierTest.php and tests/StagedBuildHostQuirksTest.php |
| 21 |
class ABJ_404_Solution_DatabaseHostStateErrorTaxonomy { |
| 22 |
|
| 23 |
/** @var ABJ_404_Solution_Functions */ |
| 24 |
private $f; |
| 25 |
|
| 26 |
/** |
| 27 |
* @param ABJ_404_Solution_Functions $functions |
| 28 |
*/ |
| 29 |
public function __construct($functions) { |
| 30 |
$this->f = $functions; |
| 31 |
} |
| 32 |
|
| 33 |
/** @param string $errorText @return bool */ |
| 34 |
public function isDiskFullError(string $errorText): bool { |
| 35 |
if ($errorText === '') { |
| 36 |
return false; |
| 37 |
} |
| 38 |
$lower = strtolower($errorText); |
| 39 |
return ($this->f->strpos($lower, 'error 28') !== false || |
| 40 |
$this->f->strpos($lower, 'errno: 28') !== false || |
| 41 |
$this->f->strpos($lower, 'errcode: 28') !== false || |
| 42 |
$this->f->strpos($lower, 'no space left on device') !== false || |
| 43 |
$this->f->strpos($lower, "' is full") !== false || |
| 44 |
$this->f->strpos($lower, 'table is full') !== false || |
| 45 |
$this->f->strpos($lower, 'disk full') !== false); |
| 46 |
} |
| 47 |
|
| 48 |
/** @param string $errorText @return bool */ |
| 49 |
public function isReadOnlyError(string $errorText): bool { |
| 50 |
if ($errorText === '') { |
| 51 |
return false; |
| 52 |
} |
| 53 |
$lower = strtolower($errorText); |
| 54 |
return ($this->f->strpos($lower, 'read only') !== false || |
| 55 |
$this->f->strpos($lower, 'read-only') !== false || |
| 56 |
$this->f->strpos($lower, 'super_read_only') !== false); |
| 57 |
} |
| 58 |
|
| 59 |
/** @param string $errorText @return bool */ |
| 60 |
public function isQuotaLimitError(string $errorText): bool { |
| 61 |
if ($errorText === '') { |
| 62 |
return false; |
| 63 |
} |
| 64 |
$lower = strtolower($errorText); |
| 65 |
return ($this->f->strpos($lower, 'max_questions') !== false || |
| 66 |
$this->f->strpos($lower, 'resource') !== false && $this->f->strpos($lower, 'question') !== false); |
| 67 |
} |
| 68 |
|
| 69 |
/** @param string $errorText @return bool */ |
| 70 |
public function isAccessDeniedError(string $errorText): bool { |
| 71 |
if ($errorText === '') { |
| 72 |
return false; |
| 73 |
} |
| 74 |
$lower = strtolower($errorText); |
| 75 |
return ($this->f->strpos($lower, 'access denied') !== false || |
| 76 |
$this->f->strpos($lower, 'command denied') !== false); |
| 77 |
} |
| 78 |
|
| 79 |
/** @param string $errorText @return bool */ |
| 80 |
public function isOutOfMemoryError(string $errorText): bool { |
| 81 |
if ($errorText === '') { |
| 82 |
return false; |
| 83 |
} |
| 84 |
$lower = strtolower($errorText); |
| 85 |
return ($this->f->strpos($lower, 'allowed memory size') !== false || |
| 86 |
$this->f->strpos($lower, 'out of memory') !== false || |
| 87 |
$this->f->strpos($lower, 'memory exhausted') !== false || |
| 88 |
$this->f->strpos($lower, 'memory_limit') !== false); |
| 89 |
} |
| 90 |
|
| 91 |
/** @param string $errorText @return bool */ |
| 92 |
public function isGaleraConflictError(string $errorText): bool { |
| 93 |
if ($errorText === '') { |
| 94 |
return false; |
| 95 |
} |
| 96 |
$lower = strtolower($errorText); |
| 97 |
return ($this->f->strpos($lower, 'record has changed since last read') !== false || |
| 98 |
$this->f->strpos($lower, 'wsrep_local_state') !== false || |
| 99 |
$this->f->strpos($lower, 'cluster conflict') !== false); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* True when a failed SET STATEMENT max_statement_time wrapper can be |
| 104 |
* stripped and retried. |
| 105 |
* |
| 106 |
* @param string $errorText |
| 107 |
* @return bool |
| 108 |
*/ |
| 109 |
public function classifySetStatementFailure(string $errorText): bool { |
| 110 |
if ($errorText === '') { |
| 111 |
return false; |
| 112 |
} |
| 113 |
$lower = strtolower($errorText); |
| 114 |
if ($this->f->strpos($lower, 'super privilege') !== false || |
| 115 |
$this->f->strpos($lower, 'super_privilege') !== false || |
| 116 |
$this->f->strpos($lower, '(at least one of) the super') !== false) { |
| 117 |
return true; |
| 118 |
} |
| 119 |
if (($this->f->strpos($lower, 'syntax error') !== false || |
| 120 |
$this->f->strpos($lower, 'error in your sql syntax') !== false || |
| 121 |
$this->f->strpos($lower, '1064') !== false) && |
| 122 |
$this->f->strpos($lower, 'set statement') !== false) { |
| 123 |
return true; |
| 124 |
} |
| 125 |
return false; |
| 126 |
} |
| 127 |
} |
| 128 |
|