Improve redlock non executed response
This commit is contained in:
parent
37935112a4
commit
e584d82e6f
|
@ -44,6 +44,15 @@ docWritethroughProcessorQueue.process(async message => {
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!lockResponse.executed) {
|
if (!lockResponse.executed) {
|
||||||
|
if (
|
||||||
|
lockResponse.reason !==
|
||||||
|
locks.UnsuccessfulRedlockExecutionReason.LockTakenWithTryOnce
|
||||||
|
) {
|
||||||
|
console.error("Error persisting docWritethrough", {
|
||||||
|
data: message.data,
|
||||||
|
})
|
||||||
|
throw "Error persisting docWritethrough"
|
||||||
|
}
|
||||||
console.log(`Ignoring redlock conflict in write-through cache`)
|
console.log(`Ignoring redlock conflict in write-through cache`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -82,6 +82,11 @@ type SuccessfulRedlockExecution<T> = {
|
||||||
}
|
}
|
||||||
type UnsuccessfulRedlockExecution = {
|
type UnsuccessfulRedlockExecution = {
|
||||||
executed: false
|
executed: false
|
||||||
|
reason: UnsuccessfulRedlockExecutionReason
|
||||||
|
}
|
||||||
|
|
||||||
|
export const enum UnsuccessfulRedlockExecutionReason {
|
||||||
|
LockTakenWithTryOnce = "LOCK_TAKEN_WITH_TRY_ONCE",
|
||||||
}
|
}
|
||||||
|
|
||||||
type RedlockExecution<T> =
|
type RedlockExecution<T> =
|
||||||
|
@ -141,7 +146,10 @@ export async function doWithLock<T>(
|
||||||
if (opts.type === LockType.TRY_ONCE) {
|
if (opts.type === LockType.TRY_ONCE) {
|
||||||
// don't throw for try-once locks, they will always error
|
// don't throw for try-once locks, they will always error
|
||||||
// due to retry count (0) exceeded
|
// due to retry count (0) exceeded
|
||||||
return { executed: false }
|
return {
|
||||||
|
executed: false,
|
||||||
|
reason: UnsuccessfulRedlockExecutionReason.LockTakenWithTryOnce,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue