Closed wajda closed 1 week ago
@vishalag001
Oh, there must be a really high concurrency if that happens :)
Can we ignore the _rev match validation
No, the _rev
validation is essential. The nextTxNumber()
function is supposed to behave as increment and get. The issue is that for an unknown reason it is missing a loop that should repeat update attempts until it either succeeds or exceeds the max attempts threshold, and only then it should fail.
Since you are running a development version I assume you have the source code and know how to build it. Can you please try to modify the nextTxNumber()
function in the tx-manager-impl.ts
to something like the below and test it again? That would be helpful as I don't have a highly concurrent setup for a decent test to experiment with.
Try to play with it and when it works, create a pull-request please.
private nextTxNumber(): TxNum {
let attempts: number = 10 // Max attempts to atomically increment the counter
while (attempts-- > 0) {
try {
const curCnt: Counter = store.getDocByKey(CollectionName.Counter, 'tx')
// as of time of writing the '@types/arangodb:3.5.13' was the latest version,
// and it was not up-to-date with ArangoDB 3.10+ JavaScript API
// @ts-ignore
const updResult: UpdateResult<Counter> = db._update(
curCnt,
{
curVal: curCnt.curVal + 1
},
// @ts-ignore
{
overwrite: false, // check _rev
returnNew: true // return an updated document in the `new` attribute
}
)
const newCnt: Counter = updResult.new
return newCnt.curVal
}
catch (e) {
if (e['errorNum'] !== 1200) throw e
}
}
}
Discussed in https://github.com/AbsaOSS/spline/discussions/1299