# Copyright (c) reifydb.com 2025
# This file is licensed under the AGPL-3.0-or-later

# This file includes and modifies code from the toydb project (https://github.com/erikgrinaker/toydb),
# originally licensed under the Apache License, Version 2.0.
# Original copyright:
#   Copyright (c) 2024 Erik Grinaker
#
# The original Apache License can be found at:
#   http://www.apache.org/licenses/LICENSE-2.0

# Set should return serialization errors both for uncommitted versions
# (past and future), and future committed versions.

t1: begin
t2: begin
t3: begin
t4: begin
---
ok

t1: set a=1
t3: set c=3
t4: set d=4
t4: commit
---
ok

t2: !set a=2 # past uncommitted
t2: !set c=2 # future uncommitted
t2: !set d=2 # future committed
---
t2: Error: transaction serialization conflict occurred, retry transaction
t2: Error: transaction serialization conflict occurred, retry transaction
t2: Error: transaction serialization conflict occurred, retry transaction

dump
---
mvcc:NextVersion → 5 ["\x00" → "\x05"]
mvcc:TxActive(1) → "" ["\x01\x00\x00\x00\x00\x00\x00\x00\x01" → ""]
mvcc:TxActive(2) → "" ["\x01\x00\x00\x00\x00\x00\x00\x00\x02" → ""]
mvcc:TxActive(3) → "" ["\x01\x00\x00\x00\x00\x00\x00\x00\x03" → ""]
mvcc:TxActiveSnapshot(2) → {1} ["\x02\x00\x00\x00\x00\x00\x00\x00\x02" → "\x01\x01"]
mvcc:TxActiveSnapshot(3) → {1,2} ["\x02\x00\x00\x00\x00\x00\x00\x00\x03" → "\x02\x01\x02"]
mvcc:TxActiveSnapshot(4) → {1,2,3} ["\x02\x00\x00\x00\x00\x00\x00\x00\x04" → "\x03\x01\x02\x03"]
mvcc:TxWrite(1, "a") → "" ["\x03\x00\x00\x00\x00\x00\x00\x00\x01a\x00\x00" → ""]
mvcc:TxWrite(3, "c") → "" ["\x03\x00\x00\x00\x00\x00\x00\x00\x03c\x00\x00" → ""]
mvcc:Version("a", 1) → "1" ["\x04a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01" → "\x01\x011"]
mvcc:Version("c", 3) → "3" ["\x04c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03" → "\x01\x013"]
mvcc:Version("d", 4) → "4" ["\x04d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04" → "\x01\x014"]
