Skip to content

Commit aad5eae

Browse files
committed
Sort snapshot when it is generated instead of inside the serialization procedure.
1 parent 7adf6f0 commit aad5eae

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

contrib/pg_xtm/dtmd/include/snapshot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ typedef struct Snapshot {
1515
} Snapshot;
1616

1717
char *snapshot_serialize(Snapshot *s);
18+
void snapshot_sort(Snapshot *s);
1819

1920
#endif

contrib/pg_xtm/dtmd/src/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ static void gen_snapshot(Snapshot *s, int node) {
255255
s->active[s->nactive++] = t->xid;
256256
}
257257
}
258+
snapshot_sort(s);
258259
s->seqno++;
259260
}
260261

contrib/pg_xtm/dtmd/src/snapshot.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ static void append_hex16(char **cursorp, xid_t value) {
1515
*cursorp += written;
1616
}
1717

18-
static int compare_xid(void const* x, void const* y, size_t size)
19-
{
20-
xid_t xid1 = *(xid_t*)x;
21-
xid_t xid2 = *(xid_t*)y;
22-
return xid1 < xid2 ? -1 : xid1 == xid2 ? 0 : 1;
18+
static int compare_xid(void const* x, void const* y) {
19+
xid_t xid1 = *(xid_t*)x;
20+
xid_t xid2 = *(xid_t*)y;
21+
return xid1 < xid2 ? -1 : xid1 == xid2 ? 0 : 1;
22+
}
23+
24+
void snapshot_sort(Snapshot *s) {
25+
qsort(s->active, s->nactive, sizeof(xid_t), compare_xid);
2326
}
2427

2528
char *snapshot_serialize(Snapshot *s) {
@@ -37,7 +40,6 @@ char *snapshot_serialize(Snapshot *s) {
3740
append_hex16(&cursor, s->xmax);
3841
append_hex16(&cursor, s->nactive);
3942

40-
qsort(s->active, s->nactive, sizeof(xid_t), compare_xid);
4143
int i;
4244
for (i = 0; i < s->nactive; i++) {
4345
append_hex16(&cursor, s->active[i]);

0 commit comments

Comments
 (0)