Skip to content

Commit 9fbc4da

Browse files
authored
ENGCOM-3470: Changes cache hosts warning / critical levels and continue on multiple hosts #18852
2 parents 52d9377 + 4c27d03 commit 9fbc4da

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

app/code/Magento/CacheInvalidate/Model/PurgeCache.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ private function splitTags($tagsPattern)
118118
private function sendPurgeRequestToServers($socketAdapter, $servers, $formattedTagsChunk)
119119
{
120120
$headers = [self::HEADER_X_MAGENTO_TAGS_PATTERN => $formattedTagsChunk];
121+
$unresponsiveServerError = [];
121122
foreach ($servers as $server) {
122123
$headers['Host'] = $server->getHost();
123124
try {
@@ -131,10 +132,30 @@ private function sendPurgeRequestToServers($socketAdapter, $servers, $formattedT
131132
$socketAdapter->read();
132133
$socketAdapter->close();
133134
} catch (\Exception $e) {
134-
$this->logger->critical($e->getMessage(), compact('server', 'formattedTagsChunk'));
135+
$unresponsiveServerError[] = "Cache host: " . $server->getHost() . ":" . $server->getPort() .
136+
"resulted in error message: " . $e->getMessage();
137+
}
138+
}
139+
140+
$errorCount = count($unresponsiveServerError);
141+
142+
if ($errorCount > 0) {
143+
$loggerMessage = implode(" ", $unresponsiveServerError);
144+
145+
if ($errorCount == count($servers)) {
146+
$this->logger->critical(
147+
'No cache server(s) could be purged ' . $loggerMessage,
148+
compact('server', 'formattedTagsChunk')
149+
);
135150
return false;
136151
}
152+
153+
$this->logger->warning(
154+
'Unresponsive cache server(s) hit' . $loggerMessage,
155+
compact('server', 'formattedTagsChunk')
156+
);
137157
}
158+
138159
$this->logger->execute(compact('servers', 'formattedTagsChunk'));
139160
return true;
140161
}

lib/internal/Magento/Framework/Cache/InvalidateLogger.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use Magento\Framework\App\Request\Http as HttpRequest;
1111
use Psr\Log\LoggerInterface as Logger;
1212

13+
/**
14+
* Invalidate logger cache.
15+
*/
1316
class InvalidateLogger
1417
{
1518
/**
@@ -34,6 +37,7 @@ public function __construct(HttpRequest $request, Logger $logger)
3437

3538
/**
3639
* Logger invalidate cache
40+
*
3741
* @param mixed $invalidateInfo
3842
* @return void
3943
*/
@@ -44,6 +48,7 @@ public function execute($invalidateInfo)
4448

4549
/**
4650
* Make extra data to logger message
51+
*
4752
* @param mixed $invalidateInfo
4853
* @return array
4954
*/
@@ -65,4 +70,16 @@ public function critical($message, $params)
6570
{
6671
$this->logger->critical($message, $this->makeParams($params));
6772
}
73+
74+
/**
75+
* Log warning
76+
*
77+
* @param string $message
78+
* @param mixed $params
79+
* @return void
80+
*/
81+
public function warning($message, $params)
82+
{
83+
$this->logger->warning($message, $this->makeParams($params));
84+
}
6885
}

0 commit comments

Comments
 (0)