chore(index): Few adjustments (#12557)

**What**
- Adjust lock duration, it is in seconds and not in ms
- Log on lock release 
- Renew lock separately from the other promises
- Add more logs 
  - Log when lock can't be acquired. It can be expected in case two processes try to sync the same entity and in that case it can be ignored. But at least it gives some information in case it happens for another reason
  - Log when the release lock failed, the lock will remain in the locking provider for 1 minute before being removed. But it wont prevent other entities to be synced
This commit is contained in:
Adrien de Peretti
2025-05-21 15:06:35 +00:00
committed by GitHub
parent 22687d694e
commit 499381d119
5 changed files with 65 additions and 35 deletions
@@ -85,12 +85,13 @@ export class DataSynchronizer {
fields: string
fields_hash: string
}[],
lockDuration: number = 1000 * 60 * 5
lockDuration: number = 60 // 1 minute
) {
this.#isReadyOrThrow()
const entitiesToSync = entities.map((entity) => entity.entity)
this.#orchestrator = new Orchestrator(this.#locking, entitiesToSync, {
lockDuration,
logger: this.#logger,
})
await this.#orchestrator.process(this.#taskRunner.bind(this))
}
@@ -156,26 +157,23 @@ export class DataSynchronizer {
ack: async (ack) => {
const endTime = performance.now()
const chunkElapsedTime = (endTime - chunkStartTime).toFixed(2)
const promises: Promise<any>[] = []
if (ack.lastCursor) {
this.#logger.debug(
`[Index engine] syncing entity '${entity}' updating last cursor to ${ack.lastCursor} (+${chunkElapsedTime}ms)`
)
promises.push(
this.#indexSyncService.update({
data: {
last_key: ack.lastCursor,
},
selector: {
entity,
},
})
)
await this.#indexSyncService.update({
data: {
last_key: ack.lastCursor,
},
selector: {
entity,
},
})
if (!ack.done && !ack.err) {
promises.push(this.#orchestrator.renewLock(entity))
await this.#orchestrator.renewLock(entity)
}
}
@@ -192,8 +190,6 @@ export class DataSynchronizer {
)
}
await promiseAll(promises)
chunkStartTime = performance.now()
},
})