incubator-hugegraph icon indicating copy to clipboard operation
incubator-hugegraph copied to clipboard

[Bug] Cassandra commitAsync lacks retry support after Cassandra restart

Open dpol1 opened this issue 7 months ago • 3 comments

Bug Type (问题类型)

logic (逻辑设计问题)

Before submit

  • [x] 我已经确认现有的 Issues 与 FAQ 中没有相同 / 重复问题 (I have confirmed and searched that there are no similar problems in the historical issue and documents)

Environment (环境信息)

  • Server Version: 1.0.0 (Apache Release Version)
  • Backend: RocksDB x nodes, HDD or SSD
  • OS: xx CPUs, xx G RAM, Ubuntu 2x.x / CentOS 7.x
  • Data Size: xx vertices, xx edges

Expected & Actual behavior (期望与实际表现)

Follow-up from #2997 / #2740.

Code pointer:

https://github.com/apache/hugegraph/blob/836b34832b485df8b4cae02880a489ebc516cf6d/hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraSessionPool.java#L237-L243

Expected behavior

When Cassandra is temporarily unavailable or restarted, the Cassandra backend should handle transient connectivity failures consistently between synchronous and asynchronous write paths.

CassandraSessionPool.Session.commit() now uses executeWithRetry() and can retry transient failures such as NoHostAvailableException.

commitAsync() should either provide equivalent retry support for async writes, or explicitly define and document different reliability semantics.

Actual behavior

CassandraSessionPool.Session.commitAsync() bypasses executeWithRetry() and calls Datastax Session.executeAsync(...) directly.

During a Cassandra restart, async writes issued through commitAsync() can fail with transient driver errors such as NoHostAvailableException.

The failure is only surfaced through the Datastax ResultSetFuture / getUninterruptibly() flow. Callers that do not inspect these futures carefully may miss failed async writes.

This creates inconsistent behavior:

commit()      -> executeWithRetry() -> transient retry support
commitAsync() -> executeAsync()     -> no async retry support

Vertex/Edge example (问题点 / 边数据举例)


Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)


dpol1 avatar Apr 25 '26 17:04 dpol1

Proposed Fix Approaches

Two implementation strategies are under consideration to add retry support to commitAsync().


Option A — Synchronous fallback

Estimated effort: Easy but to refine later

Reuse the existing executeWithRetry() for each statement in the async path, collecting results synchronously. This eliminates the need for any new infrastructure and guarantees consistent retry semantics with commit().

for (Statement s : statements) {
    this.executeWithRetry(s);
}

Pros

  • Minimal code change — reuses tested, reviewed retry logic
  • No new dependencies
  • Immediately consistent with commit() behaviour

Cons

  • Loses batched-async throughput; commitAsync() becomes semantically equivalent to per-statement commit() calls

Option B — True async retry with ListenableFuture

Estimated effort: High complexity but solid + tests

Wrap each ResultSetFuture in a retry chain using Futures.catching() from Guava (already a transitive dependency via Datastax). Preserves async throughput and adds retry semantics without blocking the calling thread.

Pros

  • Correct long-term solution — maintains true async throughput
  • Consistent retry semantics across both write paths

Cons

  • Must handle interrupt, thread-pool selection, and retry-counter propagation
  • Requires dedicated unit and integration tests

Recommended path

  • Option B is the preferred long-term fix because it preserves the current async batching behavior.

  • Option A could be considered only as a minimal correctness-first fallback if maintainers prefer a small interim patch, but it would reduce the current async throughput by executing statements sequentially.

dpol1 avatar Apr 26 '26 07:04 dpol1

@dosu WDYT?

dpol1 avatar May 20 '26 08:05 dpol1

I agree with the phased approach — Option A first, Option B later if needed — and here's my reasoning:

Option A is the right short-term fix because:

  1. commitAsync() has zero callers in the codebase [1], so there's no existing workload that depends on its async throughput characteristics. You won't regress anything.
  2. It already blocks via getUninterruptibly() every 1023 statements — the "async" is really just bounded parallelism, not a truly non-blocking API. The throughput delta from switching to per-statement executeWithRetry() is likely small.
  3. executeWithRetry() is already merged (PR #2997, April 2026) [2] and provides exponential backoff, session reset, and idempotency checks. Reusing it means no new infrastructure and consistent semantics with commit().
  4. No precedent for Futures.catching() — the codebase uses synchronous retry loops everywhere else. Option B would introduce a pattern the team hasn't used before, increasing maintenance cost for an unused method.

One suggestion: since commitAsync() is currently dead code with misleading naming, consider either:

  • Renaming it (e.g., commitBatch() or commitParallel()) if you plan to keep the bounded-parallelism behavior in the future, or
  • Documenting a concrete future call site that would justify investing in Option B later.

Without a real caller that benefits from async pipelining, Option B's complexity is hard to justify. If a use case does emerge (e.g., high-throughput bulk loading), that would be the right time to revisit with proper benchmarks.

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about hugegraph with Dosu Add Dosu to your team

dosubot[bot] avatar May 20 '26 08:05 dosubot[bot]