You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "JackieTien97 (via GitHub)" <gi...@apache.org> on 2026/06/03 07:21:03 UTC

[PR] Make Tier-A metadata operations HA when a DataNode is down (metadata lease + self-fencing) [iotdb]

JackieTien97 opened a new pull request, #17831:
URL: https://github.com/apache/iotdb/pull/17831

   ## Problem
   
   Many cluster metadata operations broadcast a cache-invalidation to **every** registered DataNode and treat *any* unreachable DataNode as a hard failure. As a result, with multiple replicas configured, a **single down DataNode** still makes these operations fail — contradicting the HA goal. The original report was table-model DDL (`CREATE TABLE`, `ALTER TABLE ...`), but the same pattern affects ~all Tier-A metadata ops (tree-model schema, templates, views, TTL, `DROP DATABASE`, permissions).
   
   The reason the broadcast cannot simply "skip" an unreachable DataNode is **correctness**: a DataNode caches ConfigNode-pushed metadata (table/tree schema, permissions, TTL, ...). If it misses an invalidation during a network partition and keeps serving the stale cache, it can produce dirty data / stale reads / stale authorization.
   
   ## Approach — metadata lease + self-fencing + a broadcast verdict
   
   1. **DataNode self-fencing (DN side, fail-closed).** The ConfigNode already heartbeats every DataNode. A DataNode records the last ConfigNode-heartbeat time on its own monotonic clock; if none arrives within `metadata_lease_fence_ms` (`T_fence`, default 20s, aligned with the failure detector), it considers itself **fenced** and stops trusting ConfigNode-pushed caches. On the next heartbeat (recovery) it resyncs.
   2. **ConfigNode broadcast verdict (CN side, liveness).** Instead of "any unreachable DataNode fails the op", the ConfigNode proceeds once every un-acked DataNode is **provably self-fenced** — out of contact for at least `T_proceed = T_fence + margin`, *and* known to support fencing. Such a DataNode is fail-closed and will resync, so it cannot serve dirty data. A DataNode that is reachable-but-unacked (still possibly serving) blocks the op (wait, then fail).
   
   This gives the desired CP behavior: a healthy majority makes progress; a partitioned minority fails closed.
   
   ## What this PR contains
   
   **DataNode side (fail-closed when fenced):**
   - `MetadataLeaseManager` — lease tracking, lazy fence check, recovery listeners (monotonic clock, injectable for tests)
   - Table schema cache (`DataNodeTableCache`) — throws retryable; tree schema cache (`TreeDeviceSchemaCacheManager`) — forces re-fetch from the quorum-backed SchemaRegion; permission cache (`ClusterAuthorityFetcher`) — drops cache → re-fetch (deny while partitioned); TTL — compaction uses an infinite TTL when fenced (never deletes by a stale TTL)
   - Heartbeat records contact + reports a `supportsMetadataLeaseFencing` capability bit; a `metadata_lease_heartbeat_age_ms` metric
   
   **ConfigNode side (proceed past provably-fenced DataNodes):**
   - `MetadataBroadcastVerdict` (pure decision logic) + `DataNodeContactTracker` (sound per-DataNode last-successful-response signal, capability bit) + `ClusterCachePropagator` (broadcast → verdict → PROCEED/WAIT/FAIL with retry)
   - Leadership/removal lifecycle hooks for the contact tracker
   - All Tier-A procedures wired through the propagator: table DDL (`CreateTable` + all 8 alter/drop procedures, forward + rollback), tree-model schema (`DeleteTimeSeries`, `AlterTimeSeriesDataType`, `AlterEncodingCompressor`, logical views, `DeactivateTemplate`), templates (`Set`/`Unset`), `SetTTL`, and `DeleteDatabase` (sync path). Region-task / physical-deletion broadcasts are deliberately left on region consensus.
   - `AuthOperationProcedure`: fixed a silent permission-staleness hole (it used to drop an unacked DataNode after a timeout, leaving a live DataNode serving a just-revoked permission); now proceeds only past provably-fenced DataNodes.
   
   ## Testing
   
   - Unit tests for every new component and each fail-closed injection (`MetadataLeaseManager`, `DataNodeTableCache`, tree schema, permission, TTL-compaction, `MetadataBroadcastVerdict`, `DataNodeContactTracker`, `ClusterCachePropagator`), plus no-regression on the affected procedures.
   - **1C3D integration test** (`IoTDBTableDDLHAIT`): with one DataNode stopped, `CREATE TABLE` **succeeds** after ~`T_proceed` (instead of failing immediately). A new `setMetadataLeaseFenceMs` IT-config setter keeps the wait short.
   
   ## Configuration & compatibility
   
   - New knob `metadata_lease_fence_ms` (default 20000). `T_proceed = T_fence + internal margin (~5s)`.
   - Takes effect on upgrade, no switch. Rolling-upgrade safe via the capability bit: an old DataNode (no fencing) is never treated as fenced, so the ConfigNode falls back to the strict (current) semantics for it; correctness is preserved DataNode-by-DataNode.
   
   ## Not in this PR (follow-up)
   
   Tier-B resource operations (DROP/CREATE `FUNCTION`/`TRIGGER`/`PIPE PLUGIN`, `SET SYSTEM STATUS=ReadOnly`) and the quota re-pull. These need DataNode-side fail-closed on resource **execution** (not a read-through cache) plus a resource recovery-resync mechanism, which is a separate, self-contained effort.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Make Tier-A metadata operations HA when a DataNode is down (metadata lease + self-fencing) [iotdb]

