mysql — Ошибка чтения / записи базы данных с высоким трафиком PHP Laravel Aurora

Итак, у нас есть приложение php laravel 5, которое читает / записывает в AWS Aurora DB примерно 1500-2000 раз в минуту. Он делает простой выбор, а затем обновляет значение в столбце.

Однако мы получаем некоторые ошибки при попытке обновления значения время от времени. (1 из 500 будет ошибка)

[2015-11-13 09:15:00] live.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to a member function update() on null

Это наш код

// Get the first free token sorted by the biggest ID to the smallest.
$token = TokenModel::where('expire_at', '>', Carbon::now())
->where('status', 'Free')
->orderBy('id', 'DESC')
->lockForUpdate()
->first();

// Update the status of the token.
$token->update(['status' => 'Used']);

Мы попытались удалить / добавить lockForUpdate() однако это не решает проблему.

Кто-нибудь когда-нибудь сталкивался с этой проблемой раньше?

Обновления:

    $token = null;

while ($token == null) {
// Get the first free token sorted by the biggest ID to the smallest.
$token = TokenModel::where('expire_at', '>', Carbon::now())
->where('status', 'Free')
->orderBy('id', 'DESC')
->lockForUpdate()
->first();
}

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …