Skip to content

fix ut - #26381

Merged
XuPeng-SH merged 14 commits into
matrixorigin:mainfrom
daviszhen:0729-fix-ut
Jul 30, 2026
Merged

fix ut#26381
XuPeng-SH merged 14 commits into
matrixorigin:mainfrom
daviszhen:0729-fix-ut

Conversation

@daviszhen

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #26374

What this PR does / why we need it:

  • 锁服务测试:将忙等改为最长 10 秒、10ms 间隔的状态轮询,明确等待 LockWaiting 与锁表引用的创建/清理完成。
  • CN 启动测试:将一次性 SQL 就绪检查改为最长 30 秒的重试检查,每次请求限时 1 秒。
  • 不涉及生产逻辑修改,仅调整测试稳定性。

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] The changes do not cover the failure modes recorded in #26374. (1) TestClusterCanStartNewCNServices failed by panicking inside the CN bootstrap goroutine before validCNCanWork runs, so retrying the later SQL readiness check cannot prevent it. (2) TestReLockInRollingRestartCN and TestPreTxnLockInRollingRestartCN failed after the service reached the requested state, when the following one-shot remote Lock returned backend connection closed. State polling does not retry those operations; please use the existing rolling-restart retry contract/helper for the transient RPC errors and add deterministic coverage. Also prefer a fatal readiness assertion so a timed-out prerequisite does not let the test continue.

@matrix-meow matrix-meow added size/L Denotes a PR that changes [500,999] lines and removed size/M Denotes a PR that changes [100,499] lines labels Jul 30, 2026
@daviszhen
daviszhen requested a review from XuPeng-SH July 30, 2026 09:03

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review of exact head 7b964ac. The idempotent HAKeeper allocation closes the prior lock-ownership hole, but bootstrap connection-error closure is still incomplete.

[P1] Make bootstrap retries phase-aware across the initial check and an unknown transaction commit — pkg/bootstrap/service.go:186-190, pkg/bootstrap/service.go:223-237

Two retryable windows still reach handleBootstrapErr or can make the owner panic:

  1. Bootstrap returns any connection error from the initial checkAlreadyBootstrapped directly, before the new idempotent lock path is reached. A transient SQL connection reset in this pre-owner check therefore still reproduces the original pre-readiness failure class.

  2. execBootstrapWithRetry blindly starts the full bootstrap transaction again after every connection error. If ExecTxn committed the initialization but the commit response was lost, the next attempt does not re-check bootstrap state and reruns non-idempotent initialization SQL (create database, version insert, etc.); that can fail with a non-connection duplicate-object error and still panic. This is the SQL-side equivalent of the allocation unknown-outcome case the new request ID correctly handles.

TestBootstrapRetriesOwnerInitializationWithoutReacquiringLock only injects the error from the first init SQL before a successful commit, so it cannot exercise either case. Please retry the safe pre-owner check, and after an owner transaction connection error reconcile committed bootstrap state before deciding whether to rerun, with deterministic tests for the initial-check reset and a committed-but-response-lost ExecTxn. The rolling-restart lock retry changes and idempotent HAKeeper request handling otherwise look sound.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Deep re-review of exact head 7b964ac. The idempotent HAKeeper allocation closes the prior lock-ownership hole, but bootstrap connection-error closure is still incomplete.

[P1] Make bootstrap retries phase-aware across the initial check and an unknown transaction commit — pkg/bootstrap/service.go:186-190, pkg/bootstrap/service.go:223-237

Two retryable windows still reach handleBootstrapErr or can make the owner panic:

  1. Bootstrap returns any connection error from the initial checkAlreadyBootstrapped directly, before the new idempotent lock path is reached. A transient SQL connection reset in this pre-owner check therefore still reproduces the original pre-readiness failure class.
  2. execBootstrapWithRetry blindly starts the full bootstrap transaction again after every connection error. If ExecTxn committed the initialization but the commit response was lost, the next attempt does not re-check bootstrap state and reruns non-idempotent initialization SQL (create database, version insert, etc.); that can fail with a non-connection duplicate-object error and still panic. This is the SQL-side equivalent of the allocation unknown-outcome case the new request ID correctly handles.

TestBootstrapRetriesOwnerInitializationWithoutReacquiringLock only injects the error from the first init SQL before a successful commit, so it cannot exercise either case. Please retry the safe pre-owner check, and after an owner transaction connection error reconcile committed bootstrap state before deciding whether to rerun, with deterministic tests for the initial-check reset and a committed-but-response-lost ExecTxn. The rolling-restart lock retry changes and idempotent HAKeeper request handling otherwise look sound.

  • 初始 bootstrap 状态检查遇到连接错误或 ErrTxnUnknown 时自动重试。

  • bootstrap 重试改为阶段感知:

    • 提交前失败可安全重试,且不重新获取 owner lock。
    • 提交结果未知时只轮询 bootstrap 状态,不重放非幂等初始化 SQL。
  • 对账过程支持延迟可见、临时连接错误和 context 超时退出。

  • 增加确定性单测,覆盖初始检查失败、提交响应丢失、延迟可见、禁止 SQL 重放及超时退出。

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review of exact head fd0ea3a24a344a60fa29559455633ebec4a71caf. The phase-aware uncertain-commit reconciliation closes the two conceptual gaps from the previous review, and the new focused tests pass, but the retry classifier still does not receive the error shape produced by the real SQL executor.

