# Setup:
#
# k1: value  @ ts 20
# k1: value  @ ts 10
#
# k2: intent @ ts 20
# k2: value  @ ts 10
#

run ok
with k=k1
  put v=v ts=10,0
  put v=v2 ts=20,0
----
>> at end:
data: "k1"/20.000000000,0 -> /BYTES/v2
data: "k1"/10.000000000,0 -> /BYTES/v

run ok
with k=k2
  put v=v3 ts=10,0
  txn_begin t=A ts=20,0
  put t=A v=v4
----
put: lock acquisition = {k2 id=00000001 key="k2" iso=Serializable pri=0.00000000 epo=0 ts=20.000000000,0 min=0,0 seq=0 Replicated Intent []}
>> at end:
txn: "A" meta={id=00000001 key="k2" iso=Serializable pri=0.00000000 epo=0 ts=20.000000000,0 min=0,0 seq=0} lock=true stat=PENDING rts=20.000000000,0 wto=false gul=0,0
data: "k1"/20.000000000,0 -> /BYTES/v2
data: "k1"/10.000000000,0 -> /BYTES/v
meta: "k2"/0,0 -> txn={id=00000001 key="k2" iso=Serializable pri=0.00000000 epo=0 ts=20.000000000,0 min=0,0 seq=0} ts=20.000000000,0 del=false klen=12 vlen=7 mergeTs=<nil> txnDidNotUpdateMeta=true
data: "k2"/20.000000000,0 -> /BYTES/v4
data: "k2"/10.000000000,0 -> /BYTES/v3

# Test cases:
# 
# for ts in (5, 10, 15, 20, 25):
#   for globalUncertaintyLimit in (5, 10, 15, 20, 25):
#     if globalUncertaintyLimit < ts: continue
#     for k in (k1, k2):
#       for op in (get, scan):
#         testCase()
#

run ok
txn_begin t=txn1 ts=5,0 globalUncertaintyLimit=5,0
----
>> at end:
txn: "txn1" meta={id=00000002 key=/Min iso=Serializable pri=0.00000000 epo=0 ts=5.000000000,0 min=0,0 seq=0} lock=true stat=PENDING rts=5.000000000,0 wto=false gul=5.000000000,0

run ok
get t=txn1 k=k1
----
get: "k1" -> <no data>

run ok
scan t=txn1 k=k1
----
scan: "k1"-"k1\x00" -> <no data>

run ok
get t=txn1 k=k2
----
get: "k2" -> <no data>

run ok
scan t=txn1 k=k2
----
scan: "k2"-"k2\x00" -> <no data>


run ok
txn_begin t=txn2 ts=5,0 globalUncertaintyLimit=10,0
----
>> at end:
txn: "txn2" meta={id=00000003 key=/Min iso=Serializable pri=0.00000000 epo=0 ts=5.000000000,0 min=0,0 seq=0} lock=true stat=PENDING rts=5.000000000,0 wto=false gul=10.000000000,0

run error
get t=txn2 k=k1
----
get: "k1" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 5.000000000,0 encountered previous write with future timestamp 10.000000000,0 within uncertainty interval `t <= (local=0,0, global=10.000000000,0)`; observed timestamps: []

run error
scan t=txn2 k=k1
----
scan: "k1"-"k1\x00" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 5.000000000,0 encountered previous write with future timestamp 10.000000000,0 within uncertainty interval `t <= (local=0,0, global=10.000000000,0)`; observed timestamps: []

run error
get t=txn2 k=k2
----
get: "k2" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 5.000000000,0 encountered previous write with future timestamp 10.000000000,0 within uncertainty interval `t <= (local=0,0, global=10.000000000,0)`; observed timestamps: []

run error
scan t=txn2 k=k2
----
scan: "k2"-"k2\x00" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 5.000000000,0 encountered previous write with future timestamp 10.000000000,0 within uncertainty interval `t <= (local=0,0, global=10.000000000,0)`; observed timestamps: []


