cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

cdc: cluster instability when sink is unavailable

Open shermanCRL opened this issue 5 years ago • 4 comments

A cluster can OOM when a sink is unavailable. This issue was motivated by a customer’s experience.

A changefeed problem should not become a cluster problem. It’s better to pause or kill a changefeed than to destabilize a cluster.

Presumably, this happens because changes are buffered without limit when the sink cannot receive them. This unavailability might be a network partition, a crash of the sink (broker), or an error which prevents the feed from being consumed.

Solutions might include:

  • A cap on the number of retries (perhaps with backoff)
  • A cap on the number of buffered bytes

We would need a definition of ‘fatal’ when these caps are reached, i.e., the changefeed is considered dead. Perhaps there is a graceful version, where the feed is paused-but-recoverable, so long as changes have not been GC’d.

See also https://github.com/cockroachdb/cockroach/issues/36917

gz#8053

Jira issue: CRDB-3155

shermanCRL avatar Feb 17 '21 19:02 shermanCRL

I'd like to also entertain the definition of 'fatal' where we block (or apply backpressure to) writes to the targeted cdb table. Changefeeds are part of a distributed system and thus subject to the CAP theorem, so when a sink is unavailable we have three choices:

  • Sacrifice Consistency: The changefeed dies or is paused. Writes continue, allowing any downstream consumers of the feed to drift out of sync.
  • Sacrifice Availability: Writes to the table start failing with an error that clearly explains what's going on with the changefeed. The downstream consumers are a bounded amount out of sync, with the changefeed's high-water-mark being a legible bound.
  • Sacrifice Partition Tolerance: The buffer grows indefinitely until either the sink becomes available or the cluster runs out of memory. This is the current behavior.

We definitely have users who would prefer the first option, and almost certainly have users who would prefer the second, so probably ideally this would be configurable.

HonoreDB avatar Feb 17 '21 20:02 HonoreDB

I'm not fully aware of changefeed internals, but I would like to propose a solution to have a effectively unlimited buffer:

  1. Define a threshold limit. When it is reached, wait for the next "resolved" timestamp and take note of it. Then drop the internal changefeed without telling the user (not user-visible change).
  2. The sink can still consume from the buffer.
  3. When this buffer is consumed up to some smaller threshold then we need to start the internal changefeed again. Start a new changefeed with cursor set to the timestamp from the last resolved timestamp. Continue business as usual.

As far as I can tell this is fully consistent and undetectable from the client. It has a performance impact for "pausing" and "continuing" the changefeed, but this is better than causing cluster-level issues. The threshold would have to be tuned to avoid this happening too often.

lbguilherme avatar Feb 17 '21 21:02 lbguilherme

(1) Sacrifice Consistency: The changefeed dies or is paused. Writes continue, allowing any downstream consumers of the feed to drift out of sync.

We could maybe avoid this problem by doing failing/pausing before we actually OOM + giving a clear, actionable message that alerts the user on how to protect from garbage collection and that there is a problem with the sink. Or at least this would give a window of opportunity to fix the problem before we sacrifice consistency or availability.

(2) Sacrifice Availability: Writes to the table start failing with an error that clearly explains what's going on with the changefeed. The downstream consumers are a bounded amount out of sync, with the changefeed's high-water-mark being a legible bound.

This is interesting, we could probably do some version of (1) right now and add (2) as an option if users ask for it

amruss avatar Feb 23 '21 23:02 amruss

I think this issue can be closed. Combination of all of the previous work, plus improvements in catchup are probably all we are going to do here.

miretskiy avatar Mar 01 '22 19:03 miretskiy