Skip to content

Commit 9bbb357

Browse files
committed
Fix handlings snapshots in DTMD
1 parent b92769c commit 9bbb357

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

contrib/pg_xtm/dtmd/include/snapshot.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
#include "limits.h"
66

77
typedef struct Snapshot {
8-
// initially 0, which means 'invalid snapshot'
9-
int seqno;
10-
118
xid_t xmin;
129
xid_t xmax;
1310
int nactive;

contrib/pg_xtm/dtmd/include/transaction.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "snapshot.h"
88
#include "limits.h"
99

10+
#define MAX_SNAPSHOTS_PER_TRANS 8
11+
1012
typedef struct Transaction {
1113
// true if the transaction was started on the node
1214
bool active;
@@ -15,14 +17,15 @@ typedef struct Transaction {
1517
int vote;
1618

1719
xid_t xid;
18-
Snapshot snapshot;
20+
Snapshot snapshot[MAX_SNAPSHOTS_PER_TRANS];
1921

2022
// if this is equal to seqno, we need to generate a new snapshot (for each node)
21-
int sent_seqno;
23+
int snapshot_no;
2224
} Transaction;
2325

2426
#define CHAR_TO_INDEX(C) ((C) - 'a')
2527
typedef struct GlobalTransaction {
28+
int n_snapshots;
2629
Transaction participants[MAX_NODES];
2730
void *listeners[CHAR_TO_INDEX('z')]; // we are going to use 'a' to 'z' for indexing
2831
} GlobalTransaction;

contrib/pg_xtm/dtmd/src/main.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ static char *onbegin(void *stream, void *clientdata, cmd_t *cmd) {
152152
t->node = node;
153153
t->vote = DOUBT;
154154
t->xid = xid;
155-
t->snapshot.seqno = 0;
156-
t->sent_seqno = 0;
155+
t->snapshot_no = 0;
157156

158157
if (xid > xmax[node]) {
159158
xmax[node] = xid;
@@ -329,14 +328,15 @@ static void gen_snapshot(Snapshot *s, int node) {
329328
}
330329
}
331330
snapshot_sort(s);
332-
s->seqno++;
333331
}
334332

335333
static void gen_snapshots(GlobalTransaction *gt) {
336334
int n;
335+
assert(gt->n_snapshots < MAX_SNAPSHOTS_PER_TRANS);
337336
for (n = 0; n < MAX_NODES; n++) {
338-
gen_snapshot(&gt->participants[n].snapshot, n);
337+
gen_snapshot(&gt->participants[n].snapshot[gt->n_snapshots], n);
339338
}
339+
gt->n_snapshots += 1;
340340
}
341341

342342
static char *onsnapshot(void *stream, void *clientdata, cmd_t *cmd) {
@@ -373,15 +373,14 @@ static char *onsnapshot(void *stream, void *clientdata, cmd_t *cmd) {
373373
return strdup("-");
374374
}
375375

376-
GlobalTransaction *gt = transactions + i;
377-
Transaction *t = gt->participants + node;
378-
if (t->sent_seqno == t->snapshot.seqno) {
376+
GlobalTransaction *gt = &transactions[i];
377+
Transaction *t = &gt->participants[node];
378+
if (t->snapshot_no == gt->n_snapshots) {
379379
gen_snapshots(gt);
380380
}
381-
assert(t->sent_seqno < t->snapshot.seqno);
381+
assert(t->snapshot_no < gt->n_snapshots);
382382

383-
t->sent_seqno++;
384-
return snapshot_serialize(&t->snapshot);
383+
return snapshot_serialize(&t->snapshot[t->snapshot_no++]);
385384
}
386385

387386
static bool queue_for_transaction_finish(void *stream, void *clientdata, int node, xid_t xid, char cmd) {
@@ -402,7 +401,7 @@ static bool queue_for_transaction_finish(void *stream, void *clientdata, int nod
402401
return false;
403402
}
404403

405-
global_transaction_push_listener(transactions + i, cmd, stream);
404+
global_transaction_push_listener(&transactions[i], cmd, stream);
406405
return true;
407406
}
408407

contrib/pg_xtm/dtmd/src/snapshot.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ void snapshot_sort(Snapshot *s) {
2626
}
2727

2828
char *snapshot_serialize(Snapshot *s) {
29-
assert(s->seqno > 0);
30-
3129
int numberlen = 16;
3230
int numbers = 3 + s->nactive; // xmin, xmax, n, active...
3331
int len = 1 + numberlen * numbers; // +1 for '+'

contrib/pg_xtm/dtmd/src/transaction.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ bool global_transaction_mark(clog_t clg, GlobalTransaction *gt, int status) {
5858

5959
void global_transaction_clear(GlobalTransaction *gt) {
6060
int i;
61+
gt->n_snapshots = 0;
6162
for (i = 0; i < MAX_NODES; i++) {
6263
gt->participants[i].active = false;
6364
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy