Skip to content

Commit d4c9571

Browse files
committed
Update txid_snapshot codec to handle pg_snapshot
Recent Postgres versions have `txid_snapshot` deprecated and now use `pg_snapshot` instead. The difference is in the signedness of the returned transaction id values.
1 parent 2dc7cc4 commit d4c9571

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

codecs/__init__.pxd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,6 @@ cdef inet_encode(CodecContext settings, WriteBuffer buf, obj)
141141
cdef inet_decode(CodecContext settings, FRBuffer * buf)
142142

143143

144-
# txid
145-
cdef txid_snapshot_encode(CodecContext settings, WriteBuffer buf, obj)
146-
cdef txid_snapshot_decode(CodecContext settings, FRBuffer * buf)
144+
# pg_snapshot
145+
cdef pg_snapshot_encode(CodecContext settings, WriteBuffer buf, obj)
146+
cdef pg_snapshot_decode(CodecContext settings, FRBuffer * buf)

codecs/txid.pyx renamed to codecs/pg_snapshot.pyx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
# the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0
66

77

8-
cdef txid_snapshot_encode(CodecContext settings, WriteBuffer buf, obj):
8+
cdef pg_snapshot_encode(CodecContext settings, WriteBuffer buf, obj):
99
cdef:
1010
ssize_t nxip
11-
int64_t xmin
12-
int64_t xmax
11+
uint64_t xmin
12+
uint64_t xmax
1313
int i
1414
WriteBuffer xip_buf = WriteBuffer.new()
1515

@@ -29,32 +29,34 @@ cdef txid_snapshot_encode(CodecContext settings, WriteBuffer buf, obj):
2929
xmax = obj[1]
3030

3131
for i in range(nxip):
32-
xip_buf.write_int64(obj[2][i])
32+
xip_buf.write_int64(
33+
<int64_t>cpython.PyLong_AsUnsignedLongLong(obj[2][i]))
3334

3435
buf.write_int32(20 + xip_buf.len())
3536

3637
buf.write_int32(<int32_t>nxip)
37-
buf.write_int64(obj[0])
38-
buf.write_int64(obj[1])
38+
buf.write_int64(<int64_t>xmin)
39+
buf.write_int64(<int64_t>xmax)
3940
buf.write_buffer(xip_buf)
4041

4142

42-
cdef txid_snapshot_decode(CodecContext settings, FRBuffer *buf):
43+
cdef pg_snapshot_decode(CodecContext settings, FRBuffer *buf):
4344
cdef:
4445
int32_t nxip
45-
int64_t xmin
46-
int64_t xmax
46+
uint64_t xmin
47+
uint64_t xmax
4748
tuple xip_tup
4849
int32_t i
4950
object xip
5051

5152
nxip = hton.unpack_int32(frb_read(buf, 4))
52-
xmin = hton.unpack_int64(frb_read(buf, 8))
53-
xmax = hton.unpack_int64(frb_read(buf, 8))
53+
xmin = <uint64_t>hton.unpack_int64(frb_read(buf, 8))
54+
xmax = <uint64_t>hton.unpack_int64(frb_read(buf, 8))
5455

5556
xip_tup = cpython.PyTuple_New(nxip)
5657
for i in range(nxip):
57-
xip = cpython.PyLong_FromLongLong(hton.unpack_int64(frb_read(buf, 8)))
58+
xip = cpython.PyLong_FromUnsignedLongLong(
59+
<uint64_t>hton.unpack_int64(frb_read(buf, 8)))
5860
cpython.Py_INCREF(xip)
5961
cpython.PyTuple_SET_ITEM(xip_tup, i, xip)
6062

pgproto.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ include "./codecs/hstore.pyx"
4545
include "./codecs/misc.pyx"
4646
include "./codecs/network.pyx"
4747
include "./codecs/tid.pyx"
48-
include "./codecs/txid.pyx"
48+
include "./codecs/pg_snapshot.pyx"

0 commit comments

Comments
 (0)