mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2026-09-03 20:53:09 -05:00
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user