Skip to content

[P1] TxExecutor契約をコンパイル時に強制する + tx.write→tx.update rename - #40

Merged
thawk105 merged 2 commits into
masterfrom
p1-tx-executor-concept
May 12, 2026
Merged

[P1] TxExecutor契約をコンパイル時に強制する + tx.write→tx.update rename#40
thawk105 merged 2 commits into
masterfrom
p1-tx-executor-concept

Conversation

@thawk105

Copy link
Copy Markdown
Owner

Closes #31.

What

  1. include/tx_executor_concept.hhTxExecutorLike<T> を新設。各プロトコルの transaction.hh 末尾に static_assert(TxExecutorLike<TxExecutor>); を追加 → 契約違反がプロトコル自身のビルド時に named diagnostic で落ちる。

  2. tx.writetx.update rename を repo 全体に。理由: 既存行への書き込み専用(行が無いと WARN_NOT_FOUND、内部 OpType::UPDATE)で、write という名前が誤解を招くため。SQL CRUD と揃えた:

    read / update / insert / delete_record / scan

  3. d2pl が scan(..., int64_t limit) overload 不足 を契約検査が捕捉 → overload 追加(-1 で無制限版に forward)。

SFINAE である理由

issue spec は C++20 concept を要求してるが、bundled masstree-betastd::allocator::construct/destroy(C++20で削除)を呼んでてビルド不可。C++17 に留まったまま is_detected 風 SFINAE で同等の検査を実装。masstree 側の C++20 対応は別 issue 案件。

動作確認

  • 全 34 バイナリ Release / Debug+ASan 共にビルド成功
  • 9 プロトコルの TPC-C smoke 全部 non-zero throughput
  • Negative test: 試しに silo/include/transaction.hhupdateupdate_DISABLED に rename したら:
    silo/include/transaction.hh:168:15: error: static assertion failed
      168 | static_assert(TxExecutorLike<TxExecutor>);
    
    と即座にコンパイル fail。契約強制が機能してる証左。

Out of scope

  • masstree の C++20 非互換: 真の concept 構文を解禁したいなら別 issue 必要。
  • ss2pl/d2pl の legacy void write(uint64_t key) 宣言: 実装/呼び出し共に無し。P7 dead-code sweep ([P7] デッドコード・残骸ファイルを一掃する #36) で。
  • workload-template 側の <TxExecutorLike Tx, ...> 制約: per-protocol static_assert で先に / 局所的に検出されるので redundant、省略。

統計

  • Touched 32 files for the rename, 10 protocol headers for static_assert, 2 d2pl files for missing scan overload, plus CLAUDE.md
  • 35 files changed, +210 -56

thawk105 added 2 commits May 12, 2026 21:28
…tx.update (#31)

Closes #31.

## Contract enforcement

Add include/tx_executor_concept.hh defining `TxExecutorLike<T>`. Each
protocol's `transaction.hh` ends with `static_assert(TxExecutorLike<TxExecutor>);`
so a missing or wrong-signature method fails the protocol's own build with
a named diagnostic instead of crashing at runtime in some workload.

Caught d2pl missing the `scan(..., int64_t limit)` overload — added the
overload (forwarding to the unlimited form with -1) so d2pl now satisfies
the contract uniformly with the other 9 protocols.

The check uses an `is_detected`-style SFINAE helper instead of a C++20
`concept` because the bundled `masstree-beta` upstream still calls
`std::allocator::construct/destroy`, which were removed in C++20. Bumping
the tree to C++20 broke masstree's `small_vector::rep`. Filing this as a
separate concern; for now the SFINAE path gives the same compile-time
guarantee in C++17.

## tx.write -> tx.update rename

`tx.write` was misnamed: it operates only on existing rows (returns
`WARN_NOT_FOUND` otherwise) and internally tags the write set with
`OpType::UPDATE`. Renaming aligns the API with SQL CRUD:

  read / update / insert / delete_record / scan

`write_set_`, `write_phase`, etc. keep the "write" terminology — the set
holds insert + update + delete ops collectively, and matches Silo / Cicada
/ ERMIA paper terminology.

Touched 32 files, mechanical replace of `tx.write(` -> `tx.update(` and
the matching method definitions/declarations. `tx.write_lock(...)` (a
separate ss2pl/d2pl-only API) is intentionally untouched.

## Verified

- All 34 binaries build (Release + Debug+ASan).
- 9 TPC-C smoke runs all return non-zero throughput.
- Negative test: deliberately removing `update` from silo's TxExecutor
  triggers the static_assert with a clear diagnostic.

## Out of scope

- masstree C++20 incompatibility (separate; would unlock real C++20
  `concept` syntax in this repo).
- legacy `void write(uint64_t key)` decls in ss2pl/d2pl (no impl, no
  callers; defer to P7 dead-code sweep #36).
- workload-template-side `<TxExecutorLike Tx, ...>` constraint not
  added — per-protocol static_assert already catches violations earlier
  and locally.
Now that thawk105/masstree-beta#1 is in (refcount as std::atomic, rep
construct/destroy via std::allocator_traits), the bundled masstree
header compiles cleanly under -std=c++20, so the rest of the tree can
use C++20 too:

- cmake/CompileOptions.cmake: CMAKE_CXX_STANDARD 17 -> 20.
- top-level CMakeLists.txt: ccbench_common now requires cxx_std_20
  PUBLICly, so consumers inherit the standard.
- third_party/masstree submodule: bump to b3c5d05 (the merged PR).
- include/tx_executor_concept.hh: replace the is_detected-style SFINAE
  scaffolding with a real `requires`-clause C++20 concept. The
  per-protocol `static_assert(TxExecutorLike<TxExecutor>)` checks now
  fail with much sharper diagnostics —

    constraints not satisfied
    the required expression 't.update(s, k, declval<TupleBody&&>())' is invalid

  (verified by removing `update` from silo's TxExecutor and rebuilding.)
@thawk105

Copy link
Copy Markdown
Owner Author

追加コミット e42eba3:

  • thawk105/masstree-beta#1 を取り込んで(submodule SHA を b3c5d05 に bump)、これで masstree が C++20 でクリーンにビルドできるように
  • cmake/CompileOptions.cmake: CXX_STANDARD 17 → 20
  • ccbench_common: cxx_std_20 PUBLIC で全 consumer に伝播
  • include/tx_executor_concept.hh: SFINAE → 真の C++20 concept (requires-clause)

これで static_assert 違反時の診断が SFINAE 版より遥かに鮮明:

constraints not satisfied
the required expression 't.update(s, k, declval<TupleBody&&>())' is invalid

(silo から update を抜く negative test で確認)

全 34 バイナリ Release ビルド clean、warning ゼロ。

@thawk105
thawk105 merged commit eb22773 into master May 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1] TxExecutorコントラクトをC++20 conceptで明示する

1 participant