Posted by "Caideyipi (via GitHub)" <gi...@apache.org>.
Caideyipi commented on PR #17831:
URL: https://github.com/apache/iotdb/pull/17831#issuecomment-4610279864

   我看了这版实现和设计说明,有几个安全语义点建议再收紧/补证:
   
   1. **lease recovery 解除 fence 的顺序有窗口。**
      `MetadataLeaseManager.recordConfigNodeHeartbeat()` 现在先更新 `lastConfigNodeHeartbeatNanos`,再跑 recovery listeners;这意味着 listener 执行期间(或 listener 抛异常被吞掉后)`isFenced()` 已经返回 false,旧缓存可能被重新信任。这和“解除 fence 前缓存已作废/已 resync”的安全条件不一致。
      建议改成显式状态机,例如 `FENCED -> RECOVERING -> ACTIVE`:critical recovery listener/resync 成功后才切到 ACTIVE;失败则保持 fenced。
      代码位置:
      https://github.com/apache/iotdb/blob/cc0cbcc1432c804ac4939a3c536279e4994f5d57/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/lease/MetadataLeaseManager.java#L85-L94
   
   2. **leader 切换场景还需要 epoch/token 级证明。**
      DN 现在收到任意 `getDataNodeHeartBeat` 就续约 metadata lease,心跳里没有 leader term / lease token。新 leader 重置 `lastResp` 可以避免使用旧历史,但不能阻止旧 leader 在少数派继续给某些 DN 续约。如果新 leader 收不到这些 DN 的响应,`T_proceed` 后可能判定 FENCED_SAFE,而 DN 实际被旧 leader 心跳续约、未 self-fence。
      这里需要补一个严格证明:旧 leader 在新 leader ready 后不可能继续发送“有效续约”心跳;否则建议在 heartbeat 中带 leader epoch/token,DN 只接受当前有效 token 续约。
      代码位置:
      https://github.com/apache/iotdb/blob/cc0cbcc1432c804ac4939a3c536279e4994f5d57/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/DataNodeInternalRPCServiceImpl.java#L2227-L2232
   
   3. **AuthOperationProcedure 仍有 post-consensus 失败语义问题。**
      现在不再 180s 静默丢弃 DN,这是改进;但 `writePlan` 先写 CN consensus,之后 `ClusterCachePropagator.propagate()` 如果返回 false,会 `setFailure`。此时权限变更已经在 CN 生效,而某个心跳新鲜但 invalidate RPC 持续失败的 DN 可能仍用旧权限缓存服务。对 REVOKE / DROP USER / DROP ROLE 这类安全操作,procedure FAIL 本身不能恢复安全语义。
      建议这类操作在写入成功后保持 pending/retry 直到每个 DN ack 或 fenced,或主动触发 DN fence,或引入 auth version/token,让 DN 侧在版本不明时 fail-closed。
      代码位置:
      https://github.com/apache/iotdb/blob/cc0cbcc1432c804ac4939a3c536279e4994f5d57/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/sync/AuthOperationProcedure.java#L100-L118
      https://github.com/apache/iotdb/blob/cc0cbcc1432c804ac4939a3c536279e4994f5d57/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/sync/AuthOperationProcedure.java#L155-L165
   
   4. **建议补几个负向/竞态测试。**
      目前 IT 覆盖了“停 1 个 DN 后 CREATE TABLE 成功”,但还需要覆盖安全证明里更关键的场景:
      - 心跳通、metadata broadcast RPC 持续失败的半坏 DN;
      - leader 切换时旧 leader 残留/继续心跳续约;
      - recovery listener 延迟或失败时不得提前解除 fence;
      - REVOKE/权限变更后,分区或半坏 DN 不得继续按旧权限放行。
   
   这些不影响“停机 DN 可跳过”的 HA 目标,但会影响 fencing 方案的安全闭包。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Make Tier-A metadata operations HA when a DataNode is down (metadata lease + self-fencing) [iotdb]

Posted by "JackieTien97 (via GitHub)" <gi...@apache.org>.
JackieTien97 closed pull request #17831: Make Tier-A metadata operations HA when a DataNode is down (metadata lease + self-fencing)
URL: https://github.com/apache/iotdb/pull/17831


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org