run ok
txn_begin t=txn3 ts=5,0 globalUncertaintyLimit=15,0
----
>> at end:
txn: "txn3" meta={id=00000004 key=/Min iso=Serializable pri=0.00000000 epo=0 ts=5.000000000,0 min=0,0 seq=0} lock=true stat=PENDING rts=5.000000000,0 wto=false gul=15.000000000,0

run error
get t=txn3 k=k1
----
get: "k1" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 5.000000000,0 encountered previous write with future timestamp 10.000000000,0 within uncertainty interval `t <= (local=0,0, global=15.000000000,0)`; observed timestamps: []

run error
scan t=txn3 k=k1
----
scan: "k1"-"k1\x00" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 5.000000000,0 encountered previous write with future timestamp 10.000000000,0 within uncertainty interval `t <= (local=0,0, global=15.000000000,0)`; observed timestamps: []

run error
get t=txn3 k=k2
----
get: "k2" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 5.000000000,0 encountered previous write with future timestamp 10.000000000,0 within uncertainty interval `t <= (local=0,0, global=15.000000000,0)`; observed timestamps: []

run error
scan t=txn3 k=k2
----
scan: "k2"-"k2\x00" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 5.000000000,0 encountered previous write with future timestamp 10.000000000,0 within uncertainty interval `t <= (local=0,0, global=15.000000000,0)`; observed timestamps: []


run ok
txn_begin t=txn4 ts=5,0 globalUncertaintyLimit=20,0
----
>> at end:
txn: "txn4" meta={id=00000005 key=/Min iso=Serializable pri=0.00000000 epo=0 ts=5.000000000,0 min=0,0 seq=0} lock=true stat=PENDING rts=5.000000000,0 wto=false gul=20.000000000,0

run error
get t=txn4 k=k1
----
get: "k1" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 5.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=20.000000000,0)`; observed timestamps: []

run error
scan t=txn4 k=k1
----
scan: "k1"-"k1\x00" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 5.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=20.000000000,0)`; observed timestamps: []

run error
get t=txn4 k=k2
----
get: "k2" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 5.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=20.000000000,0)`; observed timestamps: []

run error
scan t=txn4 k=k2
----
scan: "k2"-"k2\x00" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 5.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=20.000000000,0)`; observed timestamps: []


run ok
txn_begin t=txn5 ts=5,0 globalUncertaintyLimit=25,0
----
>> at end:
txn: "txn5" meta={id=00000006 key=/Min iso=Serializable pri=0.00000000 epo=0 ts=5.000000000,0 min=0,0 seq=0} lock=true stat=PENDING rts=5.000000000,0 wto=false gul=25.000000000,0

run error
get t=txn5 k=k1
----
get: "k1" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 5.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=25.000000000,0)`; observed timestamps: []

run error
scan t=txn5 k=k1
----
scan: "k1"-"k1\x00" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 5.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=25.000000000,0)`; observed timestamps: []

run error
get t=txn5 k=k2
----
get: "k2" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 5.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=25.000000000,0)`; observed timestamps: []

run error
scan t=txn5 k=k2
----
scan: "k2"-"k2\x00" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 5.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=25.000000000,0)`; observed timestamps: []


run ok
txn_begin t=txn6 ts=10,0 globalUncertaintyLimit=10,0
----
>> at end:
txn: "txn6" meta={id=00000007 key=/Min iso=Serializable pri=0.00000000 epo=0 ts=10.000000000,0 min=0,0 seq=0} lock=true stat=PENDING rts=10.000000000,0 wto=false gul=10.000000000,0

run ok
get t=txn6 k=k1
----
get: "k1" -> /BYTES/v @10.000000000,0

run ok
scan t=txn6 k=k1
----
scan: "k1" -> /BYTES/v @10.000000000,0

run ok
get t=txn6 k=k2
----
get: "k2" -> /BYTES/v3 @10.000000000,0

run ok
scan t=txn6 k=k2
----
scan: "k2" -> /BYTES/v3 @10.000000000,0


