Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit46c3961

Browse files
committed
Optimize get_global_xmin
1 parent7abbbb9 commit46c3961

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

‎contrib/pg_dtm/dtmd/src/main.c‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
#defineDEFAULT_LISTENHOST "0.0.0.0"
1919
#defineDEFAULT_LISTENPORT 5431
2020

21+
staticxid_tget_global_xmin();
22+
2123
L2Listactive_transactions= {&active_transactions,&active_transactions};
2224
L2List*free_transactions;
2325

2426
// We reserve the local xids if they fit between (prev, next) range, and
2527
// reserve something in (next, x) range otherwise, moving 'next' after 'x'.
2628
xid_tprev_gxid,next_gxid;
29+
xid_tglobal_xmin=INVALID_XID;
2730

2831
typedefstructclient_userdata_t {
2932
intid;
@@ -55,6 +58,9 @@ inline static void free_transaction(Transaction* t)
5558
l2_list_unlink(&t->elem);
5659
t->elem.next=free_transactions;
5760
free_transactions=&t->elem;
61+
if (t->xmin==global_xmin) {
62+
global_xmin=get_global_xmin();
63+
}
5864
}
5965

6066

@@ -246,18 +252,12 @@ static void onreserve(client_t client, int argc, xid_t *argv) {
246252
}
247253

248254
staticxid_tget_global_xmin() {
249-
intj;
250255
xid_txmin=next_gxid;
251256
Transaction*t;
252257
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-
}
258+
if (t->xmin<xmin) {
259+
xmin=t->xmin;
260+
}
261261
}
262262
returnxmin;
263263
}
@@ -285,7 +285,7 @@ static void onbegin(client_t client, int argc, xid_t *argv) {
285285
transaction_clear(t);
286286
l2_list_link(&active_transactions,&t->elem);
287287

288-
prev_gxid=t->xid=t->xmin=next_gxid++;
288+
prev_gxid=t->xid=next_gxid++;
289289
t->snapshots_count=0;
290290
t->size=1;
291291

@@ -303,16 +303,18 @@ static void onbegin(client_t client, int argc, xid_t *argv) {
303303
return;
304304
}
305305

306-
xid_tgxmin=get_global_xmin();
307306
Snapshot*snap=transaction_next_snapshot(t);
308307
gen_snapshot(snap);// FIXME: increase 'times_sent' here? see also 4765234987
309308
t->xmin=snap->xmin;
309+
if (global_xmin==INVALID_XID) {
310+
global_xmin=snap->xmin;
311+
}
310312

311313
xid_tok=RES_OK;
312314
client_message_start(client); {
313315
client_message_append(client,sizeof(xid_t),&ok);
314316
client_message_append(client,sizeof(xid_t),&t->xid);
315-
client_message_append(client,sizeof(xid_t),&gxmin);
317+
client_message_append(client,sizeof(xid_t),&global_xmin);
316318
client_message_append(client,sizeof(xid_t),&snap->xmin);
317319
client_message_append(client,sizeof(xid_t),&snap->xmax);
318320
client_message_append(client,sizeof(xid_t)*snap->nactive,snap->active);
@@ -464,15 +466,13 @@ static void onsnapshot(client_t client, int argc, xid_t *argv) {
464466
gen_snapshot(transaction_next_snapshot(t));
465467
}
466468

467-
xid_tgxmin=get_global_xmin();
468-
469469
Snapshot*snap=transaction_snapshot(t,CLIENT_SNAPSENT(client)++);
470470
snap->times_sent+=1;// FIXME: does times_sent get used anywhere? see also 4765234987
471471

472472
xid_tok=RES_OK;
473473
client_message_start(client); {
474474
client_message_append(client,sizeof(xid_t),&ok);
475-
client_message_append(client,sizeof(xid_t),&gxmin);
475+
client_message_append(client,sizeof(xid_t),&global_xmin);
476476
client_message_append(client,sizeof(xid_t),&snap->xmin);
477477
client_message_append(client,sizeof(xid_t),&snap->xmax);
478478
client_message_append(client,sizeof(xid_t)*snap->nactive,snap->active);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp