Skip to content

Commit 7e0b32c

Browse files
committed
Differenciate between UNKNOWN and IN_PROGRESS status.
1 parent cec9a05 commit 7e0b32c

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

contrib/pg_xtm/dtmd/include/clog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
#define MIN_XID 42
1313
#define MAX_XID 0xdeadbeefcafebabe
1414

15-
#define NEUTRAL 0
15+
#define BLANK 0
1616
#define POSITIVE 1
1717
#define NEGATIVE 2
18+
#define DOUBT 3
1819

1920
typedef struct clog_data_t *clog_t;
2021

contrib/pg_xtm/dtmd/src/clog-test.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bool test_clog(char *datadir) {
2222
printf("commit %d status %d\n", 42, clog_read(clog, 42));
2323
printf("commit %d status %d\n", 1000, clog_read(clog, 1000));
2424
if (!clog_write(clog, 1000, POSITIVE)) return false;
25-
if (!clog_write(clog, 1500, NEGATIVE)) return false;
25+
if (!clog_write(clog, 1500, DOUBT)) return false;
2626

2727
if (!clog_close(clog)) return false;
2828
if (!(clog = clog_open(datadir))) return false;
@@ -35,11 +35,11 @@ bool test_clog(char *datadir) {
3535
printf("commit %d status %d (should be 1)\n", 1000, status = clog_read(clog, 1000));
3636
if (status != POSITIVE) return false;
3737

38-
printf("commit %d status %d (should be 2)\n", 1500, status = clog_read(clog, 1500));
39-
if (status != NEGATIVE) return false;
38+
printf("commit %d status %d (should be 3)\n", 1500, status = clog_read(clog, 1500));
39+
if (status != DOUBT) return false;
4040

4141
printf("commit %d status %d (should be 0)\n", 2044, status = clog_read(clog, 2044));
42-
if (status != NEUTRAL) return false;
42+
if (status != BLANK) return false;
4343

4444
if (!clog_close(clog)) return false;
4545

contrib/pg_xtm/dtmd/src/clog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ int clog_read(clog_t clog, xid_t xid) {
124124
"you might be experiencing a bug in backend\n",
125125
xid
126126
);
127-
return NEUTRAL;
127+
return BLANK;
128128
}
129129
}
130130

contrib/pg_xtm/dtmd/src/main.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static char *onbegin(void *client, cmd_t *cmd) {
135135
}
136136
t->active = true;
137137
t->node = node;
138-
t->vote = NEUTRAL;
138+
t->vote = DOUBT;
139139
t->xid = xid;
140140
t->snapshot.seqno = 0;
141141
t->sent_seqno = 0;
@@ -144,11 +144,22 @@ static char *onbegin(void *client, cmd_t *cmd) {
144144
xmax[node] = xid;
145145
}
146146
}
147+
if (!global_transaction_mark(clg, transactions + i, DOUBT)) {
148+
shout(
149+
"[%d] VOTE: global transaction failed"
150+
" to initialize clog bits O_o\n",
151+
CLIENT_ID(client)
152+
);
153+
return strdup("-");
154+
}
155+
147156
transactions_count++;
148157
return strdup("+");
149158
}
150159

151160
static char *onvote(void *client, cmd_t *cmd, int vote) {
161+
assert((vote == POSITIVE) || (vote == NEGATIVE));
162+
152163
if (cmd->argc != 2) {
153164
shout(
154165
"[%d] VOTE: wrong number of arguments\n",
@@ -182,7 +193,7 @@ static char *onvote(void *client, cmd_t *cmd, int vote) {
182193
return strdup("-");
183194
}
184195

185-
if (transactions[i].participants[node].vote != NEUTRAL) {
196+
if (transactions[i].participants[node].vote != DOUBT) {
186197
shout(
187198
"[%d] VOTE: node %d voting on xid %llu again\n",
188199
CLIENT_ID(client), node, xid
@@ -209,7 +220,7 @@ static char *onvote(void *client, cmd_t *cmd, int vote) {
209220
);
210221
return strdup("-");
211222
}
212-
case NEUTRAL:
223+
case DOUBT:
213224
shout("[%d] VOTE: vote counted\n", CLIENT_ID(client));
214225
return strdup("+");
215226
case POSITIVE:
@@ -333,13 +344,16 @@ static char *onstatus(void *client, cmd_t *cmd) {
333344

334345
int status = clog_read(clg, MUX_XID(node, xid));
335346
switch (status) {
347+
case BLANK:
348+
return strdup("+0");
336349
case POSITIVE:
337350
return strdup("+c");
338351
case NEGATIVE:
339352
return strdup("+a");
340-
case NEUTRAL:
353+
case DOUBT:
341354
return strdup("+?");
342355
default:
356+
assert(false); // should not happen
343357
return strdup("-");
344358
}
345359
}

contrib/pg_xtm/dtmd/src/transaction.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ int global_transaction_status(GlobalTransaction *gt) {
1111
if (t->active) {
1212
assert(t->node == node);
1313
switch (t->vote) {
14+
case BLANK:
15+
shout("a blank vote, this should not happen");
16+
return BLANK;
1417
case NEGATIVE:
1518
againstcount++;
1619
break;
17-
case NEUTRAL:
20+
case DOUBT:
1821
inprogresscount++;
1922
break;
2023
case POSITIVE:
@@ -26,7 +29,7 @@ int global_transaction_status(GlobalTransaction *gt) {
2629
if (againstcount) {
2730
return NEGATIVE;
2831
} else if (inprogresscount) {
29-
return NEUTRAL;
32+
return DOUBT;
3033
} else {
3134
return POSITIVE;
3235
}

contrib/pg_xtm/libdtm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ XidStatus DtmGlobalGetTransStatus(DTMConn dtm, NodeId nodeid, TransactionId xid)
280280
if (!dtm_read_char(dtm, &statuschar)) return -1;
281281

282282
switch (statuschar) {
283+
case '0':
284+
return TRANSACTION_STATUS_UNKNOWN;
283285
case 'c':
284286
return TRANSACTION_STATUS_COMMITTED;
285287
case 'a':

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