Prevent concurrency issues on small system

Serializable isolation level is not really useful for a job system,
where we insert/update many rows
This commit is contained in:
Chocobozzz
2026-05-19 16:27:01 +02:00
parent a34262a3a8
commit 630f0599a8
2 changed files with 7 additions and 3 deletions
+5 -2
View File
@@ -68,11 +68,14 @@ export function transactionRetryer<T> (func: (err: any, data: T) => any) {
})
}
export function saveInTransactionWithRetries<T extends Pick<Model, 'save' | 'changed'>> (model: T) {
export function saveInTransactionWithRetries<T extends Pick<Model, 'save' | 'changed'>> (
model: T,
isolationLevel: Transaction.ISOLATION_LEVELS = Transaction.ISOLATION_LEVELS.SERIALIZABLE
) {
const changedKeys = model.changed() || []
return retryTransactionWrapper(() => {
return sequelizeTypescript.transaction(async transaction => {
return sequelizeTypescript.transaction({ isolationLevel }, async transaction => {
try {
await model.save({ transaction })
} catch (err) {
@@ -28,6 +28,7 @@ import { PeerTubeSocket } from '@server/lib/peertube-socket.js'
import { RunnerJobModel } from '@server/models/runner/runner-job.js'
import { setAsUpdated } from '@server/models/shared/update.js'
import { MRunnerJob } from '@server/types/models/runners/index.js'
import { Transaction } from 'sequelize'
type CreateRunnerJobArg =
| {
@@ -98,7 +99,7 @@ export abstract class AbstractJobHandler<C, U extends RunnerJobUpdatePayload, S
priority
})
await saveInTransactionWithRetries(runnerJob)
await saveInTransactionWithRetries(runnerJob, Transaction.ISOLATION_LEVELS.READ_COMMITTED)
if (runnerJob.state === RunnerJobState.PENDING) {
PeerTubeSocket.Instance.sendAvailableJobsPingToRunners()