Skip to content

Commit 504c5da

Browse files
committed
Optimize get_global_xmin
1 parent 188e359 commit 504c5da

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

contrib/pg_dtm/dtmd/include/transaction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ typedef struct L2List
2020
typedef struct Transaction {
2121
L2List elem;
2222
xid_t xid;
23+
xid_t xmin;
2324

2425
int size; // number of paritcipants
2526

contrib/pg_dtm/dtmd/src/main.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -246,19 +246,13 @@ static void onreserve(client_t client, int argc, xid_t *argv) {
246246
}
247247

248248
static xid_t get_global_xmin() {
249-
int j;
250249
xid_t xmin = next_gxid;
251250
Transaction *t;
252251
for (t = (Transaction*)active_transactions.next; t != (Transaction*)&active_transactions; t = (Transaction*)t->elem.next) {
253-
j = t->snapshots_count > MAX_SNAPSHOTS_PER_TRANS ? MAX_SNAPSHOTS_PER_TRANS : t->snapshots_count;
254-
while (--j >= 0) {
255-
Snapshot* s = transaction_snapshot(t, j);
256-
if (s->xmin < xmin) {
257-
xmin = s->xmin;
258-
}
259-
// minor TODO: Use 'times_sent' to generate a bit greater xmin?
260-
}
261-
}
252+
if (t->xmin < xmin) {
253+
xmin = t->xmin;
254+
}
255+
}
262256
return xmin;
263257
}
264258

@@ -283,7 +277,6 @@ static void onbegin(client_t client, int argc, xid_t *argv) {
283277
free_transactions = t->elem.next;
284278
}
285279
transaction_clear(t);
286-
l2_list_link(&active_transactions, &t->elem);
287280

288281
prev_gxid = t->xid = next_gxid++;
289282
t->snapshots_count = 0;
@@ -299,15 +292,15 @@ static void onbegin(client_t client, int argc, xid_t *argv) {
299292
CLIENT_ID(client), t->xid
300293
);
301294
client_message_shortcut(client, RES_FAILED);
295+
free_transaction(t);
302296
return;
303297
}
304-
305298
xid_t gxmin = get_global_xmin();
299+
Snapshot *snap = transaction_next_snapshot(t);
300+
gen_snapshot(snap); // FIXME: increase 'times_sent' here? see also 4765234987
306301

307-
gen_snapshot(transaction_next_snapshot(t));
308-
// will wrap around if exceeded max snapshots
309-
Snapshot *snap = transaction_latest_snapshot(t);
310-
// FIXME: increase 'times_sent' here? see also 4765234987
302+
t->xmin = snap->xmin;
303+
l2_list_link(&active_transactions, &t->elem);
311304

312305
xid_t ok = RES_OK;
313306
client_message_start(client); {
@@ -462,7 +455,11 @@ static void onsnapshot(client_t client, int argc, xid_t *argv) {
462455

463456
if (CLIENT_SNAPSENT(client) == t->snapshots_count) {
464457
// a fresh snapshot is needed
465-
gen_snapshot(transaction_next_snapshot(t));
458+
Snapshot* snap = transaction_next_snapshot(t);
459+
gen_snapshot(snap);
460+
if (snap->xmin < t->xmin) {
461+
t->xmin = snap->xmin;
462+
}
466463
}
467464

468465
xid_t gxmin = get_global_xmin();

contrib/pg_dtm/dtmd/src/transaction.c

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

2929
t->xid = INVALID_XID;
30+
t->xmin = INVALID_XID;
3031
t->size = 0;
3132
t->votes_for = 0;
3233
t->votes_against = 0;

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