Skip to content

Commit

Permalink
Make it possible to create local and cluster sharded tables together
Browse files Browse the repository at this point in the history
  • Loading branch information
donhardman committed Dec 15, 2023
1 parent dae7819 commit 7b2becb
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Sharding/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Manticoresearch\Buddy\Base\Sharding;

use Ds\Map;
use Ds\Vector;
use Manticoresearch\Buddy\Core\ManticoreSearch\Client;
use Manticoresearch\Buddy\Core\Tool\Buddy;
Expand Down Expand Up @@ -140,11 +139,12 @@ protected function executeQuery(array $query): string {
*/
protected function attemptToUpdateStatus(array $query, string $status, int $duration): bool {
$isOk = $this->updateStatus($query['id'], $status, $query['tries'] + 1, $duration);
if (!$isOk) {
Buddy::debug("Failed to update queue status for {$query['id']}");
return false;
if ($isOk) {
return true;
}
return true;

Buddy::debug("Failed to update queue status for {$query['id']}");
return false;
}

/**
Expand Down Expand Up @@ -172,7 +172,7 @@ protected function dequeue(Node $node): Vector {
$res = $this->client->sendRequest($query)->getResult();
$queries = new Vector;
foreach ($res[0]['data'] as $row) {
$queries->push(new Map($row));
$queries->push($row);
}

return $queries;
Expand All @@ -197,8 +197,10 @@ protected function updateStatus(int $id, string $status, int $tries, int $durati

$rows = implode(', ', $update);
$q = "UPDATE {$table} SET {$rows} WHERE `id` = {$id}";
/** @var array{0:array{error:string}}|array{error:string} $result */
$result = $this->client->sendRequest($q)->getResult();
return !$result['error'];
$error = $result[0]['error'] ?? ($result['error'] ?? '');
return !$error;
}

/**
Expand Down

0 comments on commit 7b2becb

Please sign in to comment.