Skip to content

Commit 092c6ca

Browse files
committed
fix: cicada/mvto insert で TupleBody の use-after-move を解消 (#57)
Tuple::init() の 4 引数 overload で受け取る `TupleBody&& body` は本体で 未使用 (`[[maybe_unused]]`) なまま捨てられていた。呼び出し側 (cicada/mvto の TxExecutor::insert) は newVersionGeneration() で `std::move(body)` した 直後に同じ `body` を再度 `std::move()` して init() に渡しており、典型的な use-after-move となっていた。 cicada は `INLINE_VERSION_OPT=1` のとき init() 内で `body_ = std::ref(inline_ver_.body_)` する。inline_ver_.body_ は default-construct されたままで、insert で挿入したはずの値が消える (データロス)。デフォルト ビルド (INLINE_VERSION_OPT=0) と mvto は `new_ver->body_` を参照するため 偶然動いていたが、コードスメルとしての use-after-move は残っていた。 Issue #57 の Intent B (推奨案) に従い、init() overload の 4 番目の引数を 削除し、呼び出し側も 3 引数の呼び出しに揃える。これにより: - 二重 move による use-after-move を除去 - INLINE_VERSION_OPT=1 と =0 で body の所有経路が一致 (`new_ver->body_`) なお INLINE_VERSION_OPT=1 で insert された tuple の body が new_ver 経由でアクセスできることは元のコードでも保証されている。
1 parent 49475eb commit 092c6ca

4 files changed

Lines changed: 5 additions & 6 deletions

File tree

cc/cicada/include/tuple.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public:
9292
#endif
9393
}
9494

95-
void init([[maybe_unused]] size_t thid, Version* ver, uint64_t initial_wts,
96-
[[maybe_unused]] TupleBody&& body) {
95+
void init([[maybe_unused]] size_t thid, [[maybe_unused]] Version* ver,
96+
uint64_t initial_wts) {
9797
min_wts_ = initial_wts;
9898
gc_lock_.store(0, std::memory_order_release);
9999
continuing_commit_.store(0, std::memory_order_release);

cc/cicada/transaction.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ Status TxExecutor::insert(Storage s, std::string_view key, TupleBody&& body) {
313313

314314
tuple = new Tuple();
315315
Version* new_ver = newVersionGeneration(tuple, std::move(body));
316-
tuple->init(this->thid_, new_ver, this->wts_.ts_, std::move(body));
316+
tuple->init(this->thid_, new_ver, this->wts_.ts_);
317317

318318
typename MasstreeWrapper<Tuple>::insert_info_t insert_info;
319319
Status stat =

cc/mvto/include/tuple.hh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ public:
5858
body_ = std::ref((latest_.load(std::memory_order_acquire))->body_);
5959
}
6060

61-
void init([[maybe_unused]] size_t thid, Version* ver, uint64_t initial_wts,
62-
[[maybe_unused]] TupleBody&& body) {
61+
void init([[maybe_unused]] size_t thid, Version* ver, uint64_t initial_wts) {
6362
min_wts_ = initial_wts;
6463
gc_lock_.store(0, std::memory_order_release);
6564
latest_.store(ver, std::memory_order_release);

cc/mvto/transaction.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Status TxExecutor::insert(Storage s, std::string_view key, TupleBody&& body) {
167167

168168
tuple = new Tuple();
169169
Version* new_ver = newVersionGeneration(tuple, std::move(body));
170-
tuple->init(this->thid_, new_ver, this->wts_.ts_, std::move(body));
170+
tuple->init(this->thid_, new_ver, this->wts_.ts_);
171171

172172
Status stat = Masstrees[get_storage(s)].insert_value(key, tuple);
173173
if (stat == Status::WARN_ALREADY_EXISTS) {

0 commit comments

Comments
 (0)