run ok
txn_begin t=txn7 ts=10,0 globalUncertaintyLimit=15,0
----
>> at end:
txn: "txn7" meta={id=00000008 key=/Min iso=Serializable pri=0.00000000 epo=0 ts=10.000000000,0 min=0,0 seq=0} lock=true stat=PENDING rts=10.000000000,0 wto=false gul=15.000000000,0

run ok
get t=txn7 k=k1
----
get: "k1" -> /BYTES/v @10.000000000,0

run ok
scan t=txn7 k=k1
----
scan: "k1" -> /BYTES/v @10.000000000,0

run ok
get t=txn7 k=k2
----
get: "k2" -> /BYTES/v3 @10.000000000,0

run ok
scan t=txn7 k=k2
----
scan: "k2" -> /BYTES/v3 @10.000000000,0


run ok
txn_begin t=txn8 ts=10,0 globalUncertaintyLimit=20,0
----
>> at end:
txn: "txn8" meta={id=00000009 key=/Min iso=Serializable pri=0.00000000 epo=0 ts=10.000000000,0 min=0,0 seq=0} lock=true stat=PENDING rts=10.000000000,0 wto=false gul=20.000000000,0

run error
get t=txn8 k=k1
----
get: "k1" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 10.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=20.000000000,0)`; observed timestamps: []

run error
scan t=txn8 k=k1
----
scan: "k1"-"k1\x00" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 10.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=20.000000000,0)`; observed timestamps: []

run error
get t=txn8 k=k2
----
get: "k2" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 10.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=20.000000000,0)`; observed timestamps: []

run error
scan t=txn8 k=k2
----
scan: "k2"-"k2\x00" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 10.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=20.000000000,0)`; observed timestamps: []


run ok
txn_begin t=txn9 ts=10,0 globalUncertaintyLimit=25,0
----
>> at end:
txn: "txn9" meta={id=0000000a key=/Min iso=Serializable pri=0.00000000 epo=0 ts=10.000000000,0 min=0,0 seq=0} lock=true stat=PENDING rts=10.000000000,0 wto=false gul=25.000000000,0

run error
get t=txn9 k=k1
----
get: "k1" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 10.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=25.000000000,0)`; observed timestamps: []

run error
scan t=txn9 k=k1
----
scan: "k1"-"k1\x00" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 10.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=25.000000000,0)`; observed timestamps: []

run error
get t=txn9 k=k2
----
get: "k2" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 10.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=25.000000000,0)`; observed timestamps: []

run error
scan t=txn9 k=k2
----
scan: "k2"-"k2\x00" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 10.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=25.000000000,0)`; observed timestamps: []


run ok
txn_begin t=txn10 ts=15,0 globalUncertaintyLimit=15,0
----
>> at end:
txn: "txn10" meta={id=0000000b key=/Min iso=Serializable pri=0.00000000 epo=0 ts=15.000000000,0 min=0,0 seq=0} lock=true stat=PENDING rts=15.000000000,0 wto=false gul=15.000000000,0

run ok
get t=txn10 k=k1
----
get: "k1" -> /BYTES/v @10.000000000,0

run ok
scan t=txn10 k=k1
----
scan: "k1" -> /BYTES/v @10.000000000,0

run ok
get t=txn10 k=k2
----
get: "k2" -> /BYTES/v3 @10.000000000,0

run ok
scan t=txn10 k=k2
----
scan: "k2" -> /BYTES/v3 @10.000000000,0


run ok
txn_begin t=txn11 ts=15,0 globalUncertaintyLimit=20,0
----
>> at end:
txn: "txn11" meta={id=0000000c key=/Min iso=Serializable pri=0.00000000 epo=0 ts=15.000000000,0 min=0,0 seq=0} lock=true stat=PENDING rts=15.000000000,0 wto=false gul=20.000000000,0

run error
get t=txn11 k=k1
----
get: "k1" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 15.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=20.000000000,0)`; observed timestamps: []

run error
scan t=txn11 k=k1
----
scan: "k1"-"k1\x00" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 15.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=20.000000000,0)`; observed timestamps: []

run error
get t=txn11 k=k2
----
get: "k2" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 15.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=20.000000000,0)`; observed timestamps: []

run error
scan t=txn11 k=k2
----
scan: "k2"-"k2\x00" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 15.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=20.000000000,0)`; observed timestamps: []


