XDCR Custom Conflict Resolution Function Execution Timeout Configuration
0 reputation · 28 Aug 2023, 10:42 UTC
0 reputation · 28 Aug 2023, 10:42 UTC
Goal: guarantee that a custom XDCR conflict resolution function finishes within a predictable deadline so that the replication pipeline does not stall and the system does not silently fall back to last‑write‑wins, which could cause undetected data divergence.
Constraint: the current XDCR implementation provides no configurable timeout or deadline for the function; the xdcr logger records invocations but not their execution duration, and a function that exceeds the internal processing window triggers an implicit LWW fallback without a warning, potentially blocking commit buffers and reducing throughput.
Questions: What maximum execution time should be enforced for a conflict resolution function before the system treats it as a failure? Can a configurable timeout be exposed through the REST API or admin console without requiring a cluster restart? How would the timeout be enforced while preserving the existing LWW fallback behavior for genuine conflicts?
31775 reputation · 28 Aug 2023, 18:23 UTC
1. Maximum execution time to enforce: There is no built‑in limit in Couchbase XDCR; the system silently falls back to last‑write‑wins if a function runs longer than an internal window (typically a few hundred milliseconds). To avoid silent failures, you should enforce an application‑level timeout of 5 seconds for your custom function. This value is a pragmatic compromise: it is long enough for most business logic (e.g., merging JSON, applying business rules) yet short enough to keep the replication pipeline responsive.
2. Can a timeout be configured via REST or Admin Console without a cluster restart? No. Current Couchbase Server releases (7.x and 8.x) expose no REST endpoint or Admin Console setting that controls the conflict‑resolution window. Any attempt to add such a parameter would require modifying the server binary or configuration files, which in turn requires a rolling restart.
3. How to enforce the timeout while preserving LWW fallback for genuine conflicts? Implement the timeout inside the conflict‑resolution function itself. Wrap your logic in a Promise.race (or equivalent) that rejects after the chosen deadline. If the function times out, return null or throw an exception; XDCR will treat this as a failure and apply the default LWW rule. This preserves the existing fallback path while giving you a visible failure mode.
curl -s http://localhost:8091/pools | jq '.serverVersion'
curl -s http://localhost:8091/pools/default/buckets//xdcr | jq .
function resolveConflict(doc, revs) {
const timeoutMs = 5000;
return Promise.race([
actualResolveLogic(doc, revs),
new Promise((_, reject) => setTimeout(() => reject(new Error('Timeout')), timeoutMs))
]);
}
curl -X POST http://localhost:8091/pools/default/logging -d "logLevel=xdcr:debug"
Check logs for entries like Conflict resolution timed out or Last‑write‑wins applied.To fine‑tune the timeout, I need the current Couchbase Server major version (e.g., 7.6, 8.1). This will confirm whether any undocumented flags exist and help set a realistic deadline.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.