Skip to content

Commit e9335ab

Browse files
committed
Dynamically calculate number of participants
1 parent 3796257 commit e9335ab

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

contrib/pg_xtm/dtmd/include/transaction.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
typedef struct Transaction {
1515
xid_t xid;
1616

17-
int size;
17+
int size; // number of paritcipants
18+
int max_size; // maximal number of participants
1819

1920
// for + against ≤ size
2021
int votes_for;

contrib/pg_xtm/dtmd/src/main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ static char *onbegin(void *stream, void *clientdata, cmd_t *cmd) {
280280

281281
prev_gxid = t->xid = next_gxid++;
282282
t->snapshots_count = 0;
283-
t->size = size;
283+
t->max_size = size;
284+
t->size = 1;
284285

285286
CLIENT_SNAPSENT(clientdata) = 0;
286287
CLIENT_XID(clientdata) = t->xid;
@@ -436,6 +437,12 @@ static char *onsnapshot(void *stream, void *clientdata, cmd_t *cmd) {
436437
if (CLIENT_XID(clientdata) == INVALID_XID) {
437438
CLIENT_SNAPSENT(clientdata) = 0;
438439
CLIENT_XID(clientdata) = t->xid;
440+
t->size += 1;
441+
CHECK(
442+
t->size <= t->max_size,
443+
clientdata,
444+
"SNAPSHOT: too many participants"
445+
);
439446
}
440447

441448
CHECK(

contrib/pg_xtm/dtmd/src/transaction.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void transaction_clear(Transaction *t) {
2828

2929
t->xid = INVALID_XID;
3030
t->size = 0;
31+
t->max_size = 0;
3132
t->votes_for = 0;
3233
t->votes_against = 0;
3334
t->snapshots_count = 0;

0 commit comments

Comments
 (0)