run ok
txn_begin t=txn12 ts=15,0 globalUncertaintyLimit=25,0
----
>> at end:
txn: "txn12" meta={id=0000000d key=/Min iso=Serializable pri=0.00000000 epo=0 ts=15.000000000,0 min=0,0 seq=0} lock=true stat=PENDING rts=15.000000000,0 wto=false gul=25.000000000,0

run error
get t=txn12 k=k1
----
get: "k1" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 15.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=25.000000000,0)`; observed timestamps: []

run error
scan t=txn12 k=k1
----
scan: "k1"-"k1\x00" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 15.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=25.000000000,0)`; observed timestamps: []

run error
get t=txn12 k=k2
----
get: "k2" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 15.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=25.000000000,0)`; observed timestamps: []

run error
scan t=txn12 k=k2
----
scan: "k2"-"k2\x00" -> <no data>
error: (*kvpb.ReadWithinUncertaintyIntervalError:) ReadWithinUncertaintyIntervalError: read at time 15.000000000,0 encountered previous write with future timestamp 20.000000000,0 within uncertainty interval `t <= (local=0,0, global=25.000000000,0)`; observed timestamps: []


run ok
txn_begin t=txn13 ts=20,0 globalUncertaintyLimit=20,0
----
>> at end:
txn: "txn13" meta={id=0000000e key=/Min iso=Serializable pri=0.00000000 epo=0 ts=20.000000000,0 min=0,0 seq=0} lock=true stat=PENDING rts=20.000000000,0 wto=false gul=20.000000000,0

run ok
get t=txn13 k=k1
----
get: "k1" -> /BYTES/v2 @20.000000000,0

run ok
scan t=txn13 k=k1
----
scan: "k1" -> /BYTES/v2 @20.000000000,0

run error
get t=txn13 k=k2
----
get: "k2" -> <no data>
error: (*kvpb.LockConflictError:) conflicting locks on "k2"

run error
scan t=txn13 k=k2
----
scan: "k2"-"k2\x00" -> <no data>
error: (*kvpb.LockConflictError:) conflicting locks on "k2"


run ok
txn_begin t=txn14 ts=20,0 globalUncertaintyLimit=25,0
----
>> at end:
txn: "txn14" meta={id=0000000f key=/Min iso=Serializable pri=0.00000000 epo=0 ts=20.000000000,0 min=0,0 seq=0} lock=true stat=PENDING rts=20.000000000,0 wto=false gul=25.000000000,0

run ok
get t=txn14 k=k1
----
get: "k1" -> /BYTES/v2 @20.000000000,0

run ok
scan t=txn14 k=k1
----
scan: "k1" -> /BYTES/v2 @20.000000000,0

run error
get t=txn14 k=k2
----
get: "k2" -> <no data>
error: (*kvpb.LockConflictError:) conflicting locks on "k2"

run error
scan t=txn14 k=k2
----
scan: "k2"-"k2\x00" -> <no data>
error: (*kvpb.LockConflictError:) conflicting locks on "k2"


run ok
txn_begin t=txn15 ts=25,0 globalUncertaintyLimit=25,0
----
>> at end:
txn: "txn15" meta={id=00000010 key=/Min iso=Serializable pri=0.00000000 epo=0 ts=25.000000000,0 min=0,0 seq=0} lock=true stat=PENDING rts=25.000000000,0 wto=false gul=25.000000000,0

run ok
get t=txn15 k=k1
----
get: "k1" -> /BYTES/v2 @20.000000000,0

run ok
scan t=txn15 k=k1
----
scan: "k1" -> /BYTES/v2 @20.000000000,0

run error
get t=txn15 k=k2
----
get: "k2" -> <no data>
error: (*kvpb.LockConflictError:) conflicting locks on "k2"

run error
scan t=txn15 k=k2
----
scan: "k2"-"k2\x00" -> <no data>
error: (*kvpb.LockConflictError:) conflicting locks on "k2"