[P1] Preserve retryable error classification through the SQL executor rollback wrapper — pkg/bootstrap/service.go:250-251

checkAlreadyBootstrapped calls SQLExecutor.Exec, and pre-commit initialization runs inside SQLExecutor.ExecTxn. In the production implementation, a transaction-body error takes pkg/sql/compile/sql_executor.go:179-186 and txnExecutor.rollback returns errors.Join(originalErr, Rollback(...)) even when rollback succeeds (sql_executor.go:670-674). The new isBootstrapRetryableError then calls classifiers whose MatrixOne-code paths only accept a top-level *moerr.Error; they do not traverse that joined wrapper.

On this exact head I exercised isBootstrapRetryableError(errors.Join(err, nil)): connection reset happens to pass via morpc string matching, but ErrBackendClosed, ErrBackendCannotConnect, and ErrTxnUnknown all return false. Consequently those errors from the initial state check or an init SQL before commit still return from Bootstrap and reach the CN bootstrap panic instead of the new retry path. TestBootstrapRetriesInitialStateCheckBeforeLock uses NewMemExecutor, and the owner retry test also returns raw errors, so both bypass the production wrapper and cannot catch this.

Please make the retry classification unwrap/traverse joined errors (or fix the shared classifiers) and add deterministic coverage using the production-shaped joined error for the initial-check and pre-commit paths. The uncertain-commit no-replay logic and its delayed-visibility/context tests otherwise look sound.

Non-blocking: the PR description still says this only changes tests, although the head now changes production bootstrap, HAKeeper allocation, and protocol state.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Deep re-review of exact head fd0ea3a24a344a60fa29559455633ebec4a71caf. The phase-aware uncertain-commit reconciliation closes the two conceptual gaps from the previous review, and the new focused tests pass, but the retry classifier still does not receive the error shape produced by the real SQL executor.

[P1] Preserve retryable error classification through the SQL executor rollback wrapper — pkg/bootstrap/service.go:250-251

checkAlreadyBootstrapped calls SQLExecutor.Exec, and pre-commit initialization runs inside SQLExecutor.ExecTxn. In the production implementation, a transaction-body error takes pkg/sql/compile/sql_executor.go:179-186 and txnExecutor.rollback returns errors.Join(originalErr, Rollback(...)) even when rollback succeeds (sql_executor.go:670-674). The new isBootstrapRetryableError then calls classifiers whose MatrixOne-code paths only accept a top-level *moerr.Error; they do not traverse that joined wrapper.

On this exact head I exercised isBootstrapRetryableError(errors.Join(err, nil)): connection reset happens to pass via morpc string matching, but ErrBackendClosed, ErrBackendCannotConnect, and ErrTxnUnknown all return false. Consequently those errors from the initial state check or an init SQL before commit still return from Bootstrap and reach the CN bootstrap panic instead of the new retry path. TestBootstrapRetriesInitialStateCheckBeforeLock uses NewMemExecutor, and the owner retry test also returns raw errors, so both bypass the production wrapper and cannot catch this.

Please make the retry classification unwrap/traverse joined errors (or fix the shared classifiers) and add deterministic coverage using the production-shaped joined error for the initial-check and pre-commit paths. The uncertain-commit no-replay logic and its delayed-visibility/context tests otherwise look sound.

Non-blocking: the PR description still says this only changes tests, although the head now changes production bootstrap, HAKeeper allocation, and protocol state.

  • 修复 bootstrap 对 errors.Join(bodyErr, rollbackErr) 的识别:递归解包 joined/wrapped error,并以首个 body error 决定是否重试。
  • 避免 rollback 的临时连接错误掩盖不可重试的初始化 SQL 错误,防止错误重放 bootstrap。
  • 补充锁前 checkAlreadyBootstrapped 的 joined-error 重试覆盖。
  • 补充 owner 初始化阶段的 joined-error 重试覆盖,确认不重复获取 bootstrap lock。
  • 增加反向回归:不可重试 body error 即使 joined 了可重试 rollback error,也会直接返回而不重试。

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review of exact head a5e608784b7531f4a08f1315ae013a2fd9436322: the previous blocker is resolved; no remaining blocking findings.

isBootstrapRetryableError now traverses production-shaped single/joined wrappers and deliberately classifies only the transaction-body child, so backend-closed/backend-cannot-connect/txn-unknown errors survive SQLExecutor rollback wrapping without allowing a retryable rollback error to turn a non-retryable bootstrap SQL failure into a replay. The phase-aware ownership and uncertain-commit safeguards from the prior head remain intact.

Fresh local evidence: all six bootstrap retry/reconciliation regressions pass under -race -count=5; go build, go vet, and git diff --check pass across the affected bootstrap/CN/embed/HAKeeper/lockservice/logservice packages. Latest CI is green and the PR is MERGEABLE